Ignore:
Timestamp:
Nov 22, 2011, 9:22:10 PM (14 years ago)
Author:
Julian Iseringhausen <isering@…>
Children:
facba0
Parents:
66f24d
Message:

Major vmg update.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1136 5161e1c8-67bf-11de-9fd5-51895aff932f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/base/factory.cpp

    r66f24d rdfed1c  
    3333Factory::~Factory()
    3434{
    35   Destroy();
    36 
    37   for (Factory::command_iterator iter=command_map.begin(); iter!=command_map.end(); ++iter)
     35  for (std::map<std::string, Object*>::iterator iter=object_map.begin(); iter!=object_map.end(); ++iter)
    3836    delete iter->second;
    39 
    40   command_map.clear();
    4137}
    4238
    43 void Factory::Destroy()
     39void Factory::Register(Object* object)
    4440{
    45   for (Factory::instance_iterator iter=command_instance_map.begin(); iter!=command_instance_map.end(); ++iter)
    46     delete iter->second;
    47 
    48   for (Factory::object_iterator iter=object_map.begin(); iter!=object_map.end(); ++iter)
    49     delete iter->second;
    50 
    51   command_instance_map.clear();
    52   object_map.clear();
     41  Delete(object->Name());
     42  object_map.insert(std::make_pair(object->Name(), object));
    5343}
    5444
    55 void Factory::RegisterCommand(CommandProxyBase* object)
     45Object* Factory::Get(std::string id)
    5646{
    57   if (command_map.find(object->Name()) == command_map.end())
    58     command_map.insert(std::pair<std::string, CommandProxyBase*>(object->Name(), object));
    59   else
    60     assert(0 == "A command with the same unique name has already been registered.");
    61 }
     47  std::map<std::string, Object*>::iterator iter = object_map.find(id);
    6248
    63 void Factory::RegisterObject(Object* object)
    64 {
    65   Factory::object_iterator iter = object_map.find(object->Name());
     49  if (iter != object_map.end())
     50    return iter->second;
    6651
    67   if (iter != object_map.end()) {
    68     delete iter->second;
    69     object_map.erase(iter);
    70   }
    71 
    72   object_map.insert(std::pair<std::string, Object*>(object->Name(), object));
    73 }
    74 
    75 Command* Factory::GetCommand(std::string id)
    76 {
    77   MG::Instance();
    78 #ifdef DEBUG
    79   //std::cout << id << std::endl;
    80 #endif
    81 
    82   Factory::instance_iterator iter1 = command_instance_map.find(id);
    83   if (iter1 != command_instance_map.end())
    84     return iter1->second;
    85 
    86   Factory::command_iterator iter2 = command_map.find(id);
    87   if (iter2 != command_map.end()) {
    88     Command *command = iter2->second->CreateCommand();
    89     command_instance_map.insert(std::pair<std::string, Command*>(id, command));
    90     return command;
    91   }
    92 
    93   assert(0 == "This command is not registered.");
     52  MG::GetComm()->PrintStringOnce("Error: Object %s is not registered", id.c_str());
     53  assert(0);
    9454
    9555  return NULL;
    9656}
    9757
    98 bool Factory::CheckNumberOfArguments(std::string id, const int& num_arguments)
     58void Factory::Delete(std::string id)
    9959{
    100   Factory::command_iterator iter = command_map.find(id);
    101 
    102   assert(iter != command_map.end());
    103   assert(iter->second->Arguments() == num_arguments);
    104 
    105   return iter->second->Arguments() == num_arguments;
    106 }
    107 
    108 Object* Factory::GetObject(std::string id)
    109 {
    110   MG::Instance();
    111 
    112   Factory::object_iterator iter = object_map.find(id);
    113   if (iter != object_map.end())
    114     return iter->second;
    115 
    116   assert(0 == "This object is not registered.");
    117 
    118   return NULL;
    119 }
    120 
    121 void Factory::DeleteCommand(std::string id)
    122 {
    123   Factory::command_iterator iter1 = command_map.find(id);
    124 
    125   if (iter1 != command_map.end()) {
    126     delete iter1->second;
    127     command_map.erase(iter1);
    128   }
    129 
    130   Factory::instance_iterator iter2 = command_instance_map.find(id);
    131 
    132   if (iter2 != command_instance_map.end()) {
    133     delete iter2->second;
    134     command_instance_map.erase(iter2);
    135   }
    136 }
    137 
    138 void Factory::DeleteObject(std::string id)
    139 {
    140   Factory::object_iterator iter = object_map.find(id);
     60  std::map<std::string, Object*>::iterator iter = object_map.find(id);
    14161
    14262  if (iter != object_map.end()) {
     
    14666}
    14767
    148 void Factory::PrintAvailableCommands()
    149 {
    150   for (Factory::command_iterator iter=command_map.begin(); iter!=command_map.end(); ++iter)
    151     printf("%s\n", iter->second->Name());
    152 }
    153 
    15468void Factory::PrintAvailableObjects()
    15569{
    156   for (Factory::object_iterator iter=object_map.begin(); iter!=object_map.end(); ++iter)
    157     printf("%s\n", iter->second->Name().c_str());
     70  MG::GetComm()->PrintStringOnce("Registered objects:");
     71  for (std::map<std::string, Object*>::iterator iter=object_map.begin(); iter!=object_map.end(); ++iter)
     72    MG::GetComm()->PrintStringOnce("%s", iter->second->Name().c_str());
    15873}
Note: See TracChangeset for help on using the changeset viewer.