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     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     const SystemPathCref getSystemPath()    const 
00168     { 
00169       return theSystemPath; 
00170     }
00171 
00172     const 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     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     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     FullPN( StringCref fullpropertynamestring );
00292 
00293     ~FullPN() 
00294     {
00295       ; // do nothing
00296     }
00297 
00298 
00299     const FullIDCref     getFullID()        const
00300     {
00301       return theFullID;
00302     }
00303 
00304     const EntityType  getEntityType() const 
00305     { 
00306       return getFullID().getEntityType(); 
00307     }
00308 
00309     const SystemPathCref getSystemPath()    const
00310     { 
00311       return getFullID().getSystemPath();
00312     }
00313 
00314     const StringCref     getID()            const
00315     { 
00316       return getFullID().getID();
00317     }
00318 
00319     const StringCref     getPropertyName()  const
00320     {
00321       return thePropertyName;
00322     }
00323 
00324     void setEntityType( const EntityType type )
00325     {
00326       theFullID.setEntityType( type );
00327     }
00328 
00329     void setSystemPath( SystemPathCref systempath ) 
00330     {
00331       theFullID.setSystemPath( systempath );
00332     }
00333 
00334     void setID( StringCref id ) 
00335     {
00336       theFullID.setID( id );
00337     }
00338 
00339     void setPropertyName( StringCref propertyname )
00340     {
00341       thePropertyName = propertyname;
00342     }
00343 
00344     const String getString() const;
00345 
00346     bool isValid() const;
00347 
00348     bool operator<( FullPNCref rhs ) const
00349     {
00350       if( getFullID() != rhs.getFullID() )
00351         {
00352           return getFullID() < rhs.getFullID();
00353         }
00354 
00355       return getPropertyName() < rhs.getPropertyName();
00356     }
00357 
00358     bool operator==( FullPNCref rhs ) const
00359     {
00360       if( getFullID() != rhs.getFullID() )
00361         {
00362           return false;
00363         }
00364 
00365       // finally compare the ID strings
00366       return getPropertyName() == rhs.getPropertyName();
00367     }
00368 
00369     bool operator!=( FullPNCref rhs ) const
00370     {
00371       return ! operator==( rhs );
00372     }
00373 
00374   private:
00375 
00376     FullID theFullID;
00377     String thePropertyName;
00378 
00379   };
00380 
00381   /** @} */ // identifier module
00382 
00383 } // namespace libecs
00384 
00385 #endif // __FULLID_HPP
00386 
00387 /*
00388   Do not modify
00389   $Author: shafi $
00390   $Revision: 2529 $
00391   $Date: 2005-11-19 10:36:40 +0100 (Sat, 19 Nov 2005) $
00392   $Locker$
00393 */

Generated on Fri Apr 28 10:38:29 2006 for E-CELL C++ libraries (libecs and libemc) 3.1.105 by  doxygen 1.4.6