CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondCore/ORA/src/MappingElement.h

Go to the documentation of this file.
00001 #ifndef INCLUDE_ORA_MAPPINGELEMENT_H
00002 #define INCLUDE_ORA_MAPPINGELEMENT_H
00003 
00004 //
00005 #include <map>
00006 #include <vector>
00007 #include <string>
00008 #include <memory>
00009 
00010 namespace ora {
00011 
00018   class MappingElement
00019   {
00020   public:
00021     typedef enum { Undefined = -1,
00022                    Class,
00023                    Object,
00024                    Dependency,
00025                    Primitive,
00026                    Array,
00027                    CArray,
00028                    InlineCArray,
00029                    Pointer,
00030                    Reference,
00031                    OraReference,
00032                    OraPointer,
00033                    UniqueReference,
00034                    OraArray,
00035                    Blob,
00036                    NamedReference } ElementType;
00037 
00039     static std::string classMappingElementType();
00041     static std::string objectMappingElementType();
00043     static std::string dependencyMappingElementType();
00045     static std::string primitiveMappingElementType();
00047     static std::string arrayMappingElementType();
00049     static std::string CArrayMappingElementType();
00051     static std::string inlineCArrayMappingElementType();
00053     static std::string OraReferenceMappingElementType();
00055     static std::string OraPointerMappingElementType();
00057     static std::string uniqueReferenceMappingElementType();
00059     static std::string OraArrayMappingElementType();
00061     static std::string pointerMappingElementType();
00063     static std::string referenceMappingElementType();
00065     static std::string blobMappingElementType();
00067     static std::string namedReferenceMappingElementType();
00069     static bool isValidMappingElementType( const std::string& elementType );
00070 
00072     static std::string elementTypeAsString( ElementType elementType );
00073 
00075     static ElementType elementTypeFromString( const std::string& elementType );
00076 
00077     public:
00079     typedef std::map< std::string, MappingElement >::iterator iterator;
00080     typedef std::map< std::string, MappingElement >::const_iterator const_iterator;
00081 
00082     public:
00083 
00085     MappingElement();
00086 
00088     MappingElement( const std::string& elementType,
00089                     const std::string& variableName,
00090                     const std::string& variableType,
00091                     const std::string& tableName );
00092 
00093     // Copy constructor
00094     MappingElement( const MappingElement& element);
00095 
00096     // Assignment operator
00097     MappingElement& operator=(const MappingElement& element);
00098 
00100     ~MappingElement();
00101 
00105     ElementType elementType() const;
00106 
00107     std::string elementTypeString() const;
00108 
00112     bool isDependent() const;
00113 
00117     const MappingElement& parentClassMappingElement() const;
00118     
00122     const std::string& scopeName() const;
00126     const std::string& variableName() const;
00127 
00131     const std::string& variableNameForSchema() const;
00135     const std::string& variableType() const;
00136 
00140     const std::string& tableName() const;
00141     
00145     const std::vector< std::string >& columnNames() const;
00146 
00147     std::string idColumn() const;
00148 
00149     std::string pkColumn() const;
00150 
00151     std::vector<std::string> recordIdColumns() const;
00152 
00153     std::string posColumn() const;
00154 
00158     std::vector<std::pair<std::string,std::string> > tableHierarchy() const;
00159      
00165     void alterType( const std::string& elementType );
00166     
00172     void alterTableName( const std::string& tableName );
00173 
00178     void setColumnNames( const std::vector< std::string >& columns );
00179 
00181     iterator begin();
00182     const_iterator begin() const;
00183 
00185     iterator end();
00186     const_iterator end() const;
00187 
00189     iterator find( const std::string& key );
00190     const_iterator find( const std::string& key ) const;
00191 
00193     bool removeSubElement( const std::string& key );
00194 
00204     MappingElement& appendSubElement( const std::string& elementType,
00205                                       const std::string& variableName,
00206                                       const std::string& variableType,
00207                                       const std::string& tableName );
00208 
00209     /*
00210      * replace present data with the provided source
00211      */
00212     void override(const MappingElement& source);
00213 
00214     void printXML( std::ostream& outputStream, std::string indentation="" ) const;
00215 
00216   private:
00220     ElementType m_elementType;
00224     bool m_isDependentTree;    
00232     std::string m_scopeName;
00237     std::string m_variableName;
00241     std::string m_variableNameForSchema;
00245     std::string m_variableType;
00251     std::string m_tableName;
00260     std::vector<std::string> m_columnNames;
00261     
00265     std::map< std::string, MappingElement > m_subElements;
00266 
00267   };
00268 }
00269 
00270 inline 
00271 ora::MappingElement::MappingElement():
00272   m_elementType(ora::MappingElement::Undefined),
00273   m_isDependentTree(false),
00274   m_scopeName(""),
00275   m_variableName(""),
00276   m_variableNameForSchema(""),
00277   m_variableType(""),
00278   m_tableName(""),
00279   m_columnNames(),
00280   m_subElements(){
00281 }
00282 
00283 inline 
00284 ora::MappingElement::MappingElement( const MappingElement& element):
00285   m_elementType(element.m_elementType),
00286   m_isDependentTree(element.m_isDependentTree),
00287   m_scopeName(element.m_scopeName),
00288   m_variableName(element.m_variableName),
00289   m_variableNameForSchema(element.m_variableNameForSchema),
00290   m_variableType(element.m_variableType),
00291   m_tableName(element.m_tableName),
00292   m_columnNames(element.m_columnNames),
00293   m_subElements(element.m_subElements){
00294 }
00295 
00296 inline ora::MappingElement& 
00297 ora::MappingElement::operator=(const MappingElement& element){
00298   if(this != &element){
00299      m_elementType = element.m_elementType;
00300      m_isDependentTree = element.m_isDependentTree;
00301      m_scopeName = element.m_scopeName;
00302      m_variableName = element.m_variableName;
00303      m_variableNameForSchema = element.m_variableNameForSchema;
00304      m_variableType = element.m_variableType;
00305      m_tableName = element.m_tableName;
00306      m_columnNames = element.m_columnNames;
00307      m_subElements = element.m_subElements;
00308   }
00309   return *this;
00310 }
00311 
00312 
00313 inline ora::MappingElement::iterator
00314 ora::MappingElement::begin()
00315 {
00316   return m_subElements.begin();
00317 }
00318 
00319 inline ora::MappingElement::const_iterator
00320 ora::MappingElement::begin() const
00321 {
00322   return m_subElements.begin();
00323 }
00324 
00325 inline ora::MappingElement::iterator
00326 ora::MappingElement::end()
00327 {
00328   return m_subElements.end();
00329 }
00330 
00331 inline ora::MappingElement::const_iterator
00332 ora::MappingElement::end() const
00333 {
00334   return m_subElements.end();
00335 }
00336 
00337 inline ora::MappingElement::iterator
00338 ora::MappingElement::find( const std::string& key )
00339 {
00340   return m_subElements.find( key );
00341 }
00342 
00343 inline ora::MappingElement::const_iterator
00344 ora::MappingElement::find( const std::string& key ) const
00345 {
00346   return m_subElements.find( key );
00347 }
00348 
00349 inline ora::MappingElement::ElementType
00350 ora::MappingElement::elementType() const
00351 {
00352   return m_elementType;
00353 }
00354 
00355 inline std::string
00356 ora::MappingElement::elementTypeString() const
00357 {
00358   return elementTypeAsString( m_elementType );
00359 }
00360 
00361 inline bool 
00362 ora::MappingElement::isDependent() const {
00363   return m_isDependentTree;
00364 }
00365 
00366 inline const std::string&
00367 ora::MappingElement::scopeName() const
00368 {
00369   return m_scopeName;
00370 }
00371 
00372 inline const std::string&
00373 ora::MappingElement::variableName() const
00374 {
00375   return m_variableName;
00376 }
00377 
00378 inline const std::string&
00379 ora::MappingElement::variableNameForSchema() const
00380 {
00381   return m_variableNameForSchema;
00382 }
00383 
00384 inline const std::string&
00385 ora::MappingElement::variableType() const
00386 {
00387   return m_variableType;
00388 }
00389 
00390 inline const std::string&
00391 ora::MappingElement::tableName() const
00392 {
00393   return m_tableName;
00394 }
00395 
00396 inline const std::vector< std::string >&
00397 ora::MappingElement::columnNames() const
00398 {
00399   return m_columnNames;
00400 }
00401 
00402 #endif