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.1.1 2005/02/23 14:47:21 cvs Exp $
20
constant cvs_version="$Id: Link.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $";
22
//! A Link points to some other object inside the sTeam system.
24
inherit "/classes/Object";
27
#include <exception.h>
32
static object oLinkObject;
38
add_data_storage(STORE_LINK, retrieve_link_data, restore_link_data);
42
* Create a duplicate of this link object which means create
43
* another link pointing to the same object than this.
45
* @return the duplicated object.
46
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
50
object dup_obj = ::duplicate();
51
dup_obj->set_link_object(oLinkObject);
55
static void delete_object()
58
if ( objectp(oLinkObject) )
59
oLinkObject->remove_reference(this());
71
* Set the link object which is the object this link refers to.
73
* @param obj - the link
75
* @see query_link_object
78
set_link_object(object obj)
80
if ( objectp(oLinkObject) || !objectp(obj) )
81
return; // only set link once !
82
/* the object links to another one now */
84
oLinkObject->add_reference(this());
85
require_save(STORE_LINK);
89
* Get the object this link points to.
91
* @return the object linked to this
93
* @see set_link_object
102
* Retrieve the to be saved data of this Link.
104
* @return mapping of link data.
105
* @author Thomas Bopp (astra@upb.de)
110
if ( CALLER != _Database )
111
THROW("Caller is not database !", E_ACCESS);
112
return ([ "LinkObject": oLinkObject ]);
116
* Restore the saved link data. Called by database to load the link.
118
* @param mixed data - the data to be restored.
119
* @author Thomas Bopp (astra@upb.de)
122
restore_link_data(mixed data)
124
if ( CALLER != _Database )
125
THROW("Caller is not database !", E_ACCESS);
127
oLinkObject = data[0];
129
oLinkObject = data["LinkObject"];
134
* Get the action to take for this link. Usually follow for exits
135
* or get if the link points to a document.
137
* @return the link action string description.
138
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
140
string get_link_action()
142
if ( !objectp(oLinkObject) )
144
else if ( oLinkObject->get_object_class() &
145
(CLASS_CONTAINER|CLASS_ROOM|CLASS_EXIT|CLASS_MESSAGEBOARD|CLASS_DOCEXTERN) )
153
* Get the content size of the object linked to.
155
* @return the content size of the linked object.
156
* @author <a href="mailto:astra@upb.de">Thomas Bopp</a>)
158
int get_content_size()
160
if ( objectp(oLinkObject) ) {
161
if ( !(oLinkObject->get_object_class() & CLASS_LINK) )
162
return oLinkObject->get_content_size();
164
return ::get_content_size();
170
if ( objectp(oLinkObject) )
171
stat = oLinkObject->stat();
177
int get_object_class() { return CLASS_LINK | ::get_object_class(); }