SheafSystem  0.0.0.0
standard_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 standard_member_index facet of namespace sheaf.
19 
20 
21 #include "SheafSystem/standard_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 STANDARD_MEMBER_INDEX_CT =
31  sheaf::STANDARD_MEMBER_INDEX_END - sheaf::STANDARD_MEMBER_INDEX_BEGIN;
32 }
33 
36 sheaf::
38 {
39  return x =
40  (x == STANDARD_MEMBER_INDEX_END) ?
41  STANDARD_MEMBER_INDEX_BEGIN :
43 };
44 
46 const std::string&
47 sheaf::
49 {
50  // Preconditions:
51 
52  // Body:
53 
54  static const string names[STANDARD_MEMBER_INDEX_CT+1] =
55  {
56  "BOTTOM_INDEX",
57  "TOP_INDEX",
58  "NOT_A_STANDARD_MEMBER_INDEX" // Must be one more than last std id.
59  };
60 
61  const string* lresult_ptr = &names[STANDARD_MEMBER_INDEX_CT];
62 
63  pod_index_type lpt = xpt;
65  {
66  lresult_ptr = &names[lpt - STANDARD_MEMBER_INDEX_BEGIN];
67  }
68 
69  const string& result = *lresult_ptr;
70 
71  // Postconditions:
72 
73  ensure(!result.empty());
74 
75  // Exit:
76 
77  return result;
78 }
79 
82 sheaf::
83 standard_member_index_from_name(const std::string& xname)
84 {
85  standard_member_index result = NOT_A_STANDARD_MEMBER_INDEX;
86  for(standard_member_index i=STANDARD_MEMBER_INDEX_BEGIN;
87  i< STANDARD_MEMBER_INDEX_END;
88  ++i)
89  {
90  if(standard_member_index_to_name(i) == xname)
91  {
92  result = i;
93  break;
94  }
95  }
96 
97  return result;
98 }
99 
102 sheaf::
104 {
105  // Preconditions:
106 
107  // Body:
108 
109  static const standard_member_index prims[STANDARD_MEMBER_INDEX_CT+1] =
110  {
111  BOTTOM_INDEX,
112  TOP_INDEX, // 1
113  NOT_A_STANDARD_MEMBER_INDEX
114  };
115 
116  standard_member_index result = prims[STANDARD_MEMBER_INDEX_CT];
117  if(is_standard_member_index(xindex))
118  {
119  result = prims[xindex];
120  }
121 
122  // Postconditions:
123 
124  // Exit:
125 
126  return result;
127 }
128 
130 bool
131 sheaf::
133 {
134  bool result;
135 
136  // Preconditions:
137 
138  // Body:
139 
140  result =
141  (STANDARD_MEMBER_INDEX_BEGIN <= xindex) && (xindex < STANDARD_MEMBER_INDEX_END);
142 
143  // Postconditions:
144 
145  // Exit
146 
147  return result;
148 }
149 
standard_member_index
Ids for standard poset members.
STL namespace.
SHEAF_DLL_SPEC standard_member_index standard_member_index_from_index(pod_index_type xindex)
The enumerator corresponding to primitive index xindex.
SHEAF_DLL_SPEC standard_member_index standard_member_index_from_name(const std::string &xname)
The enumerator with name xname.
SHEAF_DLL_SPEC bool is_standard_member_index(pod_index_type xindex)
True if xindex is a valid primitive index.
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 const std::string & standard_member_index_to_name(standard_member_index xpt)
The name of the enumerator xpt.