interreality.org [VOS]
[Home] [About]
[Screenshots]
[Download]
[News]
[Community]
[Documentation] [Manual]
[Bugs & Requests] [Wiki]

/home/tetron/hack/vos/libs/vos/vos/vobjectstate.hh

Go to the documentation of this file.
00001 /*
00002     This file is part of the Virtual Object System of
00003     the Interreality project (http://interreality.org).
00004 
00005     Copyright (C) 2001-2003 Peter Amstutz
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021     Peter Amstutz <http://www.interreality.org>
00022 */
00023 
00024 #ifndef _VOBJECTSTATE_HH_
00025 #define _VOBJECTSTATE_HH_
00026 
00027 /** @file
00028     Defines VobjectState.
00029 */
00030 
00031 #include <deque>
00032 #include <stdexcept>
00033 #include <boost/thread/recursive_mutex.hpp>
00034 
00035 #include <vos/vutil/refcount.hh>
00036 #include <vos/vutil/url.hh>
00037 #include <vos/vutil/log.hh>
00038 #include <vos/vos/listener.hh>
00039 #include <vos/vos/parentchildrel.hh>
00040 
00041 
00042 namespace VOS
00043 {
00044     class Site;
00045     class Message;
00046     class MessageBlock;
00047     class TypeChangeListener;
00048     class ParentChangeListener;
00049     class ChildChangeListener;
00050     class ParentChildRelation;
00051     class VobjectBase;
00052     class VobjectEvent;
00053 
00054     class PCRIterator;
00055     typedef PCRIterator ChildListIterator;
00056     typedef PCRIterator ParentSetIterator;
00057     class StringIterator;
00058     typedef StringIterator TypeSetIterator;
00059 
00060 /** @class VobjectState vobjectstate.hh vos/vos/vobjectstate.hh
00061     @ingroup libvos
00062 
00063     This holds the actual state common to every Vobject: the type set,
00064     the child list, and the parent set.  Listeners are also stored
00065     here, although the methods of this class do not actually trigger
00066     the listener callbacks.  The API for VobjectState is basically a
00067     subset of Vobject, for obvious reasons.  You shouldn't ever access
00068     a Vobject's state object state directly unless you have a very
00069     good reason to bypass the extensions, access control checks and
00070     listener callbacks that are implemented by VobjectBase.
00071 */
00072 class VOS_API VobjectState
00073 {
00074 public:
00075     typedef std::set<ParentChildRelation*> ParentSet;
00076     typedef std::deque<ParentChildRelation*> ChildList;
00077     typedef std::set<std::string> TypeSet;
00078 private:
00079     VobjectBase* myvobject;
00080 
00081     ParentSet parents;
00082 
00083     ChildList children;
00084     std::map<std::string, ParentChildRelation*> children_map;
00085 
00086     TypeSet types;
00087 
00088     void adjustChildMap(ParentChildRelation* pcr, int ofs);
00089 public:
00090     boost::recursive_mutex state_mutex;
00091 
00092     VUtil::ListenerBase<TypeChangeListener, VobjectEvent> typeListeners;
00093     VUtil::ListenerBase<ParentChangeListener, VobjectEvent> parentListeners;
00094     VUtil::ListenerBase<ChildChangeListener, VobjectEvent> childListeners;
00095 
00096     VobjectState(VobjectBase* myvobject);
00097     ~VobjectState();
00098 
00099     VUtil::vRef<VobjectBase> getBase();
00100 
00101     void addType(const std::string& s);
00102     void removeType(const std::string& s);
00103     TypeSetIterator getTypes();
00104 
00105     int numChildren();
00106     void insertChild(int pos, const std::string& c, Vobject* vobj);
00107     void setChild(int pos, const std::string& c, Vobject* vobj);
00108     void removeChild(int pos);
00109     void fixPosition(int& pos, int forinsert = 0);
00110 
00111     bool hasChild(const std::string& c);
00112     bool hasChild(int pos);
00113 
00114     VUtil::vRef<ParentChildRelation> findChild(int pos);
00115     VUtil::vRef<ParentChildRelation> findChild(const std::string& c);
00116     ChildListIterator getChildren(int start = 0, int end = -1);
00117     void clearChildren();
00118 
00119     ParentSetIterator getParents();
00120     VUtil::vRef<ParentChildRelation> findParent(Vobject& parent);
00121     VUtil::vRef<ParentChildRelation> findParent(Vobject* parent);
00122     void addParent(ParentChildRelation* pcr);
00123     void removeParent(ParentChildRelation* pcr);
00124 };
00125 }
00126 
00127 #endif
00128