Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

Crate.cpp

00001 #include <config/ConfigObject.h>
00002 #include <config/Change.h>
00003 #include "Crate.h"
00004 
00005 // include files for classes used in relationships
00006 
00007 #include "Rod.h"
00008 #include "Tim.h"
00009 
00010 
00011 namespace SCTDAL {
00012   const std::string Crate::s_class_name("Crate");
00013 
00014     // the constructor
00015 
00016   Crate::Crate(::Configuration& db, ::ConfigObject& o) :
00017     DalObject(db, o)  {
00018     m_tim = 0;
00019   }
00020 
00021 
00022   void Crate::print(unsigned int indent, bool print_header, std::ostream& s) const
00023   {
00024     std::string str(indent, ' ');
00025 
00026     if(print_header) {
00027       s
00028         << str << "SCTDAL Crate object:\n"
00029         << str << "  id: \'" << UID() << "\', class name: \'" << class_name() << "\'\n";
00030     }
00031 
00032 
00033       // print direct attributes
00034 
00035     s << str << "  id: " << id() << std::endl;
00036 
00037 
00038       // print direct relationships
00039 
00040     s << str << "  tim:\n";
00041     if(get_tim()) {
00042       get_tim()->print(indent + 4, true, s);
00043     }
00044     else {
00045       s << str << "    (null)" << std::endl;
00046     }
00047     if( m_rods.empty() ) {
00048       s << str << "  rods value is empty\n";
00049     }
00050     else {
00051       s << str << "  " << m_rods.size() << " object(s) in rods:\n";
00052       for(std::vector<const SCTDAL::Rod*>::const_iterator i = m_rods.begin(); i != m_rods.end(); ++i) {
00053         (*i)->print(indent + 4, true, s);
00054       }
00055       }
00056   }
00057 
00058 
00059   std::ostream&
00060   operator<<(std::ostream& s, const Crate * obj)
00061   {
00062     s << '\'';
00063 
00064     if(obj == 0) {
00065       s << "(null)";
00066     }
00067     else {
00068       obj->config_object().print_ptr(s);
00069     }
00070     s << '\'';
00071 
00072     return s;
00073   }
00074 
00075 
00076   std::ostream&
00077   operator<<(std::ostream& s, const Crate & obj)
00078   {
00079     if(&obj == 0) {
00080       s << "(null)";
00081     }
00082     else {
00083       obj.print(0, true, s);
00084     }
00085 
00086     return s;
00087   }
00088 
00089 
00090   void Crate::update(::Configuration& conf, const ::ConfigurationChange * change)
00091   {
00092     conf.update<Crate>(change->get_modified_objs(), change->get_removed_objs());
00093   }
00094 
00095 
00096   void Crate::reset(::Configuration& conf, bool re_initialise_obj)
00097   {
00098     conf.reset_objects<Crate>(re_initialise_obj);
00099   }
00100 
00101 
00102   void Crate::init(bool init_children)
00103   {
00104     p_was_read = true;
00105     increment_read();
00106     static const char * env = ::getenv("TDAQ_REPORT_DAL_OBJECT_READ");
00107     if(env) { std::cout << "DEBUG: read object " << this << std::endl; }
00108 
00109     if(!p_obj.get("id",m_id)) {
00110       std::cerr << "ERROR: could not find attribute 'id'\n";
00111     }
00112     else {
00113       p_db.convert(m_id, p_obj, "id");
00114     }
00115     m_tim = p_db.ref<SCTDAL::Tim>(p_obj, "tim", init_children);
00116     p_db.ref<SCTDAL::Rod>(p_obj, "rods", m_rods, init_children);
00117 
00118     p_obj.clear(); // clear resources used by implementation
00119   }
00120 
00121   Crate::~Crate()
00122   {
00123   }
00124 
00125   bool Crate::set_tim(const SCTDAL::Tim * value) {
00126     clear();
00127     return p_obj.set_obj("tim", (value ? &value->config_object() : (::ConfigObject *)0) );
00128   }
00129 
00130   bool Crate::set_rods(const std::vector<const SCTDAL::Rod*>& a) {
00131     clear();
00132     std::vector<const ConfigObject*> v;
00133     for(std::vector<const SCTDAL::Rod*>::const_iterator i = a.begin(); i != a.end(); ++i) {
00134       v.push_back(&((*i)->config_object()));
00135     }
00136     return p_obj.set_objs("rods", v);
00137   }
00138 
00139 }

Generated on Thu Dec 15 21:14:24 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5