Follow this link to skip to the main content

claraty::File_FDM_Parse_Tree Class Reference

#include <file_fdm_parse_tree.h>

Inheritance diagram for claraty::File_FDM_Parse_Tree:

Inheritance graph
[legend]
Collaboration diagram for claraty::File_FDM_Parse_Tree:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 File_FDM_Parse_Tree (FDM::Direction dir)
 File_FDM_Parse_Tree (std::auto_ptr< std::iostream > fio, FDM::Direction dir)
 File_FDM_Parse_Tree (const std::string &filename, FDM::Direction dir, bool append=false)
 ~File_FDM_Parse_Tree ()
virtual bool eof ()
virtual bool open (const std::string &filename, bool append=false)
virtual void close ()
virtual bool flush ()
virtual void summarize (std::ostream &os)
void break_on_error (bool perform_break_on_error=true)
void clear ()
Parse_Tree get_parse_tree ()
void set_parse_tree (const Parse_Tree &parse_tree)
bool is_read ()
bool is_write ()
void debug (int debugging_level=1)
template<class T>
bool write (const T &x)
template<class T>
bool read (T &x)

Static Public Member Functions

static std::string get_filetag ()
template<class T>
static bool write_object (const T &obj, const std::string &filename, bool append=false)
template<class T>
static bool read_object (T &obj, const std::string &filename)
template<class T>
static Parse_Tree object_to_parse_tree (const T &obj)
template<class T>
static bool parse_tree_to_object (T &obj, const Parse_Tree &p_in)
template<class T>
static std::string object_to_string (const T &obj)
template<class T>
static bool string_to_object (T &obj, const std::string &str_in)
template<class T>
static std::ostream & write_object (const T &obj, std::ostream &os)
template<class T>
static bool read_object (T &obj, std::istream &is)

Protected Member Functions

bool _read_header ()
bool _write_header ()
bool _read_block (Parse_Tree &pt)
bool _write_block (Parse_Tree &pt)
bool _process_next_block ()
virtual bool _start_topform (const char *type_name)
virtual bool _end_topform ()
_Stack_Elt & top_of_stack ()
void show_stack ()
template<class T1>
bool type_equal (const T1 &x, const T1 &y)
template<class T1, class T2>
bool type_equal (const T1 &x, const T2 &y)
template<class T1, class T2>
bool type_equal ()
template<class T>
bool io_primitive (T &x)
virtual bool _io_object (bool &x)
virtual bool _io_object (unsigned char &x)
virtual bool _io_object (char &x)
virtual bool _io_object (unsigned short &x)
virtual bool _io_object (short &x)
virtual bool _io_object (unsigned int &x)
virtual bool _io_object (int &x)
virtual bool _io_object (unsigned long &x)
virtual bool _io_object (long &x)
virtual bool _io_object (unsigned long long &x)
virtual bool _io_object (long long &x)
virtual bool _io_object (float &x)
virtual bool _io_object (double &x)
virtual bool _io_object (std::string &x)
bool _io_object (std::vector< bool >::reference bit_ref)
template<class T>
bool _io_object (T &x)
virtual bool _peek_object (unsigned int &x)
virtual bool _peek_object (std::string &x)
virtual void _begin_map ()
virtual void _begin_array ()
virtual bool _array_resizable_length (int &size)
virtual bool _array_element ()
virtual void _end ()
virtual bool _map_field (const char *name)
FDM_Untyped_Node _map_field_node (const char *name)
FDM_Untyped_Node _array_element_node ()
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::iostream * _io_file
bool _file_ok
bool _file_eof
bool _got_block
std::string _topform_typename
std::vector< _Stack_Elt > _stack
bool _break_on_error
int _id
bool _write
int _debug

Detailed Description

Definition at line 38 of file file_fdm_parse_tree.h.


Constructor & Destructor Documentation

claraty::File_FDM_Parse_Tree::File_FDM_Parse_Tree ( FDM::Direction  dir  ) 

Definition at line 32 of file file_fdm_parse_tree.cc.

00032                                                          : 
00033     FDM_Parse_Tree(dir), _io_file(NULL), _file_ok(false), 
00034     _file_eof(false), _got_block(false), _topform_typename("")
00035 {
00036 }

