Sierra Toolkit  Version of the Day
ProductRegistry.cpp
1 // Copyright (c) 2013, Sandia Corporation.
2 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
3 // the U.S. Government retains certain rights in this software.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of Sandia Corporation nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
33 
35 #include <stk_util/environment/ProductRegistry.hpp>
36 #ifdef STK_BUILT_IN_SIERRA
37 #include <stk_util/environment/stk_version.hpp>
38 #else
39 #define STK_VERSION "0.1a"
40 #endif
41 
42 namespace stk_classic {
43 
44 const std::string
45 ProductRegistry::NAME = "Name";
46 
47 const std::string
48 ProductRegistry::TITLE = "Title";
49 
50 const std::string
51 ProductRegistry::VERSION = "Version";
52 
53 const std::string
54 ProductRegistry::QUALIFIER = "Qualifier";
55 
56 const std::string
57 ProductRegistry::BUILD_TIME = "Build Time";
58 
59 const std::string
60 ProductRegistry::EXECUTABLE = "Executable";
61 
62 const std::string
63 ProductRegistry::CONTACT = "Contact";
64 
65 const std::string
66 ProductRegistry::ERROR = "Error";
67 
68 const std::string
70 
71 const std::string
72 ProductRegistry::REGION_TITLE = "Region Title";
73 
74 const std::string
75 ProductRegistry::BANNER_DETAIL = "Banner Detail";
76 
77 const std::string
78 ProductRegistry::COPYRIGHT = "Copyright";
79 
80 const std::string
82 
83 
84 ProductRegistry &
86 {
87  static ProductRegistry s_productRegistry;
88 
89  return s_productRegistry;
90 }
91 
92 
93 const char *
95 {
96  // STK_VERSION should be a build-time define (i.e. -D flag) passed on
97  // the compilation command line
98  static const char *s_version = STK_VERSION;
99 
100  return s_version;
101 }
102 
103 
106  const std::string & name,
107  const std::string & version,
108  const std::string & qualifier)
109 {
110  std::pair<ProductMap::iterator, bool> iit = m_productMap.insert(std::make_pair(name, AttributeMap()));
111  ProductMap::iterator it = iit.first;
112  if (iit.second) {
113  (*it).second[NAME] = name.c_str();
114  (*it).second[VERSION] = version;
115  (*it).second[QUALIFIER] = qualifier;
116  }
117  else {
118  std::string &current_version = (*it).second[VERSION];
119  std::string &current_qualifer = (*it).second[QUALIFIER];
120  if (current_version.empty())
121  current_version = version;
122  if (current_qualifer.empty())
123  current_qualifer = qualifier;
124  if (current_version != version || current_qualifer != qualifier) {
125  (*it).second[ERROR] = std::string("Product registration of ") + (*it).first + " version/qualifier conflict, "
126  + " initially " + (*it).second[VERSION] + "/" + (*it).second[QUALIFIER]
127  + " tried to change to " + version + "/" + qualifier;
129  }
130  }
131 
132  return (*it).second;
133 }
134 
135 
137 ProductRegistry::addProduct(const std::string & name)
138 {
139  std::pair<ProductMap::iterator, bool> iit = m_productMap.insert(std::make_pair(name, AttributeMap()));
140  ProductMap::iterator it = iit.first;
141  if (iit.second) {
142  (*it).second[NAME] = name.c_str();
143  }
144 
145  return (*it).second;
146 }
147 
148 
151  const std::string & name)
152 {
153  AttributeMap &attribute_map = addProduct(name);
156 
157  return attribute_map;
158 }
159 
160 
163  const std::string & name)
164 {
165  return m_productMap[name];
166 }
167 
168 
169 const std::string &
171  const std::string & name,
172  const std::string & attribute) const
173 {
174  return m_productMap[name][attribute];
175 }
176 
177 
178 std::string &
180  const std::string & name,
181  const std::string & attribute)
182 {
183  return m_productMap[name][attribute];
184 }
185 
186 
187 void
189  const std::string & name,
190  const std::string & attribute,
191  const std::string & value)
192 {
193  m_productMap[name][attribute] = value;
194 }
195 
196 } // namespace stk_classic
197 
198 extern "C" {
199 
200 void
202  const char * name )
203 {
204  stk_classic::ProductRegistry::instance().addProduct(name ? name : "<unknown>");
205 }
206 
207 void
209  const char * name,
210  const char * version,
211  const char * qualifier )
212 {
213  stk_classic::ProductRegistry::instance().addTPL(name ? name : "<unknown>", version ? version : "", qualifier ? qualifier : "");
214 }
215 
216 } // extern "C"
static const std::string BANNER_DETAIL
Product&#39;s additional banner info attribute.
void product_registry_add(const char *name)
Extern "C" function product_registry_add provides a means for c programs to register a product...
static const std::string TITLE
Product&#39;s title attribute.
static const std::string PRODUCT_TYPE_REGION
Region product_type value.
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...
static const std::string BUILD_TIME
Product&#39;s build_time attribute.
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 CONTACT
Product&#39;s contact attribute.
static const char * version()
Member function version returns the version number of the combined product.
static ProductRegistry & instance()
Member function instance returns a reference to the registry singleton.
static const std::string REGION_TITLE
Product&#39;s region_title attribute.
const std::string & getProductAttribute(const std::string &name, const std::string &attribute) const
Member function getAttribute returns the attribute for the named product.
Sierra Toolkit.
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 std::string QUALIFIER
TPL&#39;s qualifier attribute.
static const std::string EXECUTABLE
Product&#39;s executable attribute.
static const std::string COPYRIGHT
Product&#39;s copyright information.
std::map< std::string, std::string > AttributeMap
Map of attribute keyword to 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...
void product_registry_add_tpl(const char *name, const char *version, const char *qualifier)
Extern "C" function product_registry_add_tpl provides a means for c programs to register a tpl...
static const std::string ERROR
Product&#39;s error attribute.
static const std::string VERSION
TPL&#39;s version attribute.
static const std::string PRODUCT_TYPE
Product&#39;s product_type attribute.
void setRegistryInvalid()
Member function setRegistryInvalid marks th registry as contain a conflict of some sort...
static const std::string NAME
Product&#39;s name attribute.
AttributeMap & addProduct(const std::string &name)
Member function addProduct adds a product to the registry.
AttributeMap & getProductAttributeMap(const std::string &name)
Member function getProduct returns a reference to the product attribute map.