Ignore:
Timestamp:
Jan 10, 2011, 8:06:49 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
192c04
Parents:
9f39db
git-author:
Frederik Heber <heber@…> (01/06/11 23:48:30)
git-committer:
Frederik Heber <heber@…> (01/10/11 20:06:49)
Message:

New patterns ManipulableClone and ManipulablePrototypeFactory, changed PrototypeFactory.

  • ManipulableClone is a Clone that can spawn a manipulated copy varied by given parameters.
  • prototypes in PrototypeFactory cannot be manipulated anymore.
  • PrototypeFactory::getPrototypeManipulator() -> getPrototype() and returned reference is const (and a ref, no pointer. Preventing its accidental deletion).
  • ManipulablePrototypeFactory then has non-const references returned by getProduct().
  • ManipulablePrototypeFactory::manipulatePrototype() allows direct manipulation of the prototype by a given parameter set.
  • Added unit tests for the new patterns.
  • Changed unit tests for PrototypeFactory.
  • Library version is now 4:0:0, API version is 1.0.7.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Patterns/PrototypeFactory.hpp

    r9f39db r8dd38e  
    374374  *
    375375  * @param instance_name name of product
    376   * @return reference to prototype stored in this factory
     376  * @return const reference to prototype stored in this factory, i.e. read-only
    377377  */
    378   T* getPrototypeManipulator(const std::string instance_name)
     378  const T& getPrototype(const std::string instance_name)
    379379  {
    380380    ASSERT(enums.count(instance_name) != 0,
    381381        "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type name "+instance_name+" is not registered.");
    382382    T* prototype = dynamic_cast<T *>(PrototypeTable[ enums[instance_name] ]);
    383     return prototype;
     383    return *prototype;
    384384  }
    385385
     
    391391  *
    392392  * @param enumeration index of product
    393   * @return reference to prototype stored in this factory
     393  * @return const reference to prototype stored in this factory, i.e. read-only
    394394  */
    395   T* getPrototypeManipulator(TypeList instance_type)
     395  const T& getPrototype(TypeList instance_type)
    396396  {
    397397    ASSERT(names.count(instance_type) != 0,
    398398        "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - enum type "+toString(instance_type)+" is not registered.");
    399399    T* prototype = dynamic_cast<T *>(PrototypeTable[instance_type]);
    400     return prototype;
     400    return *prototype;
    401401  }
    402402
     
    408408  *
    409409  * @param instance_type_info object of the desired type
    410   * @return reference to prototype stored in this factory
     410  * @return const reference to prototype stored in this factory, i.e. read-only
    411411  */
    412   T* getPrototypeManipulator(const std::type_info &instance_type_info)
     412  const T& getPrototype(const std::type_info &instance_type_info)
    413413  {
    414414    ASSERT(types.count(instance_type_info.name()) != 0,
    415415        "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type info name "+instance_type_info.name()+" is not registered.");
    416416    T* prototype = dynamic_cast<T *>(PrototypeTable[ types[instance_type_info.name()] ]);
    417     return prototype;
     417    return *prototype;
    418418  }
    419419
     
    424424  * specific friends are allowed to access it.
    425425  *
    426   * @return reference to prototype stored in this factory
     426  * @return const reference to prototype stored in this factory, i.e. read-only
    427427  */
    428   T* getPrototypeManipulator()
     428  const T& getPrototype()
    429429  {
    430430    T* prototype = dynamic_cast<T *>(PrototypeTable[ currenttype ]);
    431     return prototype;
    432   }
    433 
    434   /** Allows returning (a possibly different) prototype which is stored in
    435    *  PrototypeTable.
    436    *
    437    * @warning a prototype has to be delivered by getPrototypeManipulator()
    438    * before it can be returned again.
    439    *
    440    * @param _newprototype reference to new prototype
    441    * @param instance_name name of particular type
    442    */
    443   void installPrototype(Clone<T> *_newprototype, const std::string instance_name)
    444   {
    445     ASSERT(enums.count(instance_name) != 0,
    446         "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type name "+instance_name+" is not registered.");
    447     ASSERT(typeid(PrototypeTable[ enums[instance_name] ]) == typeid(_newprototype),
    448         "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+instance_name+".");
    449     // TODO: use boost::shared_ptr to store prototypes instead!
    450     delete PrototypeTable[ enums[instance_name] ];
    451     PrototypeTable[ enums[instance_name] ] = _newprototype;
    452   }
    453 
    454   /** Allows returning (a possibly different) prototype which is stored in
    455    *  PrototypeTable.
    456    *
    457    * @warning a prototype has to be delivered by getPrototypeManipulator()
    458    * before it can be returned again.
    459    *
    460    * @param _newprototype reference to new prototype
    461    * @param instance_type enumeration index of particular type
    462    */
    463   void installPrototype(Clone<T> *_newprototype, TypeList instance_type)
    464   {
    465     ASSERT(names.count(instance_type) != 0,
    466         "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - enum type "+toString(instance_type)+" is not registered.");
    467     ASSERT( typeid(PrototypeTable[ instance_type ]) == typeid(_newprototype),
    468         "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+names[instance_type]+".");
    469     // TODO: use boost::shared_ptr to store prototypes instead!
    470     delete PrototypeTable[ instance_type ];
    471     PrototypeTable[ instance_type ] = _newprototype;
    472   }
    473 
    474   /** Allows returning (a possibly different) prototype which is stored in
    475    *  PrototypeTable.
    476    *
    477    * @warning a prototype has to be delivered by getPrototypeManipulator()
    478    * before it can be returned again.
    479    *
    480    * @param _newprototype reference to new prototype
    481    * @param instance_type_info type_info of particular type
    482    */
    483   void installPrototype(Clone<T> *_newprototype, const std::type_info &instance_type_info)
    484   {
    485     ASSERT(types.count(instance_type_info.name()) != 0,
    486         "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type info name "+instance_type_info.name()+" is not registered.");
    487     ASSERT( typeid(PrototypeTable[ types[instance_type_info.name()] ]) == typeid(_newprototype),
    488         "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+instance_type_info.name()+".");
    489     // TODO: use boost::shared_ptr to store prototypes instead!
    490     PrototypeTable[ types[instance_type_info.name()] ] = _newprototype;
    491   }
    492 
    493   /** Allows returning (a possibly different) prototype which is stored in
    494    *  PrototypeTable.
    495    *
    496    * @warning a prototype has to be delivered by getPrototypeManipulator()
    497    * before it can be returned again.
    498    *
    499    * @param _newprototype reference to new prototype
    500    * @param instance_type_info type_info of particular type
    501    */
    502   void installPrototype(Clone<T> *_newprototype)
    503   {
    504     ASSERT( typeid(PrototypeTable[ currenttype ]) == typeid(_newprototype),
    505         "PrototypeFactory<"+toString(typeid(T).name())+">::installPrototype() - new prototype is not of the necessary type "+names[currenttype]+".");
    506     // TODO: use boost::shared_ptr to store prototypes instead!
    507     PrototypeTable[ currenttype ] = _newprototype;
     431    return *prototype;
    508432  }
    509433
Note: See TracChangeset for help on using the changeset viewer.