NIREP

C:/Programs/source/NIREP/DisplayDescription/ResourceDescriptionList/BasicDescription.h

00001 /***************************************************************************************
00002 *   Programmer: Gary E. Christensen
00003 *   Date: 6/24/2010
00004 *   Name: BasicDescription
00005 *   Purpose: This class holds descriptive information about namespaces,
00006 *      algorithms, and coordinate systems.
00007 *      Objects of this class are filled with information by parsing a resource description list.
00008 *      All non-required tags and their values are stored in the attribute list.
00009 *   Optional XML Tags:
00010 *      attributes - contains user defined XML tags and values
00011 ******************************************************************************************/
00012 #pragma once
00013 #ifndef _BASIC_DESCRIPTION_H_
00014 #define _BASIC_DESCRIPTION_H_
00015 
00016 #include <string>
00017 #include <map>
00018 #include <algorithm>
00019 
00020 #include "tinyxml.h"
00021 
00022 class BasicDescription {
00023 public:
00024         typedef std::map<std::string, std::string> AttributeList;
00025 
00028   BasicDescription(){};
00029 
00030         BasicDescription(const std::string & default_ns){ m_ns = default_ns;};
00031 
00033         BasicDescription(TiXmlElement * descrip){
00034                 FillUsingDom(descrip);
00035         };
00036   
00037   BasicDescription(TiXmlElement * descrip, const std::string & default_ns){
00038     m_ns = default_ns;
00039                 FillUsingDom(descrip);
00040         };
00041 
00043         ~BasicDescription(){
00044                 this->Clear(); 
00045         };
00046 
00048         void Clear(){
00049                 m_id.clear();
00050                 m_ns.clear();
00051                 ClearAttributes(); 
00052         }
00053 
00055         const std::string & GetID(){ return m_id;}
00056         void SetID(const std::string & id){ 
00057     m_id = id;
00058     // convert m_id to lower case for case insensitivity strin comparison
00059     std::transform(m_id.begin(), m_id.end(), m_id.begin(), ::tolower);
00060   }
00061         
00063         const std::string & GetNameSpace(){ return m_ns;}
00064         void SetNameSpace(const std::string & ns){ 
00065     m_ns = ns; 
00066     // convert m_ns to lower case for case insensitivity strin comparison
00067     std::transform(m_ns.begin(), m_ns.end(), m_ns.begin(), ::tolower);
00068   }
00069 
00072   const std::string CreateNSID(){ return m_ns + "|" + m_id;}
00073 
00074         // Convert back and forth from DOM = Document Object Model
00075         TiXmlElement * CreateDOM(const std::string & tag);
00076         bool FillUsingDom(TiXmlElement * descrip);
00077 
00078         // Accessor functions for non-required data description attributes
00079         const std::string GetAttribute(std::string key){ 
00080     // convert key to lower case for case insensitivity strin comparison
00081     std::transform(key.begin(), key.end(), key.begin(), ::tolower);
00082 
00083                 // return m_attribute[key]; Incorrect.  This command adds a new empty entry to map if key is missing
00084                 AttributeList::iterator iter = m_attribute.find(key);
00085                 if (iter != m_attribute.end()){
00086                         return iter->second;
00087                 } else {
00088                         return "";
00089                 }
00090         }
00091         void AddAttribute(std::string key, const std::string & value){ 
00092     // convert key to lower case for case insensitivity strin comparison
00093     std::transform(key.begin(), key.end(), key.begin(), ::tolower);
00094 
00095     m_attribute[key] = value; 
00096   }
00097         void ClearAttributes(){ m_attribute.clear(); }
00098 
00099 protected:
00100         std::string   m_id;            // description id, e.g., 001, 002
00101   std::string   m_ns;            // namespace, e.g., na0
00102         AttributeList m_attribute;     // Stores non-required attributes listed in 
00103                                        // data resource file, e.g., name, description, 
00104                                        // modality, scanner, etc
00105 };
00106 
00107 #endif
00108 
00109 
 All Classes Functions Variables Typedefs Enumerations Enumerator