SheafSystem  0.0.0.0
arg_list.h
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 // Interface for class arg_list
19 
20 #ifndef ARG_LIST_H
21 #define ARG_LIST_H
22 
23 #ifndef SHEAF_DLL_SPEC_H
24 #include "SheafSystem/sheaf_dll_spec.h"
25 #endif
26 
27 #ifndef BLOCK_H
28 #include "SheafSystem/block.h"
29 #endif
30 
31 #ifndef PRIMITIVE_VALUE_H
32 #include "SheafSystem/primitive_value.h"
33 #endif
34 
35 namespace sheaf
36 {
37 
38 // Forward declarations to enable friend declaration.
39 
40 class arg_list;
41 class namespace_poset;
42 class poset_path;
43 class schema_poset_member;
44 
48 SHEAF_DLL_SPEC std::ostream& operator << (std::ostream &os, const arg_list& p);
49 
53 SHEAF_DLL_SPEC std::istream& operator >> (std::istream &is, arg_list& p);
54 
63 class SHEAF_DLL_SPEC arg_list
64 {
65 
66  friend SHEAF_DLL_SPEC std::ostream& operator << (std::ostream &os, const arg_list& xf);
67  friend SHEAF_DLL_SPEC std::istream& operator >> (std::istream &is, arg_list& xf);
68 
69 public:
70 
71  // The following must be public to support stream insertion operator.
72 
76  struct SHEAF_DLL_SPEC arg_type
77  {
81  std::string name;
82 
87  {
88  return value.id();
89  };
90 
95  {
96  value.id() = xid;
97  };
98 
102  void put_type(int xid);
103 
108 
112  arg_type() {} ;
113 
117  arg_type(const std::string& xname)
118  : name(xname)
119  {} ;
120 
124  arg_type(const char* xname)
125  : name(xname)
126  {};
127 
133  bool operator==(const arg_type& xother) const
134  {
135  return (name == xother.name) && (value == xother.value);
136  };
137 
141  bool empty() const
142  {
143  return name.empty();
144  };
145 
146 
147  };
148 
152  arg_list();
153 
157  arg_list(const arg_list& xinput);
158 
162  arg_list(const arg_type& xarg);
163 
169  arg_list(const char* xarg_name);
170 
174  unsigned int ct() const;
175 
179  bool empty() const;
180 
184  int index(const std::string& xname) const;
185 
189  const std::string& name(int xi) const;
190 
194  int type(int xi) const;
195  // const int& type(int xi) const;
196 
200  int type(const std::string& xname) const;
201  // const int& type(const string& xname) const;
202 
206  primitive_value& value(int xi);
207 
211  const primitive_value& value(int xi) const;
212 
216  primitive_value& value(const std::string& xname);
217 
221  const primitive_value& value(const std::string& xname) const;
222 
223 // ///
224 // /// Insert another arg_list.
225 // ///
226 // arg_list& operator<<(const arg_list& xinput);
227 
231  arg_list& operator+=(const arg_list& xother);
232 
236  arg_list& operator<<(const primitive_value& xinput);
237 
241  bool parsing_name() const;
242 
246  bool parsing_value() const;
247 
251  bool parsing_error() const;
252 
259  bool conforms_to(const namespace_poset& xns,
260  const poset_path& xschema_path,
261  bool xuse_table_schema,
262  bool xauto_access) const;
269  bool conforms_to(const schema_poset_member& xschema,
270  bool xuse_table_schema,
271  bool xauto_access) const;
272 
273 
281  bool conforms_to_extension(const namespace_poset& xns,
282  const poset_path& xschema_path,
283  const poset_path& xstd_schema_path,
284  bool xuse_table_schema,
285  bool xauto_access) const;
286 
294  bool conforms_to_extension(const schema_poset_member& xschema,
295  const schema_poset_member& xstd_schema,
296  bool xuse_table_schema,
297  bool xauto_access) const;
298 
302  void clear();
303 
307  arg_type& arg(int xi);
308 
312  const arg_type& arg(int xi) const;
313 
317  bool contains_arg(const std::string& xname) const;
318 
322  bool contains_args(const arg_list& xother) const;
323 
327  arg_type& arg(const std::string& xname);
328 
332  const arg_type& arg(const std::string& xname) const;
333 
337  arg_type& back();
338 
342  const arg_type& back() const;
343 
344  //*
345  // Put xarg at the back of the list.
346  //*/
347  void push_back(const arg_type& xarg);
348 
349 
350 private:
351 
355  block<arg_type> _args;
356 
360  enum parse_state_type {GET_NAME, GET_VALUE, ERROR};
361 
365  parse_state_type _parse_state;
366 
370  bool arg_conforms_to(const schema_poset_member& xschema) const;
371 
372 
373 };
374 
375 // ===========================================================
376 // NON-MEMBER FUNCTIONS
377 // ===========================================================
378 
382 SHEAF_DLL_SPEC
383 std::ostream& operator << (std::ostream &os, const arg_list::arg_type& p);
384 
388 SHEAF_DLL_SPEC
389 std::istream& operator >> (std::istream &os, arg_list::arg_type& p);
390 
395 size_t
396 SHEAF_DLL_SPEC
397 deep_size(const arg_list::arg_type& xtype, bool xinclude_shallow = true);
398 
399 
400 } // namespace sheaf
401 
402 #endif // ifndef ARG_LIST_H
primitive_value value
The value of the argument.
Definition: arg_list.h:107
bool empty() const
True if and only if name is empty.
Definition: arg_list.h:141
The default name space; a poset which contains other posets as members.
A path defined by a poset name and a member name separated by a forward slash (&#39;/&#39;). For example: "cell_definitions/triangle".
Definition: poset_path.h:48
T & operator+=(T &xresult, const T &xother)
x0 += x1 (self-allocated for volatile types); synonym for add_equal(x0, x1).
Definition: vd.impl.h:210
The internal argument type.
Definition: arg_list.h:76
std::string name
The name of the argument.
Definition: arg_list.h:81
bool operator==(const arg_type &xother) const
True if and only if name and value of this are identical to name and value, respectively, of xother.
Definition: arg_list.h:133
A whitespace separated list of arguments. Insertion operaters are used to insert arguments into the l...
Definition: arg_list.h:63
primitive_type
Type ids for sheaf primitives.
SHEAF_DLL_SPEC size_t deep_size(const dof_descriptor_array &xp, bool xinclude_shallow=true)
The deep size of the referenced object of type dof_descriptor_array.
arg_type(const std::string &xname)
Create an instance with name == xname and default value.
Definition: arg_list.h:117
primitive_type type() const
The type of the argument.
Definition: arg_list.h:86
SHEAF_DLL_SPEC std::istream & operator>>(std::istream &is, dof_tuple_type &xdt)
Extract dof_tuple_type xdt from istream& is.
arg_type(const char *xname)
Create an instance with name == xname and default value.
Definition: arg_list.h:124
arg_type()
Create an instance with empty name.
Definition: arg_list.h:112
SHEAF_DLL_SPEC std::ostream & operator<<(std::ostream &os, const dof_descriptor_array &p)
Insert dof_descriptor_array& p into ostream& os.
Namespace for the sheaves component of the sheaf system.
void put_type(primitive_type xid)
Sets the type of the argument to xid.
Definition: arg_list.h:94
Abstract object wrapper for an instance of a primitive type.
An auto_block with a no-initialization initialization policy.
A client handle for a poset member which has been prepared for use as a schema.