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

NamedO.h

Go to the documentation of this file.
00001 
00008 #ifndef __NAMEDO_H
00009 #define __NAMEDO_H
00010 
00011 #include <string>
00012 #include <iosfwd>
00013 
00014 // Class NamedO
00016 
00028 class NamedO {
00029   public: 
00030     // Constructors
00032     explicit NamedO(const char *name_ = "?"         
00033                    );
00035     explicit NamedO(const std::string& name_         
00036                    );
00038              NamedO(const std::string& name_,        
00039                     const std::string& definition_   
00040                    );
00041     
00043     virtual const char *getName() const;
00044     
00046     virtual const char *getDefinition() const;
00047     
00049     virtual NamedO& setName (const std::string& newname  
00050                             );
00051     virtual NamedO& setName (const char *newname         
00052                             );
00054     virtual NamedO& setDefinition (const std::string& newdef   
00055                                   );
00056                                   
00058     virtual std::ostream& print (std::ostream& os) const;                       
00059 
00061 
00065     static NamedO *getObject (const std::string& name  
00066                               ); 
00068 
00072     static NamedO *getObject (const char * name  
00073                               ); 
00074                               
00075     template<class T>
00076     static T *getObject (const std::string& name  
00077                          ) {
00078       return dynamic_cast<T *>(getObject (name));
00079     }                 
00080                          
00081     template<class T>
00082     static T *getObject (const char * name  
00083                          ) {
00084       return dynamic_cast<T *>(getObject (name));
00085     }                  
00086                               
00088     static std::ostream& listObjects(std::ostream& os);
00089 
00090 
00092     virtual void destroy();
00093     
00094     // Helper functions for name creation
00096     static std::string str (char c        
00097                            );
00099     static std::string str (const char *s 
00100                            );
00102     static std::string str (int i        
00103                            );
00105     static std::string str (int i,       
00106                             int wide     
00107                            );
00109     static std::string str (float f        
00110                            );
00112     static std::string str (double d     
00113                            );
00115     static std::string str (bool b        
00116                            );
00117 
00118   protected:  
00120     virtual ~NamedO();
00121     
00122   private:
00124     void reg();
00126     void unreg();
00127     
00129     NamedO (const NamedO& source);
00131     NamedO& operator= (const NamedO& source);
00132     
00134     static void initMap();
00135     
00136     // Data members
00137     std::string name;         
00138     std::string definition;   
00139 
00140     
00141 // For a discussion of the initialization technique used here, see
00142 // B. Stroustrup, The C++ programming language, 3rd ed., p. 639.
00143   public:
00144     struct Init {
00145       Init() {
00146         if (count++ == 0) initMap();
00147       }
00148       
00149       ~Init() {
00150         --count;
00151       }
00152       
00153       static int count;  
00154     };
00155     friend class NamedO::Init;
00156 };
00157 
00159 
00160 std::ostream& operator<< (std::ostream& os, const NamedO& rhs);
00161 
00162 static NamedO::Init the_NamedO_Init_Object;
00163 
00164 #endif /* #ifndef __NAMEDO_H */

Generated on Thu Oct 26 12:52:58 2006 for SFH by doxygen 1.3.2