Follow this link to skip to the main content

claraty::FDM_Stream Class Reference

#include <fdm.h>

Inheritance diagram for claraty::FDM_Stream:

Inheritance graph
[legend]
List of all members.

Public Member Functions

virtual ~FDM_Stream ()
bool is_read ()
bool is_write ()
virtual bool eof ()
virtual bool flush ()
void debug (int debugging_level=1)
template<class T>
bool write (const T &x)
template<class T>
bool read (T &x)

Protected Member Functions

 FDM_Stream (FDM::Direction dir)
virtual bool _start_topform (const char *type_name)
virtual bool _end_topform ()
virtual bool _map_field (const char *name)=0
virtual bool _array_element ()=0
virtual void _begin_array ()=0
virtual void _begin_map ()=0
virtual bool _array_resizable_length (int &size)=0
virtual void _end ()=0
bool _io_object (std::vector< bool >::reference bit_ref)
virtual bool _io_object (bool &x)=0
virtual bool _io_object (unsigned char &x)=0
virtual bool _io_object (char &x)=0
virtual bool _io_object (unsigned short &x)=0
virtual bool _io_object (short &x)=0
virtual bool _io_object (unsigned int &x)=0
virtual bool _io_object (int &x)=0
virtual bool _io_object (unsigned long &x)=0
virtual bool _io_object (long &x)=0
virtual bool _io_object (unsigned long long &x)=0
virtual bool _io_object (long long &x)=0
virtual bool _io_object (float &x)=0
virtual bool _io_object (double &x)=0
virtual bool _io_object (std::string &x)=0
virtual bool _peek_object (unsigned int &x)=0
virtual bool _peek_object (std::string &x)=0
FDM_Untyped_Node _map_field_node (const char *name)
FDM_Untyped_Node _array_element_node ()
template<class T>
bool _io_object (T &x)
void _pop_node ()
void _unwind_to_node (FDM_Node &node)
void _ref_node (FDM_Node &node)
void _unref_node (FDM_Node &node)
void _push_node (FDM_Node &node)
int _find_node (FDM_Node &node)

Protected Attributes

std::vector< nodeinfo_str_stack
int _id
bool _write
int _debug

Friends

class FDM_Map
class FDM_Array
class FDM_Untyped_Node
class FDM_Node

Classes

struct  nodeinfo_str

Detailed Description

Definition at line 70 of file fdm.h.


Constructor & Destructor Documentation

virtual claraty::FDM_Stream::~FDM_Stream (  )  [inline, virtual]

Definition at line 76 of file fdm.h.

00076 {}

claraty::FDM_Stream::FDM_Stream ( FDM::Direction  dir  )  [inline, protected]

Definition at line 111 of file fdm.h.

00112     : _id(1), _write(dir == FDM::Write), _debug(0) { }


Member Function Documentation

virtual bool claraty::FDM_Stream::eof (  )  [inline, virtual]

Reimplemented in claraty::File_FDM_Parse_Tree.

Definition at line 82 of file fdm.h.

00082 { return false; }

virtual bool claraty::FDM_Stream::flush (  )  [inline, virtual]

Reimplemented in claraty::File_FDM_Parse_Tree.

Definition at line 86 of file fdm.h.

00086 { return true; }

void claraty::FDM_Stream::debug ( int  debugging_level = 1  )  [inline]

Definition at line 88 of file fdm.h.

References _debug.

00088                                     {
00089     _debug= debugging_level;
00090   }

template<class T>
bool claraty::FDM_Stream::write ( const T &  x  )  [inline]

Definition at line 93 of file fdm.h.

References _end_topform(), _io_object(), _start_topform(), and is_write().

Referenced by claraty::FDM_Parse_Tree::object_to_parse_tree(), claraty::FDM_Parse_Tree::object_to_string(), claraty::File_FDM_Parse_Tree::write_object(), and claraty::FDM_Parse_Tree::write_object().

00093                          {
00094     assert(is_write());
00095     bool ok = _start_topform(typeid(T).name());
00096     ok &= _io_object((T&)x);
00097     ok &= _end_topform();
00098     return(ok);
00099   }

Here is the call graph for this function:

template<class T>
bool claraty::FDM_Stream::read ( T &  x  )  [inline]

Definition at line 102 of file fdm.h.

References _end_topform(), _io_object(), _start_topform(), and is_read().

Referenced by claraty::FDM_Parse_Tree::parse_tree_to_object(), and claraty::File_FDM_Parse_Tree::read_object().

