SheafSystem  0.0.0.0
standard_version_index.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
18 // Definitions for standard_version_index facet of namespace sheaf.
19 
20 
21 #include "SheafSystem/standard_version_index.h"
22 
23 #include "SheafSystem/assert_contract.h"
24 #include "SheafSystem/std_string.h"
25 
26 using namespace std;
27 
28 namespace
29 {
30 const int STANDARD_VERSION_INDEX_CT =
31  sheaf::STANDARD_VERSION_INDEX_END - sheaf::STANDARD_VERSION_INDEX_BEGIN;
32 }
33 
36 sheaf::
38 {
39  return x =
40  (x == STANDARD_VERSION_INDEX_END) ?
41  STANDARD_VERSION_INDEX_BEGIN :
43 };
44 
46 const std::string&
47 sheaf::
49 {
50  // Preconditions:
51 
52  // Body:
53 
54  static const string names[STANDARD_VERSION_INDEX_CT+1] =
55  {
56  "CURRENT_MEMBER_VERSION",
57  "CURRENT_HOST_VERSION",
58  "COARSEST_COMMON_REFINEMENT_VERSION",
59  "NOT_A_STANDARD_VERSION_INDEX" // Must be one more than last std id.
60  };
61 
62  const string* lresult_ptr = &names[STANDARD_VERSION_INDEX_CT];
63 
64  pod_index_type lpt = xpt;
66  {
67  lresult_ptr = &names[lpt - STANDARD_VERSION_INDEX_BEGIN];
68  }
69 
70  const string& result = *lresult_ptr;
71 
72  // Postconditions:
73 
74  ensure(!result.empty());
75 
76  // Exit:
77 
78  return result;
79 }
80 
83 sheaf::
84 standard_version_index_from_name(const std::string& xname)
85 {
86  standard_version_index result = NOT_A_STANDARD_VERSION_INDEX;
87  for(standard_version_index i=STANDARD_VERSION_INDEX_BEGIN;
88  i< STANDARD_VERSION_INDEX_END;
89  ++i)
90  {
91  if(standard_version_index_to_name(i) == xname)
92  {
93  result = i;
94  break;
95  }
96  }
97 
98  return result;
99 }
100 
103 sheaf::
105 {
106  // Preconditions:
107 
108  // Body:
109 
110  static const standard_version_index ids[STANDARD_VERSION_INDEX_CT+1] =
111  {
112  CURRENT_MEMBER_VERSION,
113  CURRENT_HOST_VERSION,
114  COARSEST_COMMON_REFINEMENT_VERSION,
115  NOT_A_STANDARD_VERSION_INDEX
116  };
117 
118  standard_version_index result = ids[STANDARD_VERSION_INDEX_CT];
119  if(is_standard_version_index(xindex))
120  {
121  result = ids[xindex - STANDARD_VERSION_INDEX_BEGIN];
122  }
123 
124  // Postconditions:
125 
126  // Exit:
127 
128  return result;
129 }
130 
132 bool
133 sheaf::
135 {
136  bool result;
137 
138  // Preconditions:
139 
140  // Body:
141 
142  result =
143  (STANDARD_VERSION_INDEX_BEGIN <= xindex) && (xindex < STANDARD_VERSION_INDEX_END);
144 
145  // Postconditions:
146 
147  // Exit
148 
149  return result;
150 }
151 
STL namespace.
SHEAF_DLL_SPEC const std::string & standard_version_index_to_name(standard_version_index xpt)
The name of the enumerator xpt.
SHEAF_DLL_SPEC bool is_standard_version_index(pod_index_type xindex)
True if xindex is a valid primitive index.
standard_version_index
Ids for standard poset versions.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
SHEAF_DLL_SPEC standard_version_index standard_version_index_from_index(pod_index_type xindex)
The enumerator corresponding to primitive index xindex.
SHEAF_DLL_SPEC namespace_member_index & operator++(namespace_member_index &x)
Prefix increment operator for namespace_member_index.
SHEAF_DLL_SPEC standard_version_index standard_version_index_from_name(const std::string &xname)
The enumerator with name xname.