SheafSystem  0.0.0.0
namespace_member_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 namespace_member_index facet of namespace sheaf.
19 
20 
21 #include "SheafSystem/namespace_member_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 NAMESPACE_MEMBER_INDEX_CT =
31  sheaf::NAMESPACE_MEMBER_INDEX_END - sheaf::NAMESPACE_MEMBER_INDEX_BEGIN;
32 }
33 
36 sheaf::
38 {
39  return x =
40  (x == NAMESPACE_MEMBER_INDEX_END) ?
41  NAMESPACE_MEMBER_INDEX_BEGIN :
43 };
44 
46 const std::string&
47 sheaf::
49 {
50  // Preconditions:
51 
52  // Body:
53 
54  static const string names[NAMESPACE_MEMBER_INDEX_CT+1] =
55  {
56  "PRIMITIVES_SCHEMA_INDEX",
57  "NAMESPACE_SCHEMA_INDEX",
58  "PRIMITIVES_INDEX",
59  "SCHEMA_DEFINITIONS_INDEX",
60  "NOT_A_NAMESPACE_MEMBER_INDEX" // Must be one more than last std id.
61  };
62 
63  const string* lresult_ptr = &names[NAMESPACE_MEMBER_INDEX_CT];
64 
65  pod_index_type lpt = xpt;
67  {
68  lresult_ptr = &names[lpt - NAMESPACE_MEMBER_INDEX_BEGIN];
69  }
70 
71  const string& result = *lresult_ptr;
72 
73  // Postconditions:
74 
75  ensure(!result.empty());
76 
77  // Exit:
78 
79  return result;
80 }
81 
84 sheaf::
85 namespace_member_index_from_name(const std::string& xname)
86 {
87  namespace_member_index result = NOT_A_NAMESPACE_MEMBER_INDEX;
88  for(namespace_member_index i=NAMESPACE_MEMBER_INDEX_BEGIN;
89  i< NAMESPACE_MEMBER_INDEX_END;
90  ++i)
91  {
92  if(namespace_member_index_to_name(i) == xname)
93  {
94  result = i;
95  break;
96  }
97  }
98 
99  return result;
100 }
101 
104 sheaf::
106 {
107  // Preconditions:
108 
109  // Body:
110 
111  static const namespace_member_index prims[NAMESPACE_MEMBER_INDEX_CT+1] =
112  {
113  PRIMITIVES_SCHEMA_INDEX, // 2
114  NAMESPACE_SCHEMA_INDEX, // 3
115  PRIMITIVES_INDEX, // 4
116  SCHEMA_DEFINITIONS_INDEX,//5
117  NOT_A_NAMESPACE_MEMBER_INDEX
118  };
119 
120  namespace_member_index result = prims[NAMESPACE_MEMBER_INDEX_CT];
121  if(is_namespace_member_index(xindex))
122  {
123  result = prims[xindex - NAMESPACE_MEMBER_INDEX_BEGIN];
124  }
125 
126  // Postconditions:
127 
128  // Exit:
129 
130  return result;
131 }
132 
134 bool
135 sheaf::
137 {
138  bool result;
139 
140  // Preconditions:
141 
142  // Body:
143 
144  result =
145  (NAMESPACE_MEMBER_INDEX_BEGIN <= xindex) && (xindex < NAMESPACE_MEMBER_INDEX_END);
146 
147  // Postconditions:
148 
149  // Exit
150 
151  return result;
152 }
153 
STL namespace.
SHEAF_DLL_SPEC bool is_namespace_member_index(pod_index_type xindex)
True if xindex is a valid primitive index.
SHEAF_DLL_SPEC namespace_member_index namespace_member_index_from_index(pod_index_type xindex)
The enumerator corresponding to primitive index xindex.
namespace_member_index
Ids for standard poset members.
SHEAF_DLL_SPEC namespace_member_index namespace_member_index_from_name(const std::string &xname)
The enumerator with name xname.
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
SHEAF_DLL_SPEC const std::string & namespace_member_index_to_name(namespace_member_index xpt)
The name of the enumerator xpt.
SHEAF_DLL_SPEC namespace_member_index & operator++(namespace_member_index &x)
Prefix increment operator for namespace_member_index.