00102                   {
00103     assert(is_read());
00104     bool ok = _start_topform(typeid(T).name());
00105     ok &= _io_object((T&)x);
00106     ok &= _end_topform();
00107     return(ok);
00108   }

Here is the call graph for this function:

virtual bool claraty::FDM_Stream::_start_topform ( const char *  type_name  )  [inline, protected, virtual]

Reimplemented in claraty::File_FDM_Parse_Tree.

Definition at line 120 of file fdm.h.

Referenced by claraty::File_FDM_Parse_Tree::_start_topform(), read(), and write().

00120                                                      {
00121     return true;
00122   }

virtual bool claraty::FDM_Stream::_end_topform (  )  [inline, protected, virtual]

Reimplemented in claraty::File_FDM_Parse_Tree.

Definition at line 123 of file fdm.h.

Referenced by read(), and write().

00123                               {
00124     return true;
00125   }

virtual bool claraty::FDM_Stream::_map_field ( const char *  name  )  [protected, pure virtual]

virtual bool claraty::FDM_Stream::_array_element (  )  [protected, pure virtual]

virtual void claraty::FDM_Stream::_begin_array (  )  [protected, pure virtual]

virtual void claraty::FDM_Stream::_begin_map (  )  [protected, pure virtual]

virtual bool claraty::FDM_Stream::_array_resizable_length ( int &  size  )  [protected, pure virtual]

