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: Link.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19 inherit "/classes/Object";
21 #include <exception.h>
25 //! A Link points to some other object inside the sTeam system.
26 class Link : public Object{
41 add_data_storage(STORE_LINK, retrieve_link_data, restore_link_data);
47 * Create a duplicate of this link object which means create
48 * another link pointing to the same object than this.
50 * @return the duplicated object.
52 mapping do_duplicate(void|mapping vars)
54 if ( !mappingp(vars) )
56 vars->link_to = oLinkObject;
57 return ::do_duplicate(vars);
64 if ( objectp(oLinkObject) )
81 * Set the link object which is the object this link refers to.
83 * @param obj - the link
84 * @see query_link_object
87 set_link_object(object obj)
89 if ( objectp(oLinkObject) || !objectp(obj) )
90 return; // only set link once !
91 /* the object links to another one now */
93 require_save(STORE_LINK);
97 * Get the object this link points to.
99 * @return the object linked to this
100 * @see set_link_object
108 object get_destination()
110 return get_link_object();
113 void lowAppendXML(object rootNode, void|int depth)
115 ::lowAppendXML(rootNode, depth);
116 object dest = get_destination();
117 rootNode->add_prop("Target", (objectp(dest)?
118 (string)dest->get_object_id(): "0"));
123 * Retrieve the to be saved data of this Link.
125 * @return mapping of link data.
131 if ( CALLER != _Database )
132 THROW("Caller is not database !", E_ACCESS);
133 return ([ "LinkObject": oLinkObject ]);
139 * Restore the saved link data. Called by database to load the link.
141 * @param mixed data - the data to be restored.
145 restore_link_data(mixed data)
147 if ( CALLER != _Database )
148 THROW("Caller is not database !", E_ACCESS);
150 oLinkObject = data[0];
152 oLinkObject = data["LinkObject"];
159 * Get the action to take for this link. Usually follow for exits
160 * or get if the link points to a document.
162 * @return the link action string description.
164 string get_link_action()
166 if ( !objectp(oLinkObject) )
168 else if ( oLinkObject->get_object_class() &
169 (CLASS_CONTAINER|CLASS_ROOM|CLASS_EXIT|CLASS_MESSAGEBOARD|CLASS_DOCEXTERN) )
177 * Get the content size of the object linked to.
179 * @return the content size of the linked object.
181 int get_content_size()
183 if ( objectp(oLinkObject) ) {
184 if ( !(oLinkObject->get_object_class() & CLASS_LINK) )
185 return oLinkObject->get_content_size();
187 return ::get_content_size();
193 if ( objectp(oLinkObject) )
194 stat = oLinkObject->stat();
200 int get_object_class() { return CLASS_LINK | ::get_object_class(); }