Changeset 567640


Ignore:
Timestamp:
Jan 6, 2011, 12:22:12 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Children:
9f39db
Parents:
d76c105
Message:

PrototypeFactory now allows for replacing prototypes.

  • if a prototype can only be manipulated via its constructor, it is essential for the factory to allow for changing prototypes in a controlled manner. All the functions on prototypes are protected, hence only friends may get access.
  • Library version is now 3:1:1, API version is 1.0.6.
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • configure.ac

    rd76c105 r567640  
    33
    44AC_PREREQ([2.65])
    5 AC_INIT([CodePatterns], [1.0.5], [heber@ins.uni-bonn.de], [codepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/])
     5AC_INIT([CodePatterns], [1.0.6], [heber@ins.uni-bonn.de], [codepatterns], [http://trac.ins.uni-bonn.de/projects/CodePatterns/])
    66AC_CONFIG_AUX_DIR(config)
    77AC_CONFIG_SRCDIR([src/Patterns/Singleton_impl.hpp])
     
    2525# refer to the libtool manual, section "Updating library version information":
    2626# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
    27 AC_SUBST([CODEPATTERNS_SO_VERSION], [3:0:0])
    28 AC_SUBST([CODEPATTERNS_API_VERSION], [1.0.5])
     27AC_SUBST([CODEPATTERNS_SO_VERSION], [3:1:1])
     28AC_SUBST([CODEPATTERNS_API_VERSION], [1.0.6])
    2929
    3030# Checks for libraries.
  • src/Patterns/PrototypeFactory.hpp

    rd76c105 r567640  
    364364
    365365protected:
    366   /** Getter for the true prototype of the product.
     366  /** Yields true prototype of the product and sets entry to NULL on
     367   *  PrototypeTable.
    367368  *
    368369  * @warning This method is \b intentionally protected such that only
     
    378379  {
    379380    ASSERT(enums.count(instance_name) != 0,
    380         "PrototypeFactory<"+toString(typeid(T).name())+">::getProduct() - type name "+instance_name+" is not registered.");
    381     return dynamic_cast<T *>(PrototypeTable[ enums[instance_name] ]);
    382   }
    383 
    384   /** Getter for the true prototype of the product.
     381        "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type name "+instance_name+" is not registered.");
     382    T* prototype = dynamic_cast<T *>(PrototypeTable[ enums[instance_name] ]);
     383    return prototype;
     384  }
     385
     386  /** Yields true prototype of the product and sets entry to NULL on
     387   *  PrototypeTable.
    385388  *
    386389  * @warning This method is \b intentionally protected such that only
     
    393396  {
    394397    ASSERT(names.count(instance_type) != 0,
    395         "PrototypeFactory<"+toString(typeid(T).name())+">::getProduct() - enum type "+toString(instance_type)+" is not registered.");
    396     return dynamic_cast<T *>(PrototypeTable[instance_type]);
    397   }
    398 
    399   /** Getter for the true prototype of the product.
     398        "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - enum type "+toString(instance_type)+" is not registered.");
     399    T* prototype = dynamic_cast<T *>(PrototypeTable[instance_type]);
     400    return prototype;
     401  }
     402
     403  /** Yields true prototype of the product and sets entry to NULL on
     404   *  PrototypeTable.
    400405  *
    401406  * @warning This method is \b intentionally protected such that only
     
    408413  {
    409414    ASSERT(types.count(instance_type_info.name()) != 0,
    410         "PrototypeFactory<"+toString(typeid(T).name())+">::getProduct() - type info name "+instance_type_info.name()+" is not registered.");
    411     return dynamic_cast<T *>(PrototypeTable[ types[instance_type_info.name()] ]);
     415        "PrototypeFactory<"+toString(typeid(T).name())+">::getPrototypeManipulator() - type info name "+instance_type_info.name()+" is not registered.");
     416    T* prototype = dynamic_cast<T *>(PrototypeTable[ types[instance_type_info.name()] ]);
     417    return prototype;
     418  }
     419
     420  /** Yields true prototype of the currenttype product and sets entry to NULL
     421   *  on PrototypeTable.
     422  *
     423  * @warning This method is \b intentionally protected such that only
     424  * specific friends are allowed to access it.
     425  *
     426  * @return reference to prototype stored in this factory
     427  */
     428  T* getPrototypeManipulator()
     429  {
     430    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;
    412508  }
    413509
  • src/Patterns/unittests/PrototypeFactoryUnitTest.cpp

    rd76c105 r567640  
    183183  CPPUNIT_ASSERT( rndA->getcount() == rndA_3->getcount() );
    184184}
     185
     186void PrototypeFactoryTest::installPrototypetest()
     187{
     188  Prototype< teststubs::Aclass> *newprototype = new Prototype< teststubs::Aclass> ();
     189  newprototype->setcount(1);
     190  PrototypeFactoryStub::getInstance().installPrototype(newprototype, std::string("Aclass"));
     191  newprototype = NULL;
     192
     193  IPrototype *rndA_1 = PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
     194  CPPUNIT_ASSERT( 1 == rndA_1->getcount() );
     195
     196  rndA_1->count();
     197  CPPUNIT_ASSERT( 2 == rndA_1->getcount() );
     198
     199  IPrototype *rndA_2 = PrototypeFactoryStub::getInstance().getProduct(std::string("Aclass"));
     200  CPPUNIT_ASSERT( 1 == rndA_2->getcount() );
     201  CPPUNIT_ASSERT( rndA_1->getcount() != rndA_2->getcount() );
     202}
  • src/Patterns/unittests/PrototypeFactoryUnitTest.hpp

    rd76c105 r567640  
    2727  CPPUNIT_TEST ( Individualitytest );
    2828  CPPUNIT_TEST ( PrototypeManipulatortest );
     29  CPPUNIT_TEST ( installPrototypetest );
    2930  CPPUNIT_TEST_SUITE_END();
    3031
     
    3940  void Individualitytest();
    4041  void PrototypeManipulatortest();
     42  void installPrototypetest();
    4143
    4244private:
  • src/Patterns/unittests/stubs/CloneStub.hpp

    rd76c105 r567640  
    3939
    4040    /**
    41      * Test is friend such that it can access protected cstor.
     41     * Tests are friend such that it can access protected cstor.
    4242     */
    4343    friend class CloneTest;
     44    friend class PrototypeFactoryTest;
    4445
    4546protected:
Note: See TracChangeset for help on using the changeset viewer.