Sierra Toolkit  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ProductRegistry.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
10 #include <stk_util/environment/ProductRegistry.hpp>
11 #ifdef STK_BUILT_IN_SIERRA
12 #include <stk_util/environment/stk_version.hpp>
13 #else
14 #define STK_VERSION "0.1a"
15 #endif
16 
17 namespace stk {
18 
19 const std::string
20 ProductRegistry::NAME = "Name";
21 
22 const std::string
23 ProductRegistry::TITLE = "Title";
24 
25 const std::string
26 ProductRegistry::VERSION = "Version";
27 
28 const std::string
29 ProductRegistry::QUALIFIER = "Qualifier";
30 
31 const std::string
32 ProductRegistry::BUILD_TIME = "Build Time";
33 
34 const std::string
35 ProductRegistry::EXECUTABLE = "Executable";
36 
37 const std::string
38 ProductRegistry::CONTACT = "Contact";
39 
40 const std::string
41 ProductRegistry::ERROR = "Error";
42 
43 const std::string
45 
46 const std::string
47 ProductRegistry::REGION_TITLE = "Region Title";
48 
49 const std::string
50 ProductRegistry::BANNER_DETAIL = "Banner Detail";
51 
52 const std::string
53 ProductRegistry::COPYRIGHT = "Copyright";
54 
55 const std::string
57 
58 
59 ProductRegistry &
61 {
62  static ProductRegistry s_productRegistry;
63 
64  return s_productRegistry;
65 }
66 
67 
68 const char *
70 {
71  // STK_VERSION should be a build-time define (i.e. -D flag) passed on
72  // the compilation command line
73  static const char *s_version = STK_VERSION;
74 
75  return s_version;
76 }
77 
78 
81  const std::string & name,
82  const std::string & version,
83  const std::string & qualifier)
84 {
85  std::pair<ProductMap::iterator, bool> iit = m_productMap.insert(std::make_pair(name, AttributeMap()));
86  ProductMap::iterator it = iit.first;
87  if (iit.second) {
88  (*it).second[NAME] = name.c_str();
89  (*it).second[VERSION] = version;
90  (*it).second[QUALIFIER] = qualifier;
91  }
92  else {
93  std::string &current_version = (*it).second[VERSION];
94  std::string &current_qualifer = (*it).second[QUALIFIER];
95  if (current_version.empty())
96  current_version = version;
97  if (current_qualifer.empty())
98  current_qualifer = qualifier;
99  if (current_version != version || current_qualifer != qualifier) {
100  (*it).second[ERROR] = std::string("Product registration of ") + (*it).first + " version/qualifier conflict, "
101  + " initially " + (*it).second[VERSION] + "/" + (*it).second[QUALIFIER]
102  + " tried to change to " + version + "/" + qualifier;
104  }
105  }
106 
107  return (*it).second;
108 }
109 
110 
112 ProductRegistry::addProduct(const std::string & name)
113 {
114  std::pair<ProductMap::iterator, bool> iit = m_productMap.insert(std::make_pair(name, AttributeMap()));
115  ProductMap::iterator it = iit.first;
116  if (iit.second) {
117  (*it).second[NAME] = name.c_str();
118  }
119 
120  return (*it).second;
121 }
122 
123 
126  const std::string & name)
127 {
128  AttributeMap &attribute_map = addProduct(name);
131 
132  return attribute_map;
133 }
134 
135 
138  const std::string & name)
139 {
140  return m_productMap[name];
141 }
142 
143 
144 const std::string &
146  const std::string & name,
147  const std::string & attribute) const
148 {
149  return m_productMap[name][attribute];
150 }
151 
152 
153 std::string &
155  const std::string & name,
156  const std::string & attribute)
157 {
158  return m_productMap[name][attribute];
159 }
160 
161 
162 void
164  const std::string & name,
165  const std::string & attribute,
166  const std::string & value)
167 {
168  m_productMap[name][attribute] = value;
169 }
170 
171 } // namespace stk
172 
173 extern "C" {
174 
175 void
177  const char * name )
178 {
179  stk::ProductRegistry::instance().addProduct(name ? name : "<unknown>");
180 }
181 
182 
183 void
185  const char * name,
186  const char * version,
187  const char * qualifier )
188 {
189  stk::ProductRegistry::instance().addTPL(name ? name : "<unknown>", version ? version : "", qualifier ? qualifier : "");
190 }
191 
192 
193 size_t
195 {
197 }
198 
199 } // extern "C"
void setProductAttribute(const std::string &name, const std::string &attribute, const std::string &value)
Member function setAttribute sets the attribute for the named poduct to the specified value...
AttributeMap & addRegion(const std::string &name)
Member function addRegion add a region as a product to the registry. A region product is a product wi...
static const std::string PRODUCT_TYPE
Product&#39;s product_type attribute.
static const std::string REGION_TITLE
Product&#39;s region_title attribute.
void product_registry_add(const char *name)
Extern &quot;C&quot; function product_registry_add provides a means for c programs to register a product...
static const std::string NAME
Product&#39;s name attribute.
static const std::string PRODUCT_TYPE_REGION
Region product_type value.
static const std::string TITLE
Product&#39;s title attribute.
static const std::string BANNER_DETAIL
Product&#39;s additional banner info attribute.
static const std::string COPYRIGHT
Product&#39;s copyright information.
static ProductRegistry & instance()
Member function instance returns a reference to the registry singleton.
AttributeMap & getProductAttributeMap(const std::string &name)
Member function getProduct returns a reference to the product attribute map.
static const std::string QUALIFIER
TPL&#39;s qualifier attribute.
AttributeMap & addProduct(const std::string &name)
Member function addProduct adds a product to the registry.
AttributeMap & addTPL(const std::string &name, const std::string &version, const std::string &qualifier="")
Member function addTPL adds a product to the registry. A product always has the VERSION and QUALIFIER...
static const char * version()
Member function version returns the version number of the combined product.
static const std::string CONTACT
Product&#39;s contact attribute.
size_t product_registry_size()
Extern &quot;C&quot; function product_registry_size returns the number of products in the registry.
Class ProductRegistry maps product names and attributes to brief descriptive values. Each added product has at a minimum the NAME value initialized. A region type product also has the PRODUCT_TYPE set to PRODUCT_TYPE_REGION.
static const std::string EXECUTABLE
Product&#39;s executable attribute.
std::map< std::string, std::string > AttributeMap
Map of attribute keyword to value.
void setRegistryInvalid()
Member function setRegistryInvalid marks th registry as contain a conflict of some sort...
const std::string & getProductAttribute(const std::string &name, const std::string &attribute) const
Member function getAttribute returns the attribute for the named product.
static const std::string ERROR
Product&#39;s error attribute.
void product_registry_add_tpl(const char *name, const char *version, const char *qualifier)
Extern &quot;C&quot; function product_registry_add_tpl provides a means for c programs to register a tpl...
static const std::string VERSION
TPL&#39;s version attribute.
ProductMap & getProductMap() const
Member function getProductMap returns a reference to the map of all products.
static const std::string BUILD_TIME
Product&#39;s build_time attribute.