FullID.hpp

Go to the documentation of this file.
00001 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00002 //
00003 //        This file is part of E-Cell Simulation Environment package
00004 //
00005 //                Copyright (C) 1996-2002 Keio University
00006 //
00007 //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 //
00009 //
00010 // E-Cell is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public
00012 // License as published by the Free Software Foundation; either
00013 // version 2 of the License, or (at your option) any later version.
00014 // 
00015 // E-Cell is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 // See the GNU General Public License for more details.
00019 // 
00020 // You should have received a copy of the GNU General Public
00021 // License along with E-Cell -- see the file COPYING.
00022 // If not, write to the Free Software Foundation, Inc.,
00023 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 // 
00025 //END_HEADER
00026 //
00027 // written by Koichi Takahashi <shafi@e-cell.org>,
00028 // E-Cell Project.
00029 //
00030 
00031 #ifndef __FULLID_HPP
00032 #define __FULLID_HPP
00033 
00034 #include "libecs.hpp"
00035 #include "EntityType.hpp"
00036 
00037 
00038 namespace libecs
00039 {
00040 
00041   /** @addtogroup identifier The FullID, FullPN and SystemPath.
00042    The FullID, FullPN and SystemPath.
00043    
00044 
00045    @ingroup libecs
00046    @{ 
00047    */ 
00048   
00049   /** @file */
00050 
00051 
00052   /** 
00053       SystemPath 
00054   */
00055 
00056   class SystemPath : public StringList
00057   {
00058 
00059   public:
00060 
00061     explicit SystemPath( StringCref systempathstring = "" )
00062     {
00063       parse( systempathstring );
00064     }
00065 
00066     SystemPath( SystemPathCref systempath )
00067       :
00068       StringList( static_cast<StringList>( systempath ) )
00069     {
00070       ; // do nothing
00071     }
00072 
00073     ~SystemPath() {}
00074 
00075     const String getString() const;
00076 
00077     bool isAbsolute() const
00078     {
00079       return ( ( ( ! empty() ) && ( front()[0] == DELIMITER ) ) || empty() );
00080     }
00081 
00082     bool isValid() const
00083     {
00084       // FIXME: check '..'s and '.'s etc..
00085       return true;
00086     }
00087 
00088   protected:
00089 
00090     /**
00091        Standardize a SystemPath. 
00092        Reduce '..'s and remove extra white spaces.
00093 
00094        @return reference to the systempath
00095     */
00096     void standardize();
00097 
00098   private:
00099 
00100     //    SystemPath();
00101 
00102 
00103     ECELL_API void parse( StringCref systempathstring );
00104 
00105   public:
00106 
00107     static const char DELIMITER = '/';
00108 
00109   };
00110 
00111 
00112   /**
00113      FullID is an identifier of a unique Entiy in a cell model.
00114      The FullID consists of a EntityType, a SystemPath and an ID string.
00115 
00116      @see EntityType, SystemPath
00117   */
00118   class FullID
00119   {
00120 
00121   public:
00122 
00123     FullID( const EntityType type,
00124             SystemPathCref systempath,
00125             StringCref id )
00126       :
00127       theEntityType( type ),
00128       theSystemPath( systempath ),
00129       theID( id )
00130     {
00131       ; // do nothing
00132     }
00133 
00134     explicit FullID( const EntityType type,
00135                      StringCref systempathstring,
00136                      StringCref id )
00137       :
00138       theEntityType( type ),
00139       theSystemPath( systempathstring ),
00140       theID( id )
00141     {
00142       ; // do nothing
00143     }
00144 
00145     FullID( StringCref fullidstring )
00146     {
00147       parse( fullidstring );
00148     }
00149 
00150     FullID( FullIDCref fullid )
00151       :
00152       theEntityType( fullid.getEntityType() ),
00153       theSystemPath( fullid.getSystemPath() ),
00154       theID( fullid.getID() )
00155     {
00156       ; // do nothing
00157     }
00158 
00159 
00160     ~FullID() {}
00161   
00162     const EntityType  getEntityType() const 
00163     { 
00164       return theEntityType; 
00165     }
00166 
00167     SystemPathCref getSystemPath() const
00168     { 
00169       return theSystemPath; 
00170     }
00171 
00172     StringCref getID() const
00173     { 
00174       return theID;
00175     }
00176 
00177 
00178     void setEntityType( const EntityType type )
00179     {
00180       theEntityType = type;
00181     }
00182 
00183     void setSystemPath( SystemPathCref systempath ) 
00184     {
00185       theSystemPath = systempath;
00186     }
00187 
00188     void setID( StringCref id ) 
00189     {
00190       theID = id;
00191     }
00192 
00193     bool isValid() const;
00194 
00195     ECELL_API const String getString() const;
00196 
00197     bool operator<( FullIDCref rhs ) const
00198     {
00199       // first look at the EntityType
00200       if( getEntityType() != rhs.getEntityType() )
00201         {
00202           return getEntityType() < rhs.getEntityType();
00203         }
00204 
00205       // then compare the SystemPaths
00206       // FIXME: should be faster is there is SystemPath::compare()
00207       if( getSystemPath() != rhs.getSystemPath() )
00208         {
00209           return getSystemPath() < rhs.getSystemPath();
00210         }
00211 
00212       // finally compare the ID strings
00213       return getID() < rhs.getID();
00214     }
00215 
00216     bool operator==( FullIDCref rhs ) const
00217     {
00218       // first look at the EntityType
00219       if( getEntityType() != rhs.getEntityType() )
00220         {
00221           return false;
00222         }
00223 
00224       // then compare the SystemPaths
00225       if( getSystemPath() != rhs.getSystemPath() )
00226         {
00227           return false;
00228         }
00229 
00230       // finally compare the ID strings
00231       return getID() == rhs.getID();
00232     }
00233 
00234     bool operator!=( FullIDCref rhs ) const
00235     {
00236       return ! operator==( rhs );
00237     }
00238 
00239   protected:
00240 
00241     ECELL_API void parse( StringCref fullidstring );
00242 
00243   private:
00244 
00245     FullID();
00246 
00247   public:
00248 
00249     static const char DELIMITER = ':';
00250 
00251   private:
00252 
00253     EntityType theEntityType;
00254     SystemPath    theSystemPath;
00255     String        theID;
00256 
00257   };
00258 
00259   class FullPN
00260   {
00261 
00262   public:
00263 
00264     FullPN( const EntityType type, 
00265             SystemPathCref systempath,
00266             StringCref id,
00267             StringCref propertyname )
00268       :
00269       theFullID( type, systempath, id ),
00270       thePropertyName( propertyname )
00271     {
00272       ; // do nothing
00273     }
00274 
00275     FullPN( FullIDCref fullid, StringCref propertyname )
00276       :
00277       theFullID( fullid ),
00278       thePropertyName( propertyname )
00279     {
00280       ; // do nothing
00281     }
00282 
00283     FullPN( FullPNCref fullpn )
00284       :
00285       theFullID( fullpn.getFullID() ),
00286       thePropertyName( fullpn.getPropertyName() )
00287     {
00288       ; // do nothing
00289     }
00290 
00291     ECELL_API FullPN( StringCref fullpropertynamestring );
00292 
00293     ~FullPN() 
00294     {
00295       ; // do nothing
00296     }
00297 
00298     FullIDCref getFullID() const
00299     {
00300       return theFullID;
00301     }
00302 
00303     const EntityType  getEntityType() const 
00304     { 
00305       return getFullID().getEntityType(); 
00306     }
00307 
00308     SystemPathCref getSystemPath() const
00309     { 
00310       return getFullID().getSystemPath();
00311     }
00312 
00313     StringCref getID() const
00314     { 
00315       return getFullID().getID();
00316     }
00317 
00318     StringCref     getPropertyName()  const//const StringCref     getPropertyName()  const
00319     {
00320       return thePropertyName;
00321     }
00322 
00323     void setEntityType( const EntityType type )
00324     {
00325       theFullID.setEntityType( type );
00326     }
00327 
00328     void setSystemPath( SystemPathCref systempath ) 
00329     {
00330       theFullID.setSystemPath( systempath );
00331     }
00332 
00333     void setID( StringCref id ) 
00334     {
00335       theFullID.setID( id );
00336     }
00337 
00338     void setPropertyName( StringCref propertyname )
00339     {
00340       thePropertyName = propertyname;
00341     }
00342 
00343     ECELL_API const String getString() const;
00344 
00345     bool isValid() const;
00346 
00347     bool operator<( FullPNCref rhs ) const
00348     {
00349       if( getFullID() != rhs.getFullID() )
00350         {
00351           return getFullID() < rhs.getFullID();
00352         }
00353 
00354       return getPropertyName() < rhs.getPropertyName();
00355     }
00356 
00357     bool operator==( FullPNCref rhs ) const
00358     {
00359       if( getFullID() != rhs.getFullID() )
00360         {
00361           return false;
00362         }
00363 
00364       // finally compare the ID strings
00365       return getPropertyName() == rhs.getPropertyName();
00366     }
00367 
00368     bool operator!=( FullPNCref rhs ) const
00369     {
00370       return ! operator==( rhs );
00371     }
00372 
00373   private:
00374 
00375     FullID theFullID;
00376     String thePropertyName;
00377 
00378   };
00379 
00380   /** @} */ // identifier module
00381 
00382 } // namespace libecs
00383 
00384 #endif // __FULLID_HPP
00385 
00386 /*
00387   Do not modify
00388   $Author: sachiboo $
00389   $Revision: 2620 $
00390   $Date: 2006-11-24 13:15:56 +0100 (Fri, 24 Nov 2006) $
00391   $Locker$
00392 */

Generated on Mon Dec 18 07:29:46 2006 for E-CELL C++ libraries (libecs and libemc) 3.1.105 by  doxygen 1.5.1