SheafSystem  0.0.0.0
standard_subposet_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_subposet_index facet of namespace sheaf.
19 
20 #include "SheafSystem/standard_subposet_index.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/std_string.h"
24 
25 using namespace std;
26 
27 namespace
28 {
29 const int STANDARD_SUBPOSET_INDEX_CT =
30  sheaf::STANDARD_SUBPOSET_INDEX_END - sheaf::STANDARD_SUBPOSET_INDEX_BEGIN;
31 }
32 
33 
36 sheaf::
38 {
39  return x =
40  (x == STANDARD_SUBPOSET_INDEX_END) ?
41  STANDARD_SUBPOSET_INDEX_BEGIN :
43 };
44 
46 const std::string&
47 sheaf::
49 {
50  // Preconditions:
51 
52  // Body:
53 
54  static const string names[STANDARD_SUBPOSET_INDEX_CT+1] =
55  {
56  "TOC_INDEX",
57  "STANDARD_SUBPOSET_INDEX_PLACEHOLDER_MINUS_1",
58  "JIMS_INDEX",
59  "WHOLE_INDEX",
60  "RESIDENT_INDEX",
61  "NOT_A_STANDARD_SUBPOSET_INDEX"
62  };
63 
64  const string* lresult_ptr = &names[STANDARD_SUBPOSET_INDEX_CT];
65 
66  pod_index_type lindex = xindex;
67  if(is_standard_subposet_index(lindex))
68  {
69  lresult_ptr = &names[lindex - STANDARD_SUBPOSET_INDEX_BEGIN];
70  }
71 
72  const string& result = *lresult_ptr;
73 
74  // Postconditions:
75 
76  ensure(!result.empty());
77 
78  // Exit:
79 
80  return result;
81 }
82 
85 sheaf::
86 standard_subposet_index_from_name(const std::string& xname)
87 {
88  standard_subposet_index result = NOT_A_STANDARD_SUBPOSET_INDEX;
89  for(standard_subposet_index i=STANDARD_SUBPOSET_INDEX_BEGIN;
90  i< STANDARD_SUBPOSET_INDEX_END;
91  ++i)
92  {
93  if(standard_subposet_index_to_name(i) == xname)
94  {
95  result = i;
96  break;
97  }
98  }
99 
100  return result;
101 }
102 
105 sheaf::
107 {
108  // Preconditions:
109 
110  // Body:
111 
112  static const standard_subposet_index prims[STANDARD_SUBPOSET_INDEX_CT+1] =
113  {
114  TOC_INDEX,
115  STANDARD_SUBPOSET_INDEX_PLACEHOLDER_MINUS_1,
116  JIMS_INDEX,
117  WHOLE_INDEX,
118  RESIDENT_INDEX,
119  NOT_A_STANDARD_SUBPOSET_INDEX
120  };
121 
122  standard_subposet_index result = prims[STANDARD_SUBPOSET_INDEX_CT];
123  if(is_standard_subposet_index(xindex))
124  {
125  result = prims[xindex - STANDARD_SUBPOSET_INDEX_BEGIN];
126  }
127 
128  // Postconditions:
129 
130  // Exit:
131 
132  return result;
133 }
134 
136 bool
137 sheaf::
139 {
140  bool result;
141 
142  // Preconditions:
143 
144  // Body:
145 
146  result =
147  (STANDARD_SUBPOSET_INDEX_BEGIN <= xindex) &&
148  (xindex < STANDARD_SUBPOSET_INDEX_END);
149 
150  // Postconditions:
151 
152  // Exit
153 
154  return result;
155 }
SHEAF_DLL_SPEC const std::string & standard_subposet_index_to_name(standard_subposet_index xpt)
The name of the enumerator xpt.
STL namespace.
SHEAF_DLL_SPEC bool is_standard_subposet_index(pod_index_type xindex)
True if xindex is a valid primitive index.
SHEAF_DLL_SPEC standard_subposet_index standard_subposet_index_from_name(const std::string &xname)
The enumerator with name xname.
standard_subposet_index
Ids for standard subposets.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
SHEAF_DLL_SPEC namespace_member_index & operator++(namespace_member_index &x)
Prefix increment operator for namespace_member_index.
SHEAF_DLL_SPEC standard_subposet_index standard_subposet_index_from_index(pod_index_type xindex)
The enumerator corresponding to primitive index xindex.