claraty::File_FDM_Parse_Tree::File_FDM_Parse_Tree ( std::auto_ptr< std::iostream >  fio,
FDM::Direction  dir 
)

claraty::File_FDM_Parse_Tree::File_FDM_Parse_Tree ( const std::string &  filename,
FDM::Direction  dir,
bool  append = false 
)

claraty::File_FDM_Parse_Tree::~File_FDM_Parse_Tree (  ) 

Definition at line 56 of file file_fdm_parse_tree.cc.

References close().

00056                                           {
00057   close();
00058 }

Here is the call graph for this function:


Member Function Documentation

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

Reimplemented from claraty::FDM_Stream.

Definition at line 47 of file file_fdm_parse_tree.h.

References _io_file.

00047                      { 
00048     return(_io_file == NULL || _io_file->eof()); 
00049   }

static std::string claraty::File_FDM_Parse_Tree::get_filetag (  )  [inline, static]

Definition at line 52 of file file_fdm_parse_tree.h.

References FDM_PARSE_TREE_FILETAG.

00052 { return(FDM_PARSE_TREE_FILETAG); }

virtual bool claraty::File_FDM_Parse_Tree::open ( const std::string &  filename,
bool  append = false 
) [virtual]

void claraty::File_FDM_Parse_Tree::close (  )  [virtual]

Definition at line 107 of file file_fdm_parse_tree.cc.

References _io_file, flush(), and claraty::FDM_Stream::is_write().

Referenced by ~File_FDM_Parse_Tree().

00108 {
00109   if(_io_file != NULL) {
00110     if(is_write() && _file_ok) {
00111       // Make sure everything's been written
00112       flush();
00113     }
00114     delete _io_file;
00115     _io_file = NULL;
00116   }
00117   _file_ok = false;
00118 }

Here is the call graph for this function:

bool claraty::File_FDM_Parse_Tree::flush (  )  [virtual]

Reimplemented from claraty::FDM_Stream.

Definition at line 180 of file file_fdm_parse_tree.cc.

References _write_block(), claraty::FDM_Parse_Tree::clear(), claraty::FDM_Parse_Tree::get_parse_tree(), and claraty::Parse_Tree::is_null().

Referenced by _end_topform(), close(), and write_object().

00181 {
00182   Parse_Tree pt = get_parse_tree();
00183   // TODO: how do we handle true null trees that we should output?
00184   if(!pt.is_null()) {
00185     bool ok = _write_block(pt);
00186     clear();
00187     return(ok);
00188   }
00189   else {
00190     return(true);
00191   }
00192 }

Here is the call graph for this function:

virtual void claraty::File_FDM_Parse_Tree::summarize ( std::ostream &  os  )  [virtual]

template<class T>
static bool claraty::File_FDM_Parse_Tree::write_object ( const T &  obj,
const std::string &  filename,
bool  append = false 
) [inline, static]

Definition at line 61 of file file_fdm_parse_tree.h.

References flush(), claraty::FDM_Stream::write(), and claraty::FDM::Write.

00063   {
00064     // Create conduit between fdm and the file
00065     File_FDM_Parse_Tree out(filename, FDM::Write, append);
00066     
00067     // Put the object into the output buffer
00068     if(out.write(obj)) {
00069       // Flush the writes to the file
00070       return(out.flush());
00071     }
00072     return(false);
00073   }

Here is the call graph for this function:

template<class T>
static bool claraty::File_FDM_Parse_Tree::read_object ( T &  obj,
const std::string &  filename 
) [inline, static]

Definition at line 76 of file file_fdm_parse_tree.h.

References claraty::FDM_Stream::read(), and claraty::FDM::Read.

00077   {
00078     // Create conduit between fdm and the file
00079     File_FDM_Parse_Tree in(filename, FDM::Read);
00080     
00081     // Put the data from the file into the object
00082     return(in.read(obj));
00083   }

Here is the call graph for this function:

bool claraty::File_FDM_Parse_Tree::_read_header (  )  [protected]

Definition at line 122 of file file_fdm_parse_tree.cc.

