• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/factory.h

00001 // Copyright 2009-2010 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2009-2010, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
00011 
00012 
00013 #ifndef _SST_FACTORY_H
00014 #define _SST_FACTORY_H
00015 
00016 #include <boost/foreach.hpp>
00017 
00018 #include <sst/core/sst_types.h>
00019 #include <sst/core/component.h>
00020 #include <sst/core/introspector.h>
00021 #include <sst/core/element.h>
00022 
00023 namespace SST {
00024 
00025 class SimulationBase;
00026 struct FactoryLoaderData;
00027 
00028 class Factory {
00029 public:
00030     Component* CreateComponent(ComponentId_t id, std::string componentname,
00031                                Component::Params_t& params);
00032     Introspector* CreateIntrospector(std::string introspectorname,
00033                                Component::Params_t& params);
00034     void RegisterEvent(std::string eventname);
00035   
00036 private:
00037     friend class SST::SimulationBase;
00038 
00039     typedef std::map<std::string, const ElementLibraryInfo*> eli_map_t;
00040     typedef std::map<std::string, const ElementInfoComponent*> eic_map_t;
00041     typedef std::map<std::string, const ElementInfoEvent*> eie_map_t;
00042     typedef std::map<std::string, const ElementInfoIntrospector*> eii_map_t;
00043 
00044     Factory(std::string searchPaths);
00045     ~Factory();
00046 
00047     Factory();                      // Don't Implement
00048     Factory(Factory const&);        // Don't Implement
00049     void operator=(Factory const&); // Don't Implement
00050 
00051     // find library information for name
00052     const ElementLibraryInfo* findLibrary(std::string name);
00053     // handle low-level loading of name
00054     const ElementLibraryInfo* loadLibrary(std::string name);
00055 
00056     eli_map_t loaded_libraries;
00057     eic_map_t found_components;
00058     eii_map_t found_introspectors;
00059     eie_map_t found_events;
00060     std::string searchPaths;
00061     FactoryLoaderData *loaderData;
00062 
00063     std::pair<std::string, std::string> parseLoadName(std::string wholename);
00064 
00065     friend class boost::serialization::access;
00066     template<class Archive>
00067     void save(Archive & ar, const unsigned int version) const
00068     {
00069         printf("begin Factory::save\n");
00070         std::vector<std::string> loaded_element_libraries;
00071         loaded_element_libraries.reserve(loaded_libraries.size());
00072         for (eli_map_t::const_iterator i = loaded_libraries.begin() ;
00073              i != loaded_libraries.end() ;
00074              ++i) {
00075             loaded_element_libraries.push_back(i->first);
00076         }
00077         printf("end Factory::save (%d)\n", (int) loaded_element_libraries.size());
00078         ar & BOOST_SERIALIZATION_NVP(loaded_element_libraries);
00079     }
00080 
00081     template<class Archive>
00082     void load(Archive & ar, const unsigned int version)
00083     {
00084         printf("begin Factory::load\n");
00085         std::vector<std::string> loaded_element_libraries;
00086         ar & BOOST_SERIALIZATION_NVP(loaded_element_libraries); 
00087         BOOST_FOREACH(std::string type, loaded_element_libraries) {
00088             if (NULL == findLibrary(type)) {
00089                 fprintf(stderr, 
00090                         "factory::load() failed to load %s\n", 
00091                         type.c_str());
00092                 abort();
00093             }
00094         }
00095         printf("end Factory::load (%d)\n", (int) loaded_element_libraries.size());
00096     }
00097 
00098     template<class Archive>
00099     friend void save_construct_data(Archive & ar, 
00100                                     const Factory * t, 
00101                                     const unsigned int file_version)
00102     {
00103         printf("begin Factory::save_construct_data\n");
00104         std::string search_path = t->searchPaths;
00105         ar << BOOST_SERIALIZATION_NVP(search_path);
00106         printf("end Factory::save_construct_data\n");
00107     }
00108 
00109     template<class Archive>
00110     friend void load_construct_data(Archive & ar, 
00111                                     Factory * t,
00112                                     const unsigned int file_version)
00113     {
00114         printf("begin Factory::load_construct_data\n");
00115         std::string search_path;
00116         ar >> BOOST_SERIALIZATION_NVP(search_path);
00117         ::new(t)Factory(search_path);
00118         printf("end Factory::load_construct_data\n");
00119     }
00120 
00121     BOOST_SERIALIZATION_SPLIT_MEMBER()
00122 };    
00123 
00124 } // namespace SST
00125 
00126 BOOST_CLASS_EXPORT_KEY(SST::Factory)
00127 
00128 #endif

Generated on Fri Oct 22 2010 11:02:13 for SST by  doxygen 1.7.1