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.hpp

    r66f24d rdfed1c  
    33 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
    44 * @date   Tue Apr  5 20:40:41 2011
    5  * 
     5 *
    66 * @brief  Factory class that holds commands and arbitrary objects.
    7  * 
    8  * 
     7 *
     8 *
    99 */
    1010
    11 #ifndef COMMAND_FACTORY_HPP_
    12 #define COMMAND_FACTORY_HPP_
     11#ifndef FACTORY_HPP_
     12#define FACTORY_HPP_
    1313
    14 #include <iostream>
    1514#include <map>
    1615#include <string>
    1716
    1817#include "base/object.hpp"
    19 #include "base/proxy.hpp"
    2018
    2119namespace VMG
    2220{
    2321
    24 class Object;
    25 
    2622class Factory
    2723{
    2824public:
    29   typedef std::map<std::string, CommandProxyBase*>::iterator command_iterator;
    30   typedef std::map<std::string, Command*>::iterator instance_iterator;
    31   typedef std::map<std::string, Object*>::iterator object_iterator;
    32 
    3325  Factory();
    3426  virtual ~Factory();
    3527
    36   void Destroy();
     28  void Register(Object* object); ///< Registers an object
     29  template <class T> T& RegisterObjectStorage(std::string id, const T& val);
     30  template <class T> T* RegisterObjectStorageArray(std::string id, const vmg_int& size);
    3731
    38   void RegisterCommand(CommandProxyBase* command); ///< Register a command
    39   void RegisterObject(Object* object);             ///< Register an object
     32  Object* Get(std::string id);   ///< Returns an object.
     33  template <class T> T& GetObjectStorageVal(std::string id);
     34  template <class T> T* GetObjectStorageArray(std::string id);
    4035
    41   /**
    42    * Register an arbitrary object that is not derived from Object.
    43    * Similar functionality can be achieved by calling
    44    * "new ObjectStorage<T>(id, data);"
    45    */
    46   template <class T> void RegisterObjectStorage(std::string id, const T& data);
    47   template <class T> T& GetObjectStorageVal(std::string id);
     36  void Delete(std::string id);   ///< Deletes an object
    4837
    49   void DeleteCommand(std::string id);  ///< Delete a command
    50   void DeleteObject(std::string id);   ///< Delete an object
    51 
    52   Command* GetCommand(std::string id); ///< Returns a command.
    53   Object* GetObject(std::string id);   ///< Returns an object.
    54 
    55   /**
    56    * Checks for the correct number of arguments. This check is
    57    * automatically performed, whenever a command is executed from
    58    * a command list (if the library has not been compiled with NDEBUG).
    59    */
    60   bool CheckNumberOfArguments(std::string id, const int& num_arguments);
    61 
    62   void PrintAvailableCommands(); ///< Prints the name of all commands that have been registered to the factory.
    6338  void PrintAvailableObjects();  ///< Prints the name of all objects that have been registered to the factory.
    6439
    6540private:
    66   std::map<std::string, CommandProxyBase*> command_map;
    67   std::map<std::string, Command*> command_instance_map;
    6841  std::map<std::string, Object*> object_map;
    6942};
    7043
    7144template <class T>
    72 void Factory::RegisterObjectStorage(std::string id, const T& data)
     45T& Factory::RegisterObjectStorage(std::string id, const T& val)
    7346{
    74   new ObjectStorage<T>(id, data);
     47  Object* object = new ObjectStorage<T>(id, val);
     48  return object->Cast< ObjectStorage<T> >()->Val();
     49}
     50
     51template <class T>
     52T* Factory::RegisterObjectStorageArray(std::string id, const vmg_int& size)
     53{
     54  Object* object = new ObjectStorageArray<T>(id, size);
     55  return object->Cast< ObjectStorage<T*> >()->Val();
    7556}
    7657
     
    7859T& Factory::GetObjectStorageVal(std::string id)
    7960{
    80   return GetObject(id)->Cast< ObjectStorage<T> >()->Val();
     61  return Get(id)->Cast< ObjectStorage<T> >()->Val();
     62}
     63
     64template <class T>
     65T* Factory::GetObjectStorageArray(std::string id)
     66{
     67  return Get(id)->Cast< ObjectStorage<T*> >()->Val();
    8168}
    8269
    8370}
    8471
    85 #endif /* COMMAND_FACTORY_HPP_ */
     72#endif /* FACTORY_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.