References _file_eof, _io_file, and FDM_PARSE_TREE_FILETAG.

00123 {
00124   if(!_file_ok || _file_eof || _io_file == NULL) {
00125     return(false);
00126   }
00127 
00128   bool ok = true;
00129   char tagbuf[5];
00130   if(_io_file->getline(tagbuf, 5)) {
00131     // compare with our filetag
00132     if(string(tagbuf) != string(FDM_PARSE_TREE_FILETAG)) {
00133       // Didn't get the right file tag, seek back to beginning
00134       _io_file->seekg(ios::beg);
00135       return(false);
00136     }
00137     // Matched, return true
00138     return(true);
00139   }
00140   // Get failed, return false
00141   return(false);
00142 }

bool claraty::File_FDM_Parse_Tree::_write_header (  )  [protected]

Definition at line 146 of file file_fdm_parse_tree.cc.

References _file_eof, _io_file, and FDM_PARSE_TREE_FILETAG.

00147 {
00148   if(!_file_ok || _file_eof || _io_file == NULL) {
00149     return(false);
00150   }
00151   *(_io_file) << FDM_PARSE_TREE_FILETAG << endl;
00152 }

bool claraty::File_FDM_Parse_Tree::_read_block ( Parse_Tree pt  )  [protected]

Definition at line 155 of file file_fdm_parse_tree.cc.

References _file_eof, _io_file, and claraty::Parse_Tree::read_from_stream().

Referenced by _process_next_block().

00156 {
00157   if(!_file_ok || _file_eof || _io_file == NULL) {
00158     return(false);
00159   }
00160 
00161   bool ok = pt.read_from_stream(*_io_file);
00162   _file_ok = _io_file->good();
00163   _file_eof = _io_file->eof();
00164   return(ok);
00165 }

Here is the call graph for this function:

bool claraty::File_FDM_Parse_Tree::_write_block ( Parse_Tree pt  )  [protected]

Definition at line 168 of file file_fdm_parse_tree.cc.

References _file_eof, _io_file, and claraty::Parse_Tree::write_to_stream().

Referenced by flush().

00169 {
00170   if(!_file_ok || _file_eof || _io_file == NULL) {
00171     return(false);
00172   }
00173   pt.write_to_stream((*_io_file));
00174   (*_io_file) << endl;
00175   _file_ok = _io_file->good();
00176   return(_file_ok);
00177 }

Here is the call graph for this function:

bool claraty::File_FDM_Parse_Tree::_process_next_block (  )  [protected]

Definition at line 225 of file file_fdm_parse_tree.cc.

References _file_eof, _got_block, _io_file, _read_block(), and claraty::FDM_Parse_Tree::set_parse_tree().

Referenced by _start_topform().

00226 {
00227   if(!_file_ok || _file_eof || _io_file == NULL) {
00228     return(false);
00229   }
00230 
00231   Parse_Tree pt;
00232   if(_read_block(pt)) {
00233     set_parse_tree(pt);
00234     // Mark that we already got the next block
00235     _got_block = true;
00236     return(true);
00237   }
00238   return(false);
00239 }      

Here is the call graph for this function:

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

Reimplemented from claraty::FDM_Stream.

Definition at line 242 of file file_fdm_parse_tree.cc.

References _got_block, _process_next_block(), claraty::FDM_Stream::_start_topform(), and claraty::FDM_Stream::is_read().

00243 {
00244   bool ok = true;
00245   // Read the next block if we haven't already
00246   if(is_read() && !_got_block) {
00247     ok &= _process_next_block();
00248   }
00249 //    // Put or get the type name
00250 //    _topform_typename = type_name;
00251 //    _io_object(_topform_typename);
00252 //    if(is_read()) {
00253 //      if(_topform_typename != type_name) {
00254 //        // If reading, _typeform_typename is now what was stored in the block, 
00255 //        // compare to type_name and warn if different
00256 //        cerr << "WARNING: Stored type differs from that requested " << endl
00257 //         << "   Requested '" << type_name 
00258 //         << "', Read '" << _topform_typename << endl;
00259 //      }
00260 //    }
00261   return(ok & FDM_Stream::_start_topform(type_name));
00262 }

Here is the call graph for this function:

bool claraty::File_FDM_Parse_Tree::_end_topform (  )  [protected, virtual]

Reimplemented from claraty::FDM_Stream.

Definition at line 264 of file file_fdm_parse_tree.cc.

References _got_block, flush(), and claraty::FDM_Stream::is_write().

00265 {
00266   bool ok = true;
00267   // If writing, flush output to file
00268   if(is_write()) {
00269     ok &= flush();
00270   }
00271   else {
00272     // Reading, record that we don't have the next block yet
00273     _got_block=false;
00274   }
00275   return(ok);
00276 }

Here is the call graph for this function:

void claraty::FDM_Parse_Tree::break_on_error ( bool  perform_break_on_error = true  )  [inherited]

Break on Error

Parameters:
[in] perform_break_on_error 
Returns:
void

Definition at line 38 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_break_on_error.

00039 {
00040   _break_on_error= perform_break_on_error;
00041 }

void claraty::FDM_Parse_Tree::clear (  )  [inline, inherited]

Definition at line 55 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::_stack.

Referenced by flush(), and claraty::FDM_Parse_Tree::set_parse_tree().

00055                {
00056     _stack.clear();
00057     _stack.resize(1);
00058   }

Parse_Tree claraty::FDM_Parse_Tree::get_parse_tree (  )  [inline, inherited]

Definition at line 60 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::_stack.

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

00060                               { 
00061     assert(_stack.size() > 0);
00062     return _stack[0].pt; 
00063   }

void claraty::FDM_Parse_Tree::set_parse_tree ( const Parse_Tree parse_tree  )  [inline, inherited]

Definition at line 65 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::_stack, and claraty::FDM_Parse_Tree::clear().

Referenced by _process_next_block(), and claraty::FDM_Parse_Tree::FDM_Parse_Tree().

00065                                                     {
00066     clear();
00067     _stack[0].pt= parse_tree;
00068   }

Here is the call graph for this function:

template<class T>
static Parse_Tree claraty::FDM_Parse_Tree::object_to_parse_tree ( const T &  obj  )  [inline, static, inherited]

Definition at line 71 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::get_parse_tree(), claraty::FDM_Stream::write(), and claraty::FDM::Write.

00071                                                        {
00072     FDM_Parse_Tree stream(FDM::Write);
00073     if(!stream.write(obj)) return Parse_Tree();
00074     return(stream.get_parse_tree());
00075   }

Here is the call graph for this function:

template<class T>
static bool claraty::FDM_Parse_Tree::parse_tree_to_object ( T &  obj,
const Parse_Tree p_in 
) [inline, static, inherited]

Definition at line 78 of file fdm_parse_tree.h.

References claraty::FDM_Stream::read(), and claraty::FDM::Read.

Referenced by claraty::FDM_Parse_Tree::read_object(), and claraty::FDM_Parse_Tree::string_to_object().

00078                                                                    {
00079     FDM_Parse_Tree stream(p_in, FDM::Read);
00080     return(stream.read(obj));
00081   }

Here is the call graph for this function:

template<class T>
static std::string claraty::FDM_Parse_Tree::object_to_string ( const T &  obj  )  [inline, static, inherited]

Definition at line 84 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::get_parse_tree(), claraty::Parse_Tree::pretty_print(), claraty::FDM_Stream::write(), and claraty::FDM::Write.

00084                                                   {
00085     FDM_Parse_Tree stream(FDM::Write);
00086     if(!stream.write(obj)) return "ERROR";
00087     Parse_Tree p_in = stream.get_parse_tree();
00088     return(p_in.pretty_print());
00089   }

Here is the call graph for this function:

template<class T>
static bool claraty::FDM_Parse_Tree::string_to_object ( T &  obj,
const std::string &  str_in 
) [inline, static, inherited]

Definition at line 92 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::parse_tree_to_object(), and claraty::Parse_Tree::read_from_string().

00092                                                                 {
00093     Parse_Tree p_in;
00094     if(!p_in.read_from_string(str_in)) {
00095       // Parse failed, return false
00096       return(false);
00097     }
00098     return(parse_tree_to_object(obj, p_in));
00099   }

Here is the call graph for this function:

template<class T>
static std::ostream& claraty::FDM_Parse_Tree::write_object ( const T &  obj,
std::ostream &  os 
) [inline, static, inherited]

Definition at line 102 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::get_parse_tree(), claraty::FDM_Stream::write(), claraty::FDM::Write, and claraty::Parse_Tree::write_to_stream().

Referenced by claraty::operator<<().

00102                                                                 {
00103     FDM_Parse_Tree stream(FDM::Write);
00104     if(!stream.write(obj)) {
00105       os.clear(std::ios::badbit);
00106     }
00107     Parse_Tree p = stream.get_parse_tree();
00108     return(p.write_to_stream(os));
00109   }

Here is the call graph for this function:

template<class T>
static bool claraty::FDM_Parse_Tree::read_object ( T &  obj,
std::istream &  is 
) [inline, static, inherited]

Definition at line 112 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::parse_tree_to_object(), and claraty::Parse_Tree::read_from_stream().

Referenced by claraty::operator>>().

00112                                                   {
00113     Parse_Tree p;
00114     bool ok=p.read_from_stream(is);
00115     if(ok) {
00116       ok = FDM_Parse_Tree::parse_tree_to_object(obj, p);
00117     }
00118     if(!ok) {
00119       is.clear(std::ios::badbit);
00120     }
00121     return(is);
00122   }

Here is the call graph for this function:

void claraty::FDM_Parse_Tree::show_stack (  )  [protected, inherited]

Definition at line 44 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_stack.

Referenced by claraty::FDM_Parse_Tree::_array_element(), claraty::FDM_Parse_Tree::_array_resizable_length(), claraty::FDM_Parse_Tree::_begin_array(), claraty::FDM_Parse_Tree::_begin_map(), claraty::FDM_Parse_Tree::_end(), claraty::FDM_Parse_Tree::_io_object(), claraty::FDM_Parse_Tree::_map_field(), and claraty::FDM_Parse_Tree::io_primitive().

00045 {
00046   std::cout << "Stack: ";
00047   if (_stack.size() == 0) {
00048     std::cout << "empty\n";
00049     return;
00050   }
00051   for (int i= 0; i< (int)_stack.size(); i++) {
00052     Parse_Tree &pt= _stack[i].pt;
00053     if (pt.is_atom()) {
00054       std::cout << " Atom";
00055     } else if (pt.is_array()) {
00056       std::cout << " Array(" << pt.size() << ")";
00057     } else if (pt.is_map()) {
00058       std::cout << " Map";
00059     } else if (pt.is_null()) {
00060       std::cout << " NULL";
00061     }
00062   }
00063   std::cout << "\n";
00064 }

template<class T1>
bool claraty::FDM_Parse_Tree::type_equal ( const T1 &  x,
const T1 &  y 
) [inline, protected, inherited]

Definition at line 140 of file fdm_parse_tree.h.

00140 { return true; }

template<class T1, class T2>
bool claraty::FDM_Parse_Tree::type_equal ( const T1 &  x,
const T2 &  y 
) [inline, protected, inherited]

Definition at line 143 of file fdm_parse_tree.h.

00143 { return false; }

template<class T1, class T2>
bool claraty::FDM_Parse_Tree::type_equal (  )  [inline, protected, inherited]

Definition at line 146 of file fdm_parse_tree.h.

00146                     {
00147     return type_equal((T1 const *)NULL,
00148                       (T2 const *)NULL);
00149   }

template<class T>
bool claraty::FDM_Parse_Tree::io_primitive ( T &  x  )  [inline, protected, inherited]

Definition at line 152 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::Parse_Tree::get_value(), claraty::FDM_Stream::is_write(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::Parse_Tree::set_value(), claraty::FDM_Parse_Tree::show_stack(), and claraty::FDM_Parse_Tree::top_of_stack().

Referenced by claraty::FDM_Parse_Tree::_io_object().

00152                           {
00153     if (is_write()) {
00154       std::ostringstream str;
00155       if (type_equal<T,float>()) {
00156         // Single precision has 23 bits of mantissa (plus implicit one bit)
00157         // log10(2^24)=7.22
00158         str << std::setprecision(8);
00159       } else if (type_equal<T,double>()) {
00160         // Double precision has 52 bits of mantissa (plus implicit one bit)
00161         // log10(2^53)=15.95
00162         str << std::setprecision(16);
00163       } else if (type_equal<T,long double>()) {
00164         // Long double might have 84 bits of mantissa??
00165         // log10(2^85)=25.59
00166         str << std::setprecision(26);
00167       }
00168       str << x;
00169       std::string s(str.str());
00170       top_of_stack().pt.set_value(s);
00171       if (_debug) {
00172         std::cout << "io_primitive: ";
00173         show_stack();
00174       }
00175       return true;
00176     }
00177     else {
00178       bool ok= true;
00179       std::string s= top_of_stack().pt.get_value(&ok);
00180       if (!ok) {
00181         assert(!_break_on_error);
00182         return false;
00183       }
00184       std::istringstream str(s);
00185       str >> x;
00186       if (_debug) {
00187         std::cout << "io_primitive: ";
00188         show_stack();
00189       }
00190       return true;
00191     }
00192   }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( bool &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 194 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

Referenced by claraty::FDM_Parse_Tree::_peek_object().

00194 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( unsigned char &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 195 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00195 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( char &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 196 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00196 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( unsigned short &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 197 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00197 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( short &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 198 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00198 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( unsigned int &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 199 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00199 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( int &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 200 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00200 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( unsigned long &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 201 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00201 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( long &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 202 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00202 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( unsigned long long &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 203 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00203 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( long long &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 204 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00204 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( float &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 205 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00205 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( double &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 206 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::io_primitive().

00206 { return io_primitive(x); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_io_object ( std::string &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 211 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::Parse_Tree::get_value(), claraty::FDM_Stream::is_write(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::Parse_Tree::set_value(), claraty::FDM_Parse_Tree::show_stack(), and claraty::FDM_Parse_Tree::top_of_stack().

00211                                         {
00212     if (is_write()) {
00213       top_of_stack().pt.set_value(x);
00214       if (_debug) {
00215         std::cout << "io_object(string): ";
00216         show_stack();
00217       }
00218       return true;
00219     } else {
00220       bool ok= true;
00221       // Get the top into a temporary value because if it fails 
00222       // this returns the string 'NULL', and on failure we want to 
00223       // not modify x
00224       std::string val = top_of_stack().pt.get_value(&ok);
00225       if (!ok) {
00226         assert(!_break_on_error);
00227         return false;
00228       }
00229       else {
00230         x=val;
00231       }
00232       if (_debug) {
00233         std::cout << "io_primitive: ";
00234         show_stack();
00235       }
00236       return true;
00237     }
00238   }

Here is the call graph for this function:

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

Definition at line 146 of file fdm.h.

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

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

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

Definition at line 180 of file fdm.h.

References claraty::FDM_Stream::FDM_Node, and claraty::io_object().

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

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_peek_object ( unsigned int &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 240 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::_io_object().

00240 { return(_io_object(x)); }

Here is the call graph for this function:

virtual bool claraty::FDM_Parse_Tree::_peek_object ( std::string &  x  )  [inline, protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 241 of file fdm_parse_tree.h.

References claraty::FDM_Parse_Tree::_io_object().

00241 { return(_io_object(x)); }

Here is the call graph for this function:

void claraty::FDM_Parse_Tree::_begin_map (  )  [protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 67 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::FDM_Parse_Tree::_Stack_Elt::index, claraty::FDM_Stream::is_read(), claraty::Parse_Tree::make_map(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::FDM_Parse_Tree::show_stack(), and claraty::FDM_Parse_Tree::top_of_stack().

00068 {
00069   if (is_read()) {
00070     if (!top_of_stack().pt.is_map()) {
00071       assert(!_break_on_error);
00072     }
00073   } else {
00074     top_of_stack().pt.make_map();
00075     top_of_stack().index= 0;
00076     assert(top_of_stack().pt.size() == 0);
00077     if (_debug) {
00078       std::cout << "_begin_map: ";
00079       show_stack();
00080     }
00081   }
00082 }

Here is the call graph for this function:

void claraty::FDM_Parse_Tree::_begin_array (  )  [protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 85 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::FDM_Parse_Tree::_Stack_Elt::index, claraty::FDM_Stream::is_read(), claraty::Parse_Tree::make_array(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::FDM_Parse_Tree::show_stack(), and claraty::FDM_Parse_Tree::top_of_stack().

00086 {
00087   if (is_read()) {
00088     if (!top_of_stack().pt.is_array()) {
00089       assert(!_break_on_error);
00090     }
00091   } else {
00092     // TODO: record size and check at end of array
00093     top_of_stack().pt.make_array();
00094     top_of_stack().index= 0;
00095     assert(top_of_stack().pt.size() == 0);
00096     if (_debug) {
00097       std::cout << "_begin_array: ";
00098       show_stack();
00099     }
00100   }
00101 }

Here is the call graph for this function:

bool claraty::FDM_Parse_Tree::_array_resizable_length ( int &  size  )  [protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 104 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::FDM_Stream::is_read(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::FDM_Parse_Tree::show_stack(), claraty::Parse_Tree::size(), and claraty::FDM_Parse_Tree::top_of_stack().

00105 {
00106   if (!top_of_stack().pt.is_array()) {
00107     assert(!_break_on_error);
00108     return(false);
00109   }
00110   if (is_read()) {
00111     size= top_of_stack().pt.size();
00112   } else {
00113     // Just assert that this is called before any elements
00114     // We're not actually going to check the number
00115     assert(top_of_stack().pt.size() == 0);
00116     if (_debug) {
00117       std::cout << "_begin_array_resizable: ";
00118       show_stack();
00119     }
00120   }
00121   return(true);
00122 }

Here is the call graph for this function:

bool claraty::FDM_Parse_Tree::_array_element (  )  [protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 125 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::FDM_Parse_Tree::_stack, claraty::Parse_Tree::get_element(), claraty::FDM_Stream::is_write(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::Parse_Tree::set_element(), claraty::FDM_Parse_Tree::show_stack(), and claraty::FDM_Parse_Tree::top_of_stack().

00126 {
00127   while (!top_of_stack().pt.is_array()) _stack.pop_back();
00128   bool ok= true;
00129   if (!top_of_stack().pt.is_array()) {
00130     assert(0);
00131     return false;
00132   }
00133   Parse_Tree elt;
00134   if (is_write()) {
00135     top_of_stack().pt.set_element(top_of_stack().index++, elt);
00136   } else {
00137     elt= top_of_stack().pt.get_element(top_of_stack().index++, &ok);
00138     assert(ok || !_break_on_error);
00139   }
00140   _stack.push_back(elt);
00141   if (_debug) {
00142     std::cout << "_array_element: ";
00143     show_stack();
00144   }
00145   return true;
00146 }

Here is the call graph for this function:

void claraty::FDM_Parse_Tree::_end (  )  [protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 149 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::FDM_Parse_Tree::_stack, claraty::Parse_Tree::is_array(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::FDM_Parse_Tree::show_stack(), and claraty::FDM_Parse_Tree::top_of_stack().

00150 {
00151   while (!top_of_stack().pt.is_map() && !top_of_stack().pt.is_array()) 
00152     _stack.pop_back();
00153   if (_stack.size() > 1) {
00154     _stack.pop_back();
00155     if (_debug) {
00156       std::cout << "_end: ";
00157       show_stack();
00158     }
00159   } else {
00160     if (_debug) {
00161       std::cout << "_end: ";
00162       show_stack();
00163     }
00164     assert(!_break_on_error);
00165   }
00166 }

Here is the call graph for this function:

bool claraty::FDM_Parse_Tree::_map_field ( const char *  name  )  [protected, virtual, inherited]

Implements claraty::FDM_Stream.

Definition at line 169 of file fdm_parse_tree.cc.

References claraty::FDM_Parse_Tree::_break_on_error, claraty::FDM_Stream::_debug, claraty::FDM_Parse_Tree::_stack, claraty::Parse_Tree::get_field(), claraty::FDM_Stream::is_write(), claraty::FDM_Parse_Tree::_Stack_Elt::pt, claraty::Parse_Tree::set_field(), claraty::FDM_Parse_Tree::show_stack(), and claraty::FDM_Parse_Tree::top_of_stack().

00170 {
00171   bool ok= true;
00172   while (!top_of_stack().pt.is_map()) _stack.pop_back();
00173   if (name) {
00174     Parse_Tree field;
00175     if (is_write()) top_of_stack().pt.set_field(name, field);
00176     else {
00177       field= top_of_stack().pt.get_field(name, &ok);
00178       assert(ok || !_break_on_error);
00179     }
00180     _stack.push_back(field);
00181   } else {
00182     _stack.push_back(top_of_stack());
00183   }
00184   if (_debug) {
00185     std::cout << "_map_field: ";
00186     show_stack();
00187   }
00188   return ok;
00189 }

Here is the call graph for this function:

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

Definition at line 88 of file fdm.h.

References claraty::FDM_Stream::_debug.

00088                                     {
00089     _debug= debugging_level;
00090   }

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

Definition at line 93 of file fdm.h.

References claraty::FDM_Stream::_end_topform(), claraty::FDM_Stream::_io_object(), claraty::FDM_Stream::_start_topform(), and claraty::FDM_Stream::is_write().

Referenced by claraty::FDM_Parse_Tree::object_to_parse_tree(), claraty::FDM_Parse_Tree::object_to_string(), 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, inherited]

Definition at line 102 of file fdm.h.

References claraty::FDM_Stream::_end_topform(), claraty::FDM_Stream::_io_object(), claraty::FDM_Stream::_start_topform(), and claraty::FDM_Stream::is_read().

Referenced by claraty::FDM_Parse_Tree::parse_tree_to_object(), and 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:

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

Definition at line 71 of file fdm.cc.

References claraty::FDM_Stream::_map_field(), and claraty::FDM_Stream::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, inherited]

Definition at line 77 of file fdm.cc.

References claraty::FDM_Stream::_array_element(), and claraty::FDM_Stream::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:

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

Definition at line 84 of file fdm.cc.

References claraty::FDM_Stream::_debug, claraty::FDM_Stream::_end(), and claraty::FDM_Stream::_stack.

Referenced by claraty::FDM_Stream::_unref_node(), and claraty::FDM_Stream::_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, inherited]

Definition at line 95 of file fdm.cc.

References claraty::FDM_Stream::_debug, claraty::FDM_Stream::_find_node(), claraty::FDM_Stream::_pop_node(), claraty::FDM_Stream::_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, inherited]

Definition at line 104 of file fdm.cc.

References claraty::FDM_Stream::_debug, claraty::FDM_Stream::_find_node(), claraty::FDM_Node::_id, claraty::FDM_Stream::_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, inherited]

Definition at line 113 of file fdm.cc.

References claraty::FDM_Stream::_debug, claraty::FDM_Stream::_find_node(), claraty::FDM_Node::_id, claraty::FDM_Stream::_pop_node(), and claraty::FDM_Stream::_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, inherited]

Definition at line 128 of file fdm.cc.

References claraty::FDM_Stream::_debug, claraty::FDM_Node::_id, claraty::FDM_Stream::_id, claraty::FDM_Node::_level, claraty::FDM_Stream::_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, inherited]

Definition at line 140 of file fdm.cc.

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

Referenced by claraty::FDM_Stream::_ref_node(), claraty::FDM_Stream::_unref_node(), and claraty::FDM_Stream::_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 }


Member Data Documentation

Definition at line 99 of file file_fdm_parse_tree.h.

Definition at line 102 of file file_fdm_parse_tree.h.

int claraty::FDM_Stream::_id [protected, inherited]

Definition at line 207 of file fdm.h.

Referenced by claraty::FDM_Stream::_push_node().

bool claraty::FDM_Stream::_write [protected, inherited]

Definition at line 208 of file fdm.h.

Referenced by claraty::FDM_Stream::is_read(), and claraty::FDM_Stream::is_write().


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