|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #include <stk_util/environment/product_registry.h> 00010 #include <stk_util/environment/ProductRegistry.hpp> 00011 #ifdef STK_BUILT_IN_SIERRA 00012 #include <stk_util/environment/stk_version.hpp> 00013 #else 00014 #define STK_VERSION "0.1a" 00015 #endif 00016 00017 namespace stk { 00018 00019 const std::string 00020 ProductRegistry::NAME = "Name"; 00021 00022 const std::string 00023 ProductRegistry::TITLE = "Title"; 00024 00025 const std::string 00026 ProductRegistry::VERSION = "Version"; 00027 00028 const std::string 00029 ProductRegistry::QUALIFIER = "Qualifier"; 00030 00031 const std::string 00032 ProductRegistry::BUILD_TIME = "Build Time"; 00033 00034 const std::string 00035 ProductRegistry::EXECUTABLE = "Executable"; 00036 00037 const std::string 00038 ProductRegistry::CONTACT = "Contact"; 00039 00040 const std::string 00041 ProductRegistry::ERROR = "Error"; 00042 00043 const std::string 00044 ProductRegistry::PRODUCT_TYPE = "Type"; 00045 00046 const std::string 00047 ProductRegistry::REGION_TITLE = "Region Title"; 00048 00049 const std::string 00050 ProductRegistry::BANNER_DETAIL = "Banner Detail"; 00051 00052 const std::string 00053 ProductRegistry::COPYRIGHT = "Copyright"; 00054 00055 const std::string 00056 ProductRegistry::PRODUCT_TYPE_REGION = "Region"; 00057 00058 00059 ProductRegistry & 00060 ProductRegistry::instance() 00061 { 00062 static ProductRegistry s_productRegistry; 00063 00064 return s_productRegistry; 00065 } 00066 00067 00068 const char * 00069 ProductRegistry::version() 00070 { 00071 // STK_VERSION should be a build-time define (i.e. -D flag) passed on 00072 // the compilation command line 00073 static const char *s_version = STK_VERSION; 00074 00075 return s_version; 00076 } 00077 00078 00079 ProductRegistry::AttributeMap & 00080 ProductRegistry::addTPL( 00081 const std::string & name, 00082 const std::string & version, 00083 const std::string & qualifier) 00084 { 00085 std::pair<ProductMap::iterator, bool> iit = m_productMap.insert(std::make_pair(name, AttributeMap())); 00086 ProductMap::iterator it = iit.first; 00087 if (iit.second) { 00088 (*it).second[NAME] = name.c_str(); 00089 (*it).second[VERSION] = version; 00090 (*it).second[QUALIFIER] = qualifier; 00091 } 00092 else { 00093 std::string ¤t_version = (*it).second[VERSION]; 00094 std::string ¤t_qualifer = (*it).second[QUALIFIER]; 00095 if (current_version.empty()) 00096 current_version = version; 00097 if (current_qualifer.empty()) 00098 current_qualifer = qualifier; 00099 if (current_version != version || current_qualifer != qualifier) { 00100 (*it).second[ERROR] = std::string("Product registration of ") + (*it).first + " version/qualifier conflict, " 00101 + " initially " + (*it).second[VERSION] + "/" + (*it).second[QUALIFIER] 00102 + " tried to change to " + version + "/" + qualifier; 00103 setRegistryInvalid(); 00104 } 00105 } 00106 00107 return (*it).second; 00108 } 00109 00110 00111 ProductRegistry::AttributeMap & 00112 ProductRegistry::addProduct(const std::string & name) 00113 { 00114 std::pair<ProductMap::iterator, bool> iit = m_productMap.insert(std::make_pair(name, AttributeMap())); 00115 ProductMap::iterator it = iit.first; 00116 if (iit.second) { 00117 (*it).second[NAME] = name.c_str(); 00118 } 00119 00120 return (*it).second; 00121 } 00122 00123 00124 ProductRegistry::AttributeMap & 00125 ProductRegistry::addRegion( 00126 const std::string & name) 00127 { 00128 AttributeMap &attribute_map = addProduct(name); 00129 attribute_map[ProductRegistry::PRODUCT_TYPE] = ProductRegistry::PRODUCT_TYPE_REGION; 00130 attribute_map[ProductRegistry::VERSION] = ProductRegistry::version(); 00131 00132 return attribute_map; 00133 } 00134 00135 00136 ProductRegistry::AttributeMap & 00137 ProductRegistry::getProductAttributeMap( 00138 const std::string & name) 00139 { 00140 return m_productMap[name]; 00141 } 00142 00143 00144 const std::string & 00145 ProductRegistry::getProductAttribute( 00146 const std::string & name, 00147 const std::string & attribute) const 00148 { 00149 return m_productMap[name][attribute]; 00150 } 00151 00152 00153 std::string & 00154 ProductRegistry::getProductAttribute( 00155 const std::string & name, 00156 const std::string & attribute) 00157 { 00158 return m_productMap[name][attribute]; 00159 } 00160 00161 00162 void 00163 ProductRegistry::setProductAttribute( 00164 const std::string & name, 00165 const std::string & attribute, 00166 const std::string & value) 00167 { 00168 m_productMap[name][attribute] = value; 00169 } 00170 00171 } // namespace stk 00172 00173 extern "C" { 00174 00175 void 00176 product_registry_add( 00177 const char * name ) 00178 { 00179 stk::ProductRegistry::instance().addProduct(name ? name : "<unknown>"); 00180 } 00181 00182 00183 void 00184 product_registry_add_tpl( 00185 const char * name, 00186 const char * version, 00187 const char * qualifier ) 00188 { 00189 stk::ProductRegistry::instance().addTPL(name ? name : "<unknown>", version ? version : "", qualifier ? qualifier : ""); 00190 } 00191 00192 00193 size_t 00194 product_registry_size() 00195 { 00196 return stk::ProductRegistry::instance().getProductMap().size(); 00197 } 00198 00199 } // extern "C"