Changeset 529 for library/bdm

Show
Ignore:
Timestamp:
08/14/09 09:03:02 (15 years ago)
Author:
vbarta
Message:

defined *_ptr wrappers of shared pointers

Location:
library/bdm
Files:
12 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/base/bdmbase.h

    r527 r529  
    226226}; 
    227227UIREGISTER (RV); 
     228SHAREDPTR (RV); 
    228229 
    229230//! Concat two random variables 
     
    386387 
    387388}; 
    388  
     389SHAREDPTR(epdf); 
    389390 
    390391//! Conditional probability density, e.g. modeling some dependencies. 
     
    487488                //!@} 
    488489}; 
     490SHAREDPTR(mpdf); 
    489491 
    490492template <class EPDF> 
     
    740742}; 
    741743UIREGISTER (mepdf); 
     744SHAREDPTR (mepdf); 
    742745 
    743746//! \brief Combines RVs from a list of mpdfs to a single one. 
     
    990993}; 
    991994 
     995typedef Array<shared_ptr<epdf> > epdf_array; 
     996 
     997typedef Array<shared_ptr<mpdf> > mpdf_array; 
     998 
    992999template<class EPDF> 
    9931000vec mpdf_internal<EPDF>::samplecond (const vec &cond) 
  • library/bdm/base/datasources.h

    r527 r529  
    107107 
    108108UIREGISTER ( ITppFileDS ); 
     109SHAREDPTR ( ITppFileDS ); 
    109110 
    110111/*! 
     
    263264 
    264265UIREGISTER ( ArxDS ); 
     266SHAREDPTR ( ArxDS ); 
    265267 
    266268class stateDS : public DS { 
     
    346348 
    347349UIREGISTER ( stateDS ); 
     350SHAREDPTR ( stateDS ); 
    348351 
    349352}; //namespace 
  • library/bdm/base/loggers.h

    r477 r529  
    9292 
    9393UIREGISTER ( memlog ); 
     94SHAREDPTR ( memlog ); 
    9495 
    9596/*! 
     
    139140 
    140141UIREGISTER ( dirfilelog ); 
     142SHAREDPTR ( dirfilelog ); 
    141143 
    142144}; 
  • library/bdm/base/user_info.h

    r527 r529  
    550550        ParticularUI<T> ( const string &class_name ) : UI ( class_name, &typeid ( T ) ) {}; 
    551551 
    552         //! A method returning a brand new instance of class T, this method is the reason why there have to be a parameterless construcotor in class T 
     552        //! A method returning a brand new instance of class T, this method is the reason why there have to be a parameterless constructor in class T 
    553553        root* new_instance() const { 
    554554                return new T(); 
     
    565565  \brief Macro for registration of class into map of user-infos, registered class is scriptable using UI static methods 
    566566 
    567   Argument \a class_name has to be a descendant of root class and also, it has to have parameterless constructor prepared. 
     567  Argument \a class_name has to be a descendant of root class and also to have a default constructor. 
    568568  This macro should be used in header file, immediately after a class declaration. 
    569569 
  • library/bdm/estim/arx.h

    r477 r529  
    164164 
    165165UIREGISTER ( ARX ); 
     166SHAREDPTR ( ARX ); 
    166167 
    167168} 
  • library/bdm/estim/kalman.h

    r527 r529  
    280280 
    281281UIREGISTER ( EKFCh ); 
     282SHAREDPTR ( EKFCh ); 
    282283 
    283284 
     
    466467 
    467468UIREGISTER ( MultiModel ); 
     469SHAREDPTR ( MultiModel ); 
    468470 
    469471 
  • library/bdm/mex/mex_datasource.h

    r477 r529  
    4040                it_assert_debug ( time < Data.cols(), "MemDS delays are too high." ); 
    4141 
    42                 RV* r = UI::build<RV> ( set, "rv", UI::compulsory ); 
     42                shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::compulsory ); 
    4343                RV ru = RV(); 
    4444                set_rvs ( *r, ru ); 
     
    5050 
    5151UIREGISTER ( MexDS ); 
     52SHAREDPTR ( MexDS ); 
    5253 
    5354} 
  • library/bdm/mex/mex_logger.h

    r477 r529  
    7171}; 
    7272UIREGISTER ( mexlog ); 
     73SHAREDPTR ( mexlog ); 
    7374} 
  • library/bdm/shared_ptr.h

    r477 r529  
    11/*! 
    22  \file 
    3   \brief BDM's own smart pointer. 
     3  \brief BDM's own smart pointers. 
    44  \author Vaclav Barta. 
    55 
     
    2222namespace bdm { 
    2323 
    24 //! A naive implementation of roughly a subset of the std::tr1:shared_ptr spec (really just roughly - it ignores memory exceptions, for example; also note I didn't read the spec). 
    25 // The standard template would naturally be preferable, _if_ it was 
    26 // included in the standard libraries of all supported compilers - but 
    27 // that's exactly what remains to be seen... 
     24/*! \brief A naive implementation of roughly a subset of the std::tr1:shared_ptr spec 
     25 
     26  Really just roughly - it ignores memory 
     27  exceptions, for example; also note I didn't read the spec. 
     28 
     29  The standard template would naturally be preferable, _if_ it was 
     30  included in the standard libraries of all supported compilers - but 
     31  as of 2009, that's still a problem... 
     32*/ 
    2833template <typename T> 
    2934class shared_ptr { 
     
    4146        } 
    4247 
    43         //! Constructs a shared_ptr that owns the pointer p (unless p is 
    44         //! null, in which case this constructor creates an empty 
    45         //! shared_ptr). 
     48        /*!  
     49          Constructs a shared_ptr that owns the pointer p (unless p 
     50          is NULL, in which case this constructor creates an empty 
     51          shared_ptr). When p isn't null, it must have been alllocated 
     52          by new! 
     53        */ 
    4654        shared_ptr ( T *p ) : 
    4755                        payload ( p ), 
     
    7078        } 
    7179 
    72         shared_ptr &operator= ( const shared_ptr &other ) { 
     80        shared_ptr<T> &operator= ( const shared_ptr<T> &other ) { 
    7381                other.add_ref(); 
    7482                del_ref(); 
     
    178186} 
    179187 
     188/*! \brief A wrapper of shared_ptr which is never empty. 
     189 
     190  T must have a default constructor. 
     191 
     192  Note that shared_ptr's destructor isn't virtual - don't call delete 
     193  on pointers to instances of this class. 
     194 */ 
     195template <typename T> 
     196class object_ptr : public shared_ptr<T> 
     197{ 
     198public: 
     199        /*! 
     200          \brief Default constructor 
     201 
     202          Calls T's default constructor. 
     203        */ 
     204        object_ptr() : shared_ptr<T> ( new T() ) { } 
     205 
     206        /*! 
     207          \brief Upcast from shared_ptr<T> to object_ptr<T> 
     208 
     209          \param b The shared pointer, which must not be empty. 
     210        */ 
     211        object_ptr ( const shared_ptr<T> &b ) : shared_ptr<T> ( b ) { 
     212                it_assert_debug ( this->get(), "object_ptr cannot be empty" ); 
     213        } 
     214 
     215        /*!  
     216          Constructs an object_ptr that owns the pointer p. p must 
     217          have been alllocated by new! 
     218        */ 
     219        object_ptr ( T *p ) : shared_ptr<T> ( p ) { 
     220                it_assert_debug ( p, "object_ptr cannot be empty" ); 
     221        } 
     222 
     223        object_ptr<T> &operator= ( const object_ptr<T> &other ) { 
     224                shared_ptr<T>::operator= ( other ); 
     225                return *this; 
     226        } 
     227}; 
     228 
     229#define SHAREDPTR(class_name) typedef bdm::object_ptr< class_name > class_name##_ptr 
     230 
     231#define SHAREDPTR2(template_class_name, template_parameter_name) typedef bdm::object_ptr< template_class_name < template_parameter_name > > template_class_name##_##template_parameter_name##_ptr 
     232 
    180233} 
    181234 
  • library/bdm/stat/emix.h

    r527 r529  
    186186        } 
    187187}; 
    188  
     188SHAREDPTR( emix ); 
    189189 
    190190/*! 
     
    362362}; 
    363363UIREGISTER ( mprod ); 
     364SHAREDPTR ( mprod ); 
    364365 
    365366//! Product of independent epdfs. For dependent pdfs, use mprod. 
  • library/bdm/stat/exp_family.h

    r527 r529  
    165165}; 
    166166UIREGISTER (enorm<chmat>); 
     167SHAREDPTR2 ( enorm, chmat ); 
    167168UIREGISTER (enorm<ldmat>); 
     169SHAREDPTR2 ( enorm, ldmat ); 
    168170UIREGISTER (enorm<fsqmat>); 
     171SHAREDPTR2 ( enorm, fsqmat ); 
    169172 
    170173 
     
    241244                //!@} 
    242245}; 
    243 UIREGISTER (egiw); 
     246UIREGISTER ( egiw ); 
     247SHAREDPTR ( egiw ); 
    244248 
    245249/*! \brief Dirichlet posterior density 
     
    399403}; 
    400404UIREGISTER (egamma); 
     405SHAREDPTR ( egamma ); 
     406 
    401407/*! 
    402408 \brief Inverse-Gamma posterior density 
     
    566572}; 
    567573UIREGISTER (mlnorm<ldmat>); 
     574SHAREDPTR2 ( mlnorm, ldmat ); 
    568575UIREGISTER (mlnorm<fsqmat>); 
     576SHAREDPTR2 ( mlnorm, fsqmat ); 
    569577UIREGISTER (mlnorm<chmat>); 
     578SHAREDPTR2 ( mlnorm, chmat ); 
    570579 
    571580//! Mpdf with general function for mean value 
     
    627636 
    628637UIREGISTER (mgnorm<chmat>); 
     638SHAREDPTR2 ( mgnorm, chmat ); 
    629639 
    630640 
     
    716726}; 
    717727UIREGISTER (mgamma); 
     728SHAREDPTR (mgamma); 
    718729 
    719730/*! 
     
    860871 
    861872UIREGISTER (migamma_ref); 
     873SHAREDPTR (migamma_ref); 
    862874 
    863875/*! Log-Normal probability density 
     
    941953 
    942954UIREGISTER (mlognorm); 
     955SHAREDPTR (mlognorm); 
    943956 
    944957/*! inverse Wishart density defined on Choleski decomposition 
  • library/bdm/stat/merger.h

    r507 r529  
    316316}; 
    317317UIREGISTER ( merger_base ); 
     318SHAREDPTR ( merger_base ); 
    318319 
    319320class merger_mix : public merger_base { 
     
    398399}; 
    399400UIREGISTER ( merger_mix ); 
     401SHAREDPTR ( merger_mix ); 
    400402 
    401403}