1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * $Id: references.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
20 #include <exception.h>
31 void require_save(string|void a, string|void b);
32 int get_object_class();
33 object get_environment();
34 string get_identifier();
37 * Initialize the reference storage.
41 void init_references()
50 * Add a reference to this object. The reference functionality is
51 * maintained by the server itself and shouldnt be called by other code.
53 * @param object ref - the reference.
54 * @see remove_reference
56 void add_reference(object ref)
59 require_save(STORE_REFS);
63 * Remove a reference from this object. The function is for internal use.
64 * The references are maintained by the server itself.
66 * @param object ref - a reference to remove.
69 void remove_reference(object ref)
71 if ( CALLER->get_object_id() != ref->get_object_id() )
72 THROW("Removing reference by non-referencing object ("+
73 CALLER->get_object_id()+":"+ref->get_object_id()+
75 m_delete(mReferences, ref);
76 require_save(STORE_REFS);
80 * Get the mapping of references. The mapping is in the form
81 * ([ ref:1 ]) - a mapping is used for faster lookup.
85 mapping get_references()
87 return copy_value(mReferences);
91 * Get the array of all referencing objects.
95 array get_referencing()
97 return indices(mReferences);
102 * Store the references in the database. Database calls this function.
106 * @see restore_references
112 if (CALLER != _Database ) THROW("Caller is not Database !", E_ACCESS);
113 return ([ "References": mReferences, ]);
119 * The object is loaded and its references restored by the database.
121 * @param mixed data - the reference data.
123 * @see store_references
126 void restore_references(mixed data)
128 if (CALLER != _Database ) THROW("Caller is not Database !", E_ACCESS);
129 mReferences = data["References"];