virtual void claraty::FDM_Stream::_end (  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

Referenced by _pop_node().

bool claraty::FDM_Stream::_io_object ( std::vector< bool >::reference  bit_ref  )  [inline, protected]

Definition at line 146 of file fdm.h.

Referenced by claraty::FDM_Array::element(), claraty::FDM_Map::field(), read(), claraty::FDM_Untyped_Node::value(), and write().

00146                                                     {
00147     bool b = bit_ref;
00148     bool ret = _io_object(b);
00149     bit_ref = b;
00150     return ret;
00151   }

virtual bool claraty::FDM_Stream::_io_object ( bool &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( unsigned char &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( char &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( unsigned short &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( short &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( unsigned int &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( int &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( unsigned long &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( long &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( unsigned long long &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( long long &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( float &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( double &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_io_object ( std::string &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

virtual bool claraty::FDM_Stream::_peek_object ( unsigned int &  x  )  [protected, pure virtual]

virtual bool claraty::FDM_Stream::_peek_object ( std::string &  x  )  [protected, pure virtual]

Implemented in claraty::FDM_Parse_Tree.

FDM_Untyped_Node claraty::FDM_Stream::_map_field_node ( const char *  name  )  [protected]

Definition at line 71 of file fdm.cc.

References _map_field(), and FDM_Untyped_Node.

Referenced by claraty::FDM_Map::field_node().

00072 {
00073   _map_field(name);
00074   return FDM_Untyped_Node(*this);
00075 }

Here is the call graph for this function:

FDM_Untyped_Node claraty::FDM_Stream::_array_element_node (  )  [protected]

Definition at line 77 of file fdm.cc.

References _array_element(), and FDM_Untyped_Node.

Referenced by claraty::FDM_Array::element_node().

00078 {
00079   _array_element();
00080   return FDM_Untyped_Node(*this);
00081 }

Here is the call graph for this function:

template<class T>
bool claraty::FDM_Stream::_io_object ( T &  x  )  [inline, protected]

Definition at line 180 of file fdm.h.

References FDM_Node, and claraty::io_object().

00180 { return io_object(FDM_Node(*this), x); }

Here is the call graph for this function:

void claraty::FDM_Stream::_pop_node (  )  [protected]

Definition at line 84 of file fdm.cc.

References _debug, _end(), and _stack.

Referenced by _unref_node(), and _unwind_to_node().

00085 {
00086   assert(_stack.size());
00087   if (_debug) {
00088     fprintf(stderr, "in pop_node, removing id=%d, level=%d from stack\n",
00089             _stack.back().id, _stack.size()-1);
00090   }
00091   _stack.pop_back();
00092   _end();
00093 }

Here is the call graph for this function:

void claraty::FDM_Stream::_unwind_to_node ( FDM_Node node  )  [protected]

Definition at line 95 of file fdm.cc.

References _debug, _find_node(), _pop_node(), _stack, and claraty::fdm_error().

Referenced by claraty::FDM_Array::element_node(), claraty::FDM_Map::field(), claraty::FDM_Map::field_node(), and claraty::FDM_Map::peekfield().

00096 {
00097   int index= _find_node(node);
00098   if (index == -1) fdm_error("Attempt to add to deleted node");
00099   if (_debug) fprintf(stderr, "in unwind, removing %d items from stack\n",
00100                       _stack.size() - (index+1));
00101   while (_stack.size() > (unsigned)index+1) _pop_node();
00102 }

Here is the call graph for this function:

void claraty::FDM_Stream::_ref_node ( FDM_Node node  )  [protected]

Definition at line 104 of file fdm.cc.

References _debug, _find_node(), claraty::FDM_Node::_id, _stack, and claraty::fdm_error().

Referenced by claraty::FDM_Node::FDM_Node().

00105 {
00106   int index= _find_node(node);
00107   if (index == -1) fdm_error("Attempt to reference deleted node");
00108   _stack[index].refcnt++;
00109   if (_debug) fprintf(stderr, "incrementing ref(%d) to %d\n",
00110                       node._id, _stack[index].refcnt);
00111 }

Here is the call graph for this function:

void claraty::FDM_Stream::_unref_node ( FDM_Node node  )  [protected]

Definition at line 113 of file fdm.cc.

References _debug, _find_node(), claraty::FDM_Node::_id, _pop_node(), and _stack.

Referenced by claraty::FDM_Node::~FDM_Node().

00114 {
00115   int index= _find_node(node);
00116   if (index == -1) return;
00117   _stack[index].refcnt--;
00118   if (_debug) fprintf(stderr, "decrementing ref(%d) to %d\n",
00119                       node._id, _stack[index].refcnt);
00120   assert(_stack[index].refcnt>=0);
00121   if (!_stack[index].refcnt) {
00122     if (_debug) fprintf(stderr, "  removing %d items from stack\n",
00123                         _stack.size()-index);
00124     while (_stack.size() > (unsigned)index) _pop_node();
00125   }
00126 }

Here is the call graph for this function:

void claraty::FDM_Stream::_push_node ( FDM_Node node  )  [protected]

Definition at line 128 of file fdm.cc.

References _debug, claraty::FDM_Node::_id, _id, claraty::FDM_Node::_level, _stack, claraty::FDM_Stream::nodeinfo_str::id, and claraty::FDM_Stream::nodeinfo_str::refcnt.

Referenced by claraty::FDM_Map::_begin_map(), and claraty::FDM_Array::FDM_Array().

00129 {
00130   _id++;
00131   nodeinfo_str ni;
00132   ni.id= node._id= _id++;
00133   ni.refcnt= 1;
00134   node._level= _stack.size();
00135   _stack.push_back(ni);
00136   if (_debug) fprintf(stderr, "pushing node id %d, level %d\n", 
00137                       ni.id, node._level);
00138 }

int claraty::FDM_Stream::_find_node ( FDM_Node node  )  [protected]

Definition at line 140 of file fdm.cc.

References claraty::FDM_Node::_id, claraty::FDM_Node::_level, and _stack.

Referenced by _ref_node(), _unref_node(), and _unwind_to_node().

00141 {
00142   int index= node._level;
00143   if (index >= static_cast<long>(_stack.size()) ||
00144       _stack[index].id != node._id)
00145     return -1;
00146   return index;
00147 }


Friends And Related Function Documentation

friend class FDM_Map [friend]

Definition at line 71 of file fdm.h.

friend class FDM_Array [friend]

Definition at line 72 of file fdm.h.

friend class FDM_Untyped_Node [friend]

Definition at line 73 of file fdm.h.

Referenced by _array_element_node(), and _map_field_node().

friend class FDM_Node [friend]

Definition at line 74 of file fdm.h.

Referenced by _io_object().


Member Data Documentation

std::vector<nodeinfo_str> claraty::FDM_Stream::_stack [protected]

Reimplemented in claraty::FDM_Parse_Tree.

Definition at line 204 of file fdm.h.

Referenced by _find_node(), _pop_node(), _push_node(), _ref_node(), _unref_node(), and _unwind_to_node().

int claraty::FDM_Stream::_id [protected]

Definition at line 207 of file fdm.h.

Referenced by _push_node().

bool claraty::FDM_Stream::_write [protected]

Definition at line 208 of file fdm.h.

Referenced by is_read(), and is_write().


The documentation for this class was generated from the following files: