SheafSystem  0.0.0.0
table_dof_tuple_record.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 // Implementation for class table_dof_tuple_record
19 
20 #include "SheafSystem/table_dof_tuple_record.h"
21 
22 #include "SheafSystem/arg_list.h"
23 #include "SheafSystem/array_poset_dof_map.h"
24 #include "SheafSystem/assert_contract.h"
25 #include "SheafSystem/namespace_poset.h"
26 #include "SheafSystem/namespace_poset_member.h"
27 #include "SheafSystem/primitive_type.h"
28 #include "SheafSystem/std_limits.h"
29 #include "SheafSystem/std_sstream.h"
30 
31 using namespace std;
32 
33 //#define DIAGNOSTIC_OUTPUT
34 //#undef DIAGNOSTIC_OUTPUT
35 
36 // =============================================================================
37 // ANY FACET
38 // =============================================================================
39 
40 
44 clone() const
45 {
46  table_dof_tuple_record* result = 0;
47 
48  // Preconditions:
49 
50  // Body:
51 
52  result = new table_dof_tuple_record(*this);
53 
54  // Postconditions:
55 
56  ensure(result != 0);
57  ensure(is_same_type(result));
58 
59  // Exit:
60 
61  return result;
62 }
63 
64 
65 // Class invariant
67 bool
69 invariant() const
70 {
71  bool result = true;
72 
73  // Preconditions:
74 
75  // Body:
76 
77  // Must satisfy base class invariant
78 
79  result = result && attributes_record::invariant();
80 
81  if(invariant_check())
82  {
83  // Prevent recursive calls to invariant
84 
85  disable_invariant_check();
86 
87  // Finished, turn invariant checking back on.
88 
89  enable_invariant_check();
90  }
91 
92  // Postconditions:
93 
94  // Exit
95 
96  return result;
97 }
98 
99 // Conformance test
101 bool
103 is_ancestor_of(const any* other) const
104 {
105 
106  // Preconditions:
107 
108  require(other != 0);
109 
110  // Body:
111 
112  // True if other conforms to this
113 
114  bool result = dynamic_cast<const table_dof_tuple_record*>(other) != 0;
115 
116  // Postconditions:
117 
118  return result;
119 
120 }
121 
122 
123 
124 // =============================================================================
125 // TABLE_DOF_TUPLE_RECORD FACET
126 // =============================================================================
127 
131  : attributes_record(xother)
132 {
133 
134  // Preconditions:
135 
136  // Body:
137 
138  not_implemented();
139 
140  // Postconditions:
141 
142  ensure(invariant());
143 }
144 
145 
149  : attributes_record(xscaffold)
150 {
151  // Preconditions:
152 
153  // Body:
154 
155  // Postconditions:
156 
157  ensure(invariant());
158  ensure(&(scaffold()) == &xscaffold);
159 
160  // Exit
161 
162  return;
163 }
164 
168 {
169 
170  // Preconditions:
171 
172  // Body:
173 
174  // Postconditions:
175 
176  // Exit:
177 
178  return;
179 }
180 
181 
182 // =============================================================================
183 // PROTECTED MEMBER FUNCTIONS
184 // =============================================================================
185 
187 void
190 {
191  // Preconditions:
192 
193  require(!scaffold().structure().is_external() ? scaffold().structure().state_is_read_write_accessible() : true);
194 
195  // Body:
196 
197  // Copy the string buffer to a stream.
198 
199  stringstream lstream(_str_buf);
200 
201  // Ignore the "table_dof_tuple" header line.
202 
203  lstream.ignore(numeric_limits<streamsize>::max(), '\n');
204 
205  // Get the dof tuple in arg list form.
206 
207  arg_list largs;
208  lstream >> largs;
209 
210  // Transfer the arg list to the dof tuple:
211 
212  poset_state_handle& lposet = scaffold().structure();
213 
214  if(lposet.is_external())
215  {
216  // Poset handle of the right type has already been created
217  // in storage_agent::begin_read_transaction(namespace_poset&)
218  // but the poset state has not been created because we need the
219  // table dofs, if there are any.
220 
221  // Create the table dof tuple, need one even if it is empty.
222  // Don't increment its ref_ct because we won't keep a reference here.
223 
224  array_poset_dof_map* ldof_tuple =
225  new array_poset_dof_map(&(scaffold().internal_schema()), true);
226 
227  if(scaffold().internal_schema().table_dof_ct() > 0)
228  {
229  // Table dof tuple is not empty.
230  // Convert any external ids to internal ids.
231  // $$SCRIBBLE: this conversion is probalby no longer needed;
232  // remove if possible, see scribble below.
233 
234  for(int i=0; i<largs.ct(); ++i)
235  {
236  arg_list::arg_type& largi = largs.arg(i);
237  if(largi.type() == NAMESPACE_RELATIVE_MEMBER_INDEX)
238  {
240  }
241  else if(largi.type() == NAMESPACE_RELATIVE_SUBPOSET_INDEX)
242  {
244  }
245  }
246 
247  // Put dofs into dof tuple.
248 
249  ldof_tuple->put_dof_tuple(largs);
250  }
251 
252  // Create the state.
253 
254  lposet.new_state(lposet.name(), scaffold().internal_schema(), *ldof_tuple);
255 
256  // We previously got read access to the schema and other prerequisites in
257  // storage_agent::read_prerequisites in order to build the poset.
258  // Release that level now in order to remain proper.
259 
260  release_prerequisites(lposet);
261 
262  // Get read write access.
263 
264  lposet.get_read_write_access();
265 
266  }
267 
268 
269  // Poset is guaranteed to have a state now.
270 
271  // Postconditions:
272 
273 
274  // Exit:
275 
276  return;
277 }
278 
280 void
283 {
284  // Preconditions:
285 
286 
287  // Body:
288 
289  arg_list largs;
291 
292  // Convert any external ids to internal ids.
293 
294  for(int i=0; i<largs.ct(); ++i)
295  {
296  arg_list::arg_type& largi = largs.arg(i);
297  if(largi.type() == NAMESPACE_RELATIVE_MEMBER_INDEX)
298  {
300  }
301  else if(largi.type() == NAMESPACE_RELATIVE_SUBPOSET_INDEX)
302  {
304  }
305  }
306 
307  stringstream lstream;
308  lstream << "Table_dof_tuple:" << endl << largs;
309 
310  // Have to copy stringstream to string
311  // because can't get C string from stringstream.
312 
313  _str_buf = lstream.str();
314 
315  put_is_internal(true);
316  put_is_external(false);
317 
318  // Postconditions:
319 
320  ensure(is_internal());
321  ensure(!is_external());
322 
323  // Exit:
324 
325  return;
326 }
327 
328 // =============================================================================
329 // PRIVATE MEMBER FUNCTIONS
330 // =============================================================================
331 
332 
333 
335 void
336 sheaf::table_dof_tuple_record::
337 release_prerequisites(poset_state_handle& xposet)
338 {
339 
340  // Preconditions:
341 
342  require(xposet.name_space()->state_is_read_accessible());
343 
344  // Body:
345 
346  namespace_poset* lns = xposet.name_space();
347 
348  // Release the level of access to the posets on which this poset depends,
349  // acquired in storage_agent::read_prequisties
350 
351  // Prerequisite ids are available from xposet or from associated
352  // name space member. Latter doesn't require read access to xposet.
353  // Get a handle to the name space member for xposet.
354 
355  namespace_poset_member lname_space_mbr(xposet);
356 
357  for(int i=0; i<PREREQ_IDS_UB; ++i)
358  {
359  pod_index_type lprereq_id = lname_space_mbr.poset_prereq_id(i);
360 
361  if(is_valid(lprereq_id))
362  {
363  // Release the access.
364 
365  lns->member_poset(lprereq_id).release_access();
366  }
367  }
368 
369  // Clean up
370 
371  lname_space_mbr.detach_from_state();
372 
373  // Postconditions:
374 
375  ensure(unexecutable(all prerequisites have been release));
376 
377  // Exit
378 
379  return;
380 }
381 
382 
383 
virtual void get_read_write_access(bool xrelease_read_only_access=false)
Get read write access to the state associated with this. If release_read_only_access is requested...
primitive_value value
The value of the argument.
Definition: arg_list.h:107
virtual void transfer_internal_buffer_to_poset()
Initializes scaffold from the internal buffer.
arg_type & arg(int xi)
The xi-th arg.
Definition: arg_list.cc:989
poset_scaffold & scaffold()
The scaffold for the poset associated with this record (mutable version).
Definition: record.h:112
A wrapper/adapter for the table dof tuple record. Intended for transferring data between the kernel a...
void convert_record_id_to_subposet_id(void *xbuf)
Converts namespace relative record id at location xbuf to namespace relative subposet id at location ...
The default name space; a poset which contains other posets as members.
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
virtual table_dof_tuple_record * clone() const
Virtual constructor; makes a new instance of the same type as this.
A client handle for a general, abstract partially order set.
STL namespace.
The internal argument type.
Definition: arg_list.h:76
A client handle for a member of a namespace poset.
Abstract base class with useful features for all objects.
Definition: any.h:39
A whitespace separated list of arguments. Insertion operaters are used to insert arguments into the l...
Definition: arg_list.h:63
pod_index_type poset_prereq_id(int xi) const
The id of the xi-th prerequisite poset for the poset associated with this namespace member...
std::string _str_buf
The internal/external buffer.
bool is_external() const
True if this has a corresponding member in a name space, but is not yet attached to a state...
virtual bool invariant() const
Class invariant.
bool is_internal() const
True if the internal buffer has been initialized.
void convert_record_id_to_member_id(void *buf)
Converts namespace relative record id at location xbuf to namespace relative member id at location xb...
unsigned int ct() const
The number of arguments.
Definition: arg_list.cc:139
virtual void transfer_poset_to_internal_buffer()
Initializes the internal buffer from the scaffold.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
void put_is_internal(bool xis_internal)
Sets is_internal to xis_internal.
virtual std::string name() const
The name of this poset.
SHEAF_DLL_SPEC void max(const vd &x0, vd_value_type &xresult, bool xauto_access)
Maximum component of x0, pre-allocated version.
Definition: vd.cc:2097
primitive_type type() const
The type of the argument.
Definition: arg_list.h:86
poset_state_handle & structure()
The handle for the poset being transferred. (Name chosen to void name conflict with class poset...
virtual void detach_from_state()
Detach this handle from its state, if any.
namespace_poset * name_space() const
The namespace this poset resides in.
virtual void put_dof_tuple(const void *xbuf, size_t xbuflen)
Copies the entire dof tuple from xbuf into internal storage.
schema_poset_member & internal_schema()
The schema of the poset in internal namespace (mutable version).
int_type pod_index_type
The plain old data index type.
Definition: pod_types.h:49
virtual void get_dof_tuple(void *xbuf, size_t xbuflen) const
Copies the entire dof tuple from internal storage into xbuf.
A poset specific collection of data converters, various buffers and other data used while transferrin...
bool is_external() const
True if the external buffer has been initialized.
table_dof_tuple_record(const table_dof_tuple_record &xother)
Copy constructor.
An abstract wrapper/adapter for attributes records. Intended for transferring data between the kernel...
void convert_subposet_id_to_record_id(void *xbuf)
Converts namespace relative subposet id at location xbuf to namespace relative record id at location ...
An array representation of abstract class poset_dof_map.
void new_state(namespace_poset &xns, const poset_path &xpath, const schema_poset_member &xschema, array_poset_dof_map &xdof_map)
Creates a new poset state with schema xschema and table dof map xdof_map, attaches this to the state ...
SHEAF_DLL_SPEC bool is_valid(pod_index_type xpod_index)
True if an only if xpod_index is valid.
Definition: pod_types.cc:37
virtual ~table_dof_tuple_record()
Destructor.
const int PREREQ_IDS_UB
Number of prerequisites ids. Must be consistent with PREREQ_ID_*_INDEX below.
virtual array_poset_dof_map & table_dof_map(bool xrequire_write_access=false)
The map from table dof client_ids to table dof values for this poset (mutable version) ...
void put_is_external(bool xis_external)
Sets is_external to xis_external.
void convert_member_id_to_record_id(void *buf)
Converts namespace relative member id at location xbuf to namespace relative record id at location xb...