write_binary.cpp

00001 #include "clssdf.h"
00002 
00003 namespace class_def {
00004 
00005   void class_definition::print_tag( 
00006     std::ostream& os, 
00007     const std::string& tag,
00008     const std::string& nmspc,
00009     const std::string& consttag) const
00010   {
00011     long i;
00012 
00013     if (tag=="map_by_offset") {
00014       os << "void " << _name << "::map_by_offset( " << std::endl;
00015       os << "\tconst " << _name << "& rhs," << std::endl;
00016       os << "\tconst std::vector<long>& offset_map)" << std::endl;
00017       os << "{" << std::endl;
00018     } else if (tag=="send_binary" || tag=="recv_binary") {
00019       os << "int " << _name << "::" << tag << "( int s) "
00020          << consttag << "{" << std::endl;      
00021     } else {
00022       os << "int " << _name << "::" << tag << "( FILE *fl) " 
00023          << consttag << "{" << std::endl;
00024     }
00025 
00026     os << "\tconst char *funcname = \"" << _name << "::" << tag << "\";"
00027        << std::endl;
00028     os << "\tint retval;" << std::endl << std::endl;
00029 
00030     if (tag=="write_binary") {
00031       //os << "\tretval=" << nmspc << tag << "( \"" << _name << "\", fl);" << 
00032       //std::endl;
00033         //os << "\tif (retval) { error( \"write failed at line"
00034         //" \%ld of \%s\\n\", __LINE__, funcname); return retval;}" <<
00035         //  std::endl << std::endl;
00036     } else if (tag=="send_binary") {
00037       //os << "\tretval=" << nmspc << tag << "( s, \"" << _name << "\");" << 
00038       //std::endl;
00039         //os << "\tif (retval) { error( \"send failed at line"
00040         //" \%ld of \%s\\n\", __LINE__, funcname); return retval;}" << 
00041           //std::endl << std::endl;
00042     } else if (tag=="read_binary") {
00043       //os << "\tstd::string classname;" << std::endl;
00044       //os << "\tif (cstio::read_binary( classname, fl)) {" << std::endl;
00045       //os << "\t\terror( \"read failed at line"
00046       //  " \%ld of \%s\\n\", __LINE__, funcname); return -1;" << std::endl;
00047       //os << "\t}" << std::endl << std::endl;
00048     } else if (tag=="recv_binary") {
00049 
00050       //os << "\tstd::string classname;" << std::endl;
00051       //os << "\tif (cstio::recv_binary( s, classname)) {" << std::endl;
00052       //os << "\t\terror( \"recv failed at line"
00053       //" \%ld of \%s\\n\", __LINE__, funcname); return -1;" << std::endl;
00054         //os << "\t}" << std::endl << std::endl;
00055 
00056     }
00057 
00058     if (tag=="map_by_offset") {
00059       for (i=0;i<_row_attributes.size();i++) {
00060         os << "\tcstio::map_by_offset( " << 
00061           _row_attributes[i]->storage_format_of_name() << ", rhs." <<
00062           _row_attributes[i]->storage_format_of_name() << 
00063           ", offset_map);" << std::endl << std::endl;
00064       }
00065     } else if (tag=="read_binary" || tag=="write_binary") {
00066       for (i=0;i<_defined_attributes.size();i++) {
00067         os << "\tretval=" << nmspc << tag << "( "
00068            << _defined_attributes[i]->storage_format_of_name()
00069            << ", fl);" << std::endl;
00070 
00071         os << "\tif (retval) { error( \"" << tag << " failed at line"
00072           " \%ld of \%s\\n\", __LINE__, funcname); return -1;}" << std::endl << std::endl;
00073       }
00074       if (_derived_attributes.size()>0 && tag=="read_binary") {
00075         os << "\tinit_calc_derived_attributes();" << std::endl;
00076       }
00077     } else if (tag=="send_binary" || tag=="recv_binary") {
00078       for (i=0;i<_defined_attributes.size();i++) {
00079         os << "\tretval=" << nmspc << tag << "( s, "
00080            << _defined_attributes[i]->storage_format_of_name()
00081            << ");" << std::endl;
00082 
00083         os << "\tif (retval) { error( \"" << tag << " failed at line"
00084           " \%ld of \%s\\n\", __LINE__, funcname); return -1;}" << std::endl << std::endl;
00085       }
00086       if (_derived_attributes.size()>0 && tag=="recv_binary") {
00087         os << "\tinit_calc_derived_attributes();" << std::endl;
00088       }
00089     }
00090 
00091     if (tag=="map_by_offset") {
00092       os << "}\n" << std::endl;
00093     } else {
00094       os << "\treturn 0;\n}\n" << std::endl;
00095     }
00096   }
00097 
00098 
00099 
00100   void class_definition::print_write_binary( std::ostream& os ) const {
00101     print_tag( os, "write_binary", "cstio::", " const ");
00102   }
00103 
00104   void class_definition::print_send_binary( std::ostream& os ) const {
00105     print_tag( os, "send_binary", "cstio::", " const ");
00106   }
00107 
00108   void class_definition::print_recv_binary( std::ostream& os ) const {
00109     print_tag( os, "recv_binary", "cstio::", " ");
00110   }
00111 }

Generated on Tue Jul 14 12:22:31 2009 for cstpp by  doxygen 1.5.1