SheafSystem  0.0.0.0
dof_tuple_type.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 class dof_tuple_type
19 
20 #include "SheafSystem/dof_tuple_type.h"
21 
22 #include "SheafSystem/assert_contract.h"
23 #include "SheafSystem/error_message.h"
24 
25 using namespace std;
26 
27 // =============================================================================
28 // DOF TUPLE TYPES FACET
29 // =============================================================================
30 
32 const std::string&
33 sheaf::
35 {
36  // Preconditions:
37 
38  // Body:
39 
40  static const string names[NOT_A_DOF_TUPLE_TYPE+1] =
41  {
42  "NAMESPACE_POSET_DOF_TUPLE_ID",
43  "PRIMITIVES_POSET_DOF_TUPLE_ID",
44  "ARRAY_POSET_DOF_TUPLE_ID",
45  "ARRAY_SECTION_DOF_TUPLE_ID",
46  "SPARSE_SECTOPM_DOF_TUPLE_ID",
47  "NOT_A_DOF_TUPLE_TYPE"
48  };
49 
50  const string& result = names[xdt];
51 
52  // Postconditions:
53 
54  ensure(!result.empty());
55 
56  // Exit:
57 
58  return result;
59 }
60 
63 sheaf::dof_tuple_type_from_name(const std::string& xname)
64 {
65  dof_tuple_type result;
66 
67  // Preconditions:
68 
69 
70  // Body:
71 
77 
78  if(xname == "NAMESPACE_POSET_DOF_TUPLE_ID")
79  {
80  result = NAMESPACE_POSET_DOF_TUPLE_ID;
81  }
82  else if(xname == "PRIMITIVES_POSET_DOF_TUPLE_ID")
83  {
84  result = PRIMITIVES_POSET_DOF_TUPLE_ID;
85  }
86  else if( xname == "ARRAY_POSET_DOF_TUPLE_ID")
87  {
88  result = ARRAY_POSET_DOF_TUPLE_ID;
89  }
90  else if( xname == "ARRAY_SECTION_DOF_TUPLE_ID")
91  {
92  result = ARRAY_SECTION_DOF_TUPLE_ID;
93  }
94  else if( xname == "SPARSE_SECTION_DOF_TUPLE_ID")
95  {
96  result = SPARSE_SECTION_DOF_TUPLE_ID;
97  }
98  else
99  {
100  result = NOT_A_DOF_TUPLE_TYPE;
101  }
102 
103  // Postconditions:
104 
105 
106  // Exit:
107 
108  return result;
109 }
110 
113 sheaf::
115 {
116  dof_tuple_type result;
117 
118  // Preconditions:
119 
120  // Body:
121 
122  static const dof_tuple_type ltype_ids[] =
123  {
124  NAMESPACE_POSET_DOF_TUPLE_ID,
125  PRIMITIVES_POSET_DOF_TUPLE_ID,
126  ARRAY_POSET_DOF_TUPLE_ID,
127  ARRAY_SECTION_DOF_TUPLE_ID,
128  SPARSE_SECTION_DOF_TUPLE_ID,
129  NOT_A_DOF_TUPLE_TYPE // must be last
130  }
131  ;
132 
133  if((0 <= xi) && (xi < NOT_A_DOF_TUPLE_TYPE))
134  {
135  result = ltype_ids[xi];
136  }
137  else
138  {
139  result = NOT_A_DOF_TUPLE_TYPE;
140  }
141 
142  // Postconditions:
143 
144  // Exit
145 
146  return result;
147 }
148 
149 
150 
152 std::ostream&
153 sheaf::
154 operator<<(std::ostream& os, dof_tuple_type xdt)
155 {
156  // Preconditions:
157 
158 
159  // Body:
160 
161  os << dof_tuple_type_to_name(xdt);
162 
163  // Postconditions:
164 
165 
166  // Exit:
167 
168  return os;
169 }
170 
172 std::istream&
173 sheaf::
174 operator>>(std::istream& is, dof_tuple_type& xdt)
175 {
176  // Preconditions:
177 
178 
179  // Body:
180 
181  string ltmp;
182  is >> ltmp;
183  xdt = dof_tuple_type_from_name(ltmp);
184 
185  // Postconditions:
186 
187 
188  // Exit:
189 
190  return is;
191 }
192 
SHEAF_DLL_SPEC dof_tuple_type dof_tuple_type_from_name(const std::string &xname)
The enumerator with name xname.
STL namespace.
SHEAF_DLL_SPEC const std::string & dof_tuple_type_to_name(dof_tuple_type xdt)
The name of the enumerator xdt.
dof_tuple_type
Identifiers for dof tuple types.
SHEAF_DLL_SPEC dof_tuple_type dof_tuple_type_id(int xi)
The dof tuple type associated with int xi; converts int to dof tuple type.
SHEAF_DLL_SPEC std::istream & operator>>(std::istream &is, dof_tuple_type &xdt)
Extract dof_tuple_type xdt from istream& is.
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.