PLearn 0.1
Public Member Functions | Protected Attributes | Private Types
PLearn::StaticOption< OptionType > Class Template Reference

Template class for static option definitions This is not thread safe while loading or saving! If you have some data in memory then load some other, the static value will be overwrited! This will be saved and loaded for each instance, but will override the station version each time. More...

#include <Option.h>

Inheritance diagram for PLearn::StaticOption< OptionType >:
Inheritance graph
[legend]
Collaboration diagram for PLearn::StaticOption< OptionType >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 StaticOption (const string &optionname, OptionType *member_ptr, flag_t flags, const string &optiontype, const string &defaultval, const string &description, const OptionLevel &level)
 Most of these parameters only serve to provide the user with an informative help text.
virtual void read (Object *o, PStream &in) const
 Read the option into the specified object from the input stream.
virtual void write (const Object *o, PStream &out) const
 Write the option from the specified object to the output stream.
virtual ObjectgetAsObject (Object *o) const
 Return as an Object* the option within the specified object; it's an error to call this function if the option does not refer to an Object&, Object* or PP<Object>.
virtual const ObjectgetAsObject (const Object *o) const
 Return as an Object* the option within the specified object; it's an error to call this function if the option does not refer to an Object&, Object* or PP<Object>.
virtual ObjectgetIndexedObject (Object *o, int i) const
 Return as an Object* the i-th item option, which must be either a TVec or an Array.
virtual const ObjectgetIndexedObject (const Object *o, int i) const
 Return as an Object* the i-th item option, which must be either a TVec or an Array.
virtual void * getAsVoidPtr (Object *o) const
 Return the option contained in the specified object as a raw void*.
virtual const void * getAsVoidPtr (const Object *o) const
 Return the option contained in the specified object as a raw void*.
virtual string optionHolderClassName (const Object *o) const
virtual int diff (const string &refer, const string &other, PLearnDiff *diffs) const
 Comparison between two option values.
virtual bool isAccessibleAsObject () const
 Implementation of isAccessibleAsObject() relies on caching since the first call may need to default-construct an object; relatively slow.
virtual int indexableSize (const Object *o) const
 Return the size of the indexable option, IF it is indexable.

Protected Attributes

OptionType * ptr

Private Types

typedef OptionBase inherited

Detailed Description

template<class OptionType>
class PLearn::StaticOption< OptionType >

Template class for static option definitions This is not thread safe while loading or saving! If you have some data in memory then load some other, the static value will be overwrited! This will be saved and loaded for each instance, but will override the station version each time.

Definition at line 189 of file Option.h.


Member Typedef Documentation

template<class OptionType>
typedef OptionBase PLearn::StaticOption< OptionType >::inherited [private]

Reimplemented in PLearn::TVecStaticOption< VecElementType >.

Definition at line 191 of file Option.h.


Constructor & Destructor Documentation

template<class OptionType>
PLearn::StaticOption< OptionType >::StaticOption ( const string &  optionname,
OptionType *  member_ptr,
flag_t  flags,
const string &  optiontype,
const string &  defaultval,
const string &  description,
const OptionLevel level 
) [inline]

Most of these parameters only serve to provide the user with an informative help text.

Definition at line 200 of file Option.h.


Member Function Documentation

template<class OptionType>
virtual int PLearn::StaticOption< OptionType >::diff ( const string &  refer,
const string &  other,
PLearnDiff diffs 
) const [inline, virtual]

Comparison between two option values.

Implements PLearn::OptionBase.

Definition at line 255 of file Option.h.

    {
        /*
        pout << "Calling Option<" << TypeTraits<ObjectType>::name()
            << "," << TypeTraits<OptionType>::name() << ">::diff" << endl;
        */
        // return PLearn::diff(refer, other, this, diffs);       
        //return DiffTemplate<ObjectType, OptionType>::diff(refer, other,
        //                                                  this, diffs);
        // @todo: quick hack, fix this (maybe? Xavier?)
        return 0;
    }
template<class OptionType>
virtual Object* PLearn::StaticOption< OptionType >::getAsObject ( Object o) const [inline, virtual]

Return as an Object* the option within the specified object; it's an error to call this function if the option does not refer to an Object&, Object* or PP<Object>.

Implements PLearn::OptionBase.

Definition at line 213 of file Option.h.

    { return toObjectPtr(*ptr); }
template<class OptionType>
virtual const Object* PLearn::StaticOption< OptionType >::getAsObject ( const Object o) const [inline, virtual]

Return as an Object* the option within the specified object; it's an error to call this function if the option does not refer to an Object&, Object* or PP<Object>.

Implements PLearn::OptionBase.

Definition at line 216 of file Option.h.

    { return toObjectPtr(*ptr); }
template<class OptionType>
virtual const void* PLearn::StaticOption< OptionType >::getAsVoidPtr ( const Object o) const [inline, virtual]

Return the option contained in the specified object as a raw void*.

Can be used with the optiontype() accessor to cast to an appropriate type. Should be used sparingly and only when absolutely necessary.

Implements PLearn::OptionBase.

Definition at line 228 of file Option.h.

    { return ptr; }
template<class OptionType>
virtual void* PLearn::StaticOption< OptionType >::getAsVoidPtr ( Object o) const [inline, virtual]

Return the option contained in the specified object as a raw void*.

Can be used with the optiontype() accessor to cast to an appropriate type. Should be used sparingly and only when absolutely necessary.

Implements PLearn::OptionBase.

Definition at line 225 of file Option.h.

    { return ptr; }
template<class OptionType>
virtual Object* PLearn::StaticOption< OptionType >::getIndexedObject ( Object o,
int  i 
) const [inline, virtual]

Return as an Object* the i-th item option, which must be either a TVec or an Array.

It's an error to call this function if the indexed item does not refer to an Object* or PP<Object>.

Implements PLearn::OptionBase.

Definition at line 219 of file Option.h.

    { return toIndexedObjectPtr(*ptr, i); };
template<class OptionType>
virtual const Object* PLearn::StaticOption< OptionType >::getIndexedObject ( const Object o,
int  i 
) const [inline, virtual]

Return as an Object* the i-th item option, which must be either a TVec or an Array.

It's an error to call this function if the indexed item does not refer to an Object* or PP<Object>.

Implements PLearn::OptionBase.

Definition at line 222 of file Option.h.

    { return toIndexedObjectPtr(*ptr, i); };
template<class OptionType>
virtual int PLearn::StaticOption< OptionType >::indexableSize ( const Object o) const [inline, virtual]

Return the size of the indexable option, IF it is indexable.

If not indexable, return 0. If indexable, this returns one more than the maximum permissible index in getIndexedObject() or readIntoIndex() or writeAtIndex().

Parameters:
oThe object containing the object
Returns:
The number of indexable objects within the option

Implements PLearn::OptionBase.

Definition at line 277 of file Option.h.

    {
        return indexableObjectSize(*ptr);
    }
template<class OptionType>
virtual bool PLearn::StaticOption< OptionType >::isAccessibleAsObject ( ) const [inline, virtual]

Implementation of isAccessibleAsObject() relies on caching since the first call may need to default-construct an object; relatively slow.

Implements PLearn::OptionBase.

Definition at line 271 of file Option.h.

    {
        static bool accessible = isConvertibleToObjectPtr(OptionType());
        return accessible;
    }
template<class OptionType>
virtual string PLearn::StaticOption< OptionType >::optionHolderClassName ( const Object o) const [inline, virtual]
Todo:
check that this is correct

Implements PLearn::OptionBase.

Definition at line 252 of file Option.h.

    { return "static"; }
template<class OptionType>
virtual void PLearn::StaticOption< OptionType >::read ( Object o,
PStream in 
) const [inline, virtual]

Read the option into the specified object from the input stream.

Implements PLearn::OptionBase.

Definition at line 207 of file Option.h.

    { in >> *ptr; }
template<class OptionType>
virtual void PLearn::StaticOption< OptionType >::write ( const Object o,
PStream out 
) const [inline, virtual]

Write the option from the specified object to the output stream.

Implements PLearn::OptionBase.

Definition at line 210 of file Option.h.

    { out << *ptr; }

Member Data Documentation

template<class OptionType>
OptionType* PLearn::StaticOption< OptionType >::ptr [protected]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines