Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

GObject.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Raphael Langerhorst                             *
00003  *   raphael-langerhorst@gmx.at                                            *
00004  *                                                                         *
00005  *   Permission is hereby granted, free of charge, to any person obtaining *
00006  *   a copy of this software and associated documentation files (the       *
00007  *   "Software"), to deal in the Software without restriction, including   *
00008  *   without limitation the rights to use, copy, modify, merge, publish,   *
00009  *   distribute, sublicense, and/or sell copies of the Software, and to    *
00010  *   permit persons to whom the Software is furnished to do so, subject to *
00011  *   the following conditions:                                             *
00012  *                                                                         *
00013  *   The above copyright notice and this permission notice shall be        *
00014  *   included in all copies or substantial portions of the Software.       *
00015  *                                                                         *
00016  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       *
00017  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    *
00018  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
00019  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR     *
00020  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
00021  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
00022  *   OTHER DEALINGS IN THE SOFTWARE.                                       *
00023  ***************************************************************************/
00024 
00025 #ifndef GOBJECTH
00026 #define GOBJECTH
00027 
00028 #include "GEnergy.h"
00029 #include "GForm.h"
00030 #include "GElementID.h"
00031 
00032 #include <qvaluelist.h>
00033 #include <qmutex.h>
00034 
00035 namespace GCS
00036 {
00037 
00084 class GObject : public QMutex
00085 {
00086   private:
00090     GEnergy* Energy;
00091     
00095     GForm* Form;
00096         
00100     GElementID Parent;
00101     
00105     const GElementID ID;
00106     
00116     const GElementID Connection;
00117 
00118 //   this is left as a comment for idea gathering
00119 //     /**
00120 //      * consider the following situation:
00121 //      * you hava a certain characteristic, for example you
00122 //      * tend to be very happy; if something happens and you
00123 //      * are quite unhappy for a few hours it does not mean
00124 //      * that you are unhappy in general; likely you will
00125 //      * recover and be (almost!!) happy as ever a few days
00126 //      * later;
00127 //      * (and maybe if you have learned something from the
00128 //      * unexpected event so that afterwards you are even
00129 //      * more happy - but this requires influence from your
00130 //      * spirit...)
00131 //      *
00132 //      * so, if the energy changes for what reason ever
00133 //      * this attribute could tell the "ordinary" state of
00134 //      * the element;
00135 //      *
00136 //      * removed, because:
00137 //      * the above comment actually is true, but we have to
00138 //      * consider the way how we get unhappy when we are
00139 //      * normally happy: if we get influenced by different
00140 //      * circumstances than normal then it is likely that
00141 //      * we also feel different; but this will go away as
00142 //      * soon as the different influence also goes away!!
00143 //      */
00144 //    GEnergy LongTermEnergy;
00145 
00149     QValueList<GElementID> Children;
00150 
00151     
00152   public:
00153 
00157     GObject(GEnergy* energy,
00158             GForm* form,
00159             const GElementID& parent,
00160             const GElementID& ID,
00161             const GElementID& connection)
00162     : Energy(energy),
00163       Form(form),
00164       Parent(parent),
00165       ID(ID),
00166       Connection(connection)
00167     {
00168     }
00169 
00173     virtual ~GObject()
00174     {
00175       if (hasEnergy())
00176       {
00177         delete Energy;
00178         Energy = NULL;
00179       }
00180       if (hasForm())
00181       {
00182         delete Form;
00183         Form = NULL;
00184       }
00185     }
00186 
00187     // read methods:
00188     
00192     bool hasEnergy() const { return Energy ? true : false; }
00193     
00197     GEnergy* getEnergy() { Q_ASSERT(Energy); return Energy; }
00198     
00202     const GEnergy* getEnergy() const { Q_ASSERT(Energy); return Energy; }
00203     
00207     bool hasForm() const { return Form ? true : false; }
00208     
00212     GForm* getForm() { Q_ASSERT(Form); return Form; }
00213     
00217     const GForm* getForm() const { Q_ASSERT(Form); return Form; }
00218     
00222     const GElementID& getParent() const { return Parent; }
00223     
00227     const GElementID& getID() const { return ID; }
00228     
00232     const GElementID& getConnection() const { return Connection; }
00233 
00234     
00235     // methods for hierarchy management:
00236     
00240     void reparent(const GElementID& new_parent);
00241 
00246     void addChild(const GElementID&);
00247     
00255     bool isChild(const GElementID&) const;
00256     
00262     void removeChild(const GElementID&);
00263     
00267     QValueList<GElementID> getChildren() const;
00268 };
00269 
00270 }
00271 
00272 #endif

Generated on Thu Oct 21 21:18:03 2004 for G System by doxygen 1.3.6