OMKName.h

Go to the documentation of this file.
00001 
00002 /*
00003 * This file is part of openMask � INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00004 * 
00005 * The Software has been developped within the Siames Project. 
00006 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00007 * 
00008 * The Software has been registered with the Agence pour la Protection des
00009 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00010 *
00011 * This file may be distributed under the terms of the Q Public License
00012 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00013 * LICENSE.QPL included in the packaging of this file.
00014 *
00015 * Licensees holding valid specific licenses issued by INRIA, CNRS or Universit� de Rennes 1 
00016 * for the software may use this file in accordance with that specific license 
00017 *
00018 */
00019 #ifndef NameHEADER
00020 #define NameHEADER
00021 
00022 #include "OMKBase.h"
00023 
00024 #ifdef _MSC_VER
00025 #  include <hash_map>
00026 #else
00027 #  include <ext/hash_map>
00028 #endif
00029 
00030 #include <string>
00031 
00032 namespace OMK
00033 {
00034 class NameServer;
00073 class OMK_API Name : public OMK::Type::Base 
00074 {
00075 public:
00078   Name();
00079 
00080 
00083   Name(const std::string &);
00084 
00085 
00088   Name(const char * );
00089 
00090 
00093   Name(const Name &); 
00094 
00095 
00098   virtual ~Name();
00099 
00102   bool undefined() const { return 0 == _identifier ; }
00103 
00106   virtual Type::PolatorNT * createPolator(void);
00107 
00108 
00111   virtual const char * getCString() const;
00112 
00113 
00116   virtual const std::string & getString() const;
00117 
00118 
00121   virtual void insertInStream(std::ostream & out) const;
00122 
00123 
00126   virtual void extract(std::istream & in);
00127 
00128 
00130   virtual void unpack (IncomingSynchronisationMessage &) ;
00131 
00132 
00134   virtual void pack (OutgoingSynchronisationMessage &) const ;
00135 
00136 
00140 
00143   virtual Name & operator = (const Name &);
00144 
00145 
00148   virtual Name & operator = (const char * );
00149 
00150 
00153   virtual Name & operator = (const std::string &);
00154 
00155 
00158   inline friend bool operator == (const Name & first , const Name & second) ;
00159 
00162   inline friend bool operator != (const Name & first , const Name & second) ;
00163 
00167   friend bool OMK_API operator < (const Name &Source1, const Name &Source2);
00168 
00169 
00173   friend bool OMK_API operator > (const Name &Source1, const Name &Source2);
00174 
00175 
00179   friend bool OMK_API operator <= (const Name &Source1, const Name &Source2);
00180 
00181 
00185   friend bool OMK_API operator >= (const Name &Source1, const Name &Source2);
00186 
00187 
00188 
00190 
00191 
00195   static NameServer * getNameServer () ;
00196 
00197 
00201   static void setNameServer(NameServer * ) ;
00202 
00203 
00206   typedef long idType;
00207 
00208 
00210   static const idType _maxReservedId ;
00211 
00212 
00214 #ifdef _MSC_VER
00215   struct hash_compare_Name : public stdext::hash_compare<Name>
00216   {
00217     //dont't hash on _identifiers, because they might change, breaking all hash maps
00218     size_t operator() ( const Name& s ) const
00219     {
00220       return stdext::hash_compare<std::string>()( s.getString() ) ;
00221     }
00222 
00223     bool operator()( const Name& x, const Name& y ) const 
00224     {
00225       return x.getString() < y.getString() ;
00226     }
00227   } ;
00228 #else
00229   struct hash_compare_Name : public __gnu_cxx::hash<Name>
00230   {
00231     //dont't hash on _identifiers, because they might change, breaking all hash maps
00232     size_t operator() ( const Name& s ) const
00233     {
00234       return __gnu_cxx::hash<const char*>()( s.getCString() ) ;
00235     }
00236 
00237     bool operator()( const Name& x, const Name& y ) const 
00238     {
00239       return x.getString() < y.getString() ;
00240     }
00241   } ;
00242 #endif
00243 
00244 protected:
00245   friend class OMK::NameServer ;
00246 
00251   virtual void changeId ( idType oldId, idType newId ) ;
00252 
00254   static NameServer * _nameServer ;
00255 
00258   explicit Name( idType ) ;
00259 
00262   idType _identifier;
00263 
00264 };
00265 
00272 inline bool operator == ( const Name & a, const Name & b )
00273 {
00274   return !( a != b );
00275 }
00276 
00282 // BenC 28/02/2006
00283 inline bool operator == ( const Name & a, const char * b )
00284 {
00285   return !( a != b ) ;
00286 }
00292 // BenC 28/02/2006
00293 inline bool operator == ( const char * a, const Name & b )
00294 {
00295   return b == a ;
00296 }
00297 
00298 
00299 
00302 inline bool operator != ( const Name & first , const Name & second )
00303 {
00304   return first._identifier != second._identifier;
00305 }
00311 // BenC 28/02/2006
00312 inline bool operator != ( const Name & a, const char * b )
00313 {
00314   return a.getString() != b ;
00315 }
00321 // BenC 28/02/2006
00322 inline bool operator != ( const char * a, const Name & b )
00323 {
00324   return b != a;
00325 }
00326 
00327 
00328 
00333 bool OMK_API operator < (const Name &Source1, const Name &Source2);
00334 
00335 
00340 bool OMK_API operator > (const Name &Source1, const Name &Source2);
00341 
00342 
00347 bool OMK_API operator <= (const Name &Source1, const Name &Source2);
00348 
00349 
00354 bool OMK_API operator >= (const Name &Source1, const Name &Source2);
00355 
00356 } //namespace OMK
00358 #endif

logo OpenMask

Documentation generated on Mon Jun 9 11:45:57 2008

Generated with doxygen by Dimitri van Heesch ,   1997-2007