Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 2012

Catalog.cpp

Go to the documentation of this file.
00001 // ============================================================================
00002 #include "Catalog.h"
00003 // ============================================================================
00004 // Boost:
00005 // ============================================================================
00006 #include <boost/foreach.hpp>
00007 #include <boost/format.hpp>
00008 // ============================================================================
00009 // Namesapce aliases:
00010 // ============================================================================
00011 namespace gp = Gaudi::Parsers;
00012 // ============================================================================
00013 std::vector<std::string> gp::Catalog::ClientNames() const {
00014     std::vector<std::string> result;
00015     BOOST_FOREACH(const CatalogSet::value_type& prop, catalog_) {
00016         result.push_back(prop.first);
00017     }
00018     return result;
00019 }
00020 // ============================================================================
00021 bool gp::Catalog::Add(Property* property) {
00022   assert( property != NULL);
00023   CatalogSet::iterator it = catalog_.find(property->ClientName());
00024   if (it == catalog_.end()) {
00025     CatalogSet::mapped_type properties;
00026     properties.insert(property);
00027     catalog_.insert(CatalogSet::value_type(property->ClientName(), properties));
00028     return true;
00029   }
00030   it->second.erase(*property);
00031   it->second.insert(property);
00032   //TODO: check return value
00033   return true;
00034 }
00035 // ============================================================================
00036 gp::Property* gp::Catalog::Find(const std::string& client,
00037     const std::string& name) {
00038   CatalogSet::iterator it = catalog_.find(client);
00039   if (it == catalog_.end()) return NULL;
00040 
00041   CatalogSet::mapped_type::iterator pit = std::find_if(it->second.begin(),
00042       it->second.end(), Property::Equal(name));
00043   if (pit == it->second.end()) return NULL;
00044   return &*pit;
00045 
00046 }
00047 // ============================================================================
00048 std::string gp::Catalog::ToString() const {
00049   std::string result;
00050   BOOST_FOREACH(const CatalogSet::value_type& client, catalog_) {
00051     for (CatalogSet::mapped_type::const_iterator current = client.second.begin();
00052         current != client.second.end(); ++current) {
00053       result += current->ToString()+"\n";
00054     }
00055   }
00056   return result;
00057 }
00058 // ============================================================================
00059 // print the content of the catalogue to std::ostream
00060 // ============================================================================
00061 std::ostream& Gaudi::Parsers::Catalog::fillStream ( std::ostream& o ) const
00062 {
00063   o << "// " << std::string(82,'=') << std::endl
00064     << "//       Parser catalog " << std::endl
00065     << "// " << std::string(82,'=') << std::endl ;
00066 
00067   size_t nComponents = 0 ;
00068   size_t nProperties = 0 ;
00069 
00070   BOOST_FOREACH(const CatalogSet::value_type& client, catalog_)   {
00071     o << boost::format("// Properties of '%1%' %|43t|# = %2%" )
00072         % client.first % client.second.size() << std::endl ;
00073         ++nComponents ;
00074         nProperties += client.second.size() ;
00075    for (CatalogSet::mapped_type::const_iterator current = client.second.begin();
00076        current != client.second.end(); ++current) {
00077      o << boost::format("%1%   %|44t| = %2% ; ")
00078            % current->FullName()
00079            % current->ValueAsString()
00080        << std::endl;
00081    }
00082   }
00083   o << "// " << std::string(82,'=') << std::endl
00084       << boost::format("// End parser catalog #Components=%1% #Properties=%2%")
00085   % nComponents % nProperties     << std::endl
00086   << "// " << std::string(82,'=') << std::endl ;
00087   return o ;
00088 }
00089 // ============================================================================
00090 // printout operator
00091 // ============================================================================
00092 std::ostream& operator<<( std::ostream& o , const Gaudi::Parsers::Catalog& c )
00093 {
00094   return c.fillStream ( o ) ; }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:18 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004