PLearn 0.1
Public Types | Public Member Functions | Protected Attributes | Private Types | Private Attributes
PLearn::Option< T, Enclosing > Class Template Reference

Template class for option definitions. More...

#include <ArrayAllocator.h>

Inheritance diagram for PLearn::Option< T, Enclosing >:
Inheritance graph
[legend]
Collaboration diagram for PLearn::Option< T, Enclosing >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef T value_type
typedef Enclosing enclosing_type

Public Member Functions

 Option (const T &defaultValue, Enclosing *encl)
Enclosing & operator() (const T &newValue)
const T & operator() () const
 Option (const string &optionname, OptionType ObjectType::*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
 Returns the name of the class in to which this option belongs.
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.
OptionType ObjectType::* getPtr () const
 Accessor to the member pointer wrapped by the option.

Protected Attributes

OptionType ObjectType::* ptr

Private Types

typedef OptionBase inherited

Private Attributes

optionValue
Enclosing * enclosing

Detailed Description

template<class T, class Enclosing>
class PLearn::Option< T, Enclosing >

Template class for option definitions.

This class provides a unique stop to set all options in an ArrayAllocator object. These options must be passed upon constructing the object.

Definition at line 61 of file ArrayAllocator.h.


Member Typedef Documentation

template<class T, class Enclosing>
typedef Enclosing PLearn::Option< T, Enclosing >::enclosing_type

Definition at line 65 of file ArrayAllocator.h.

template<class T, class Enclosing>
typedef OptionBase PLearn::Option< T, Enclosing >::inherited [private]

Reimplemented in PLearn::TVecOption< ObjectType, VecElementType >.

Definition at line 86 of file Option.h.

template<class T, class Enclosing>
typedef T PLearn::Option< T, Enclosing >::value_type

Definition at line 64 of file ArrayAllocator.h.


Constructor & Destructor Documentation

template<class T, class Enclosing>
PLearn::Option< T, Enclosing >::Option ( const T &  defaultValue,
Enclosing *  encl 
) [inline]

Definition at line 68 of file ArrayAllocator.h.

        : optionValue(defaultValue), enclosing(encl)
    {}
template<class T, class Enclosing>
PLearn::Option< T, Enclosing >::Option ( const string &  optionname,
OptionType ObjectType::*  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 95 of file Option.h.


Member Function Documentation

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

Comparison between two option values.

Implements PLearn::OptionBase.

Definition at line 148 of file Option.h.

Referenced by PLearn::diff(), and PLearn::Option< DeallocatorType, self >::diff().

    {
        /*
        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);
    }

Here is the caller graph for this function:

template<class T, class Enclosing>
virtual Object* PLearn::Option< T, Enclosing >::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 108 of file Option.h.

    { return toObjectPtr(dynamic_cast<ObjectType*>(o)->*ptr); }
template<class T, class Enclosing>
virtual const Object* PLearn::Option< T, Enclosing >::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 111 of file Option.h.

    { return toObjectPtr(dynamic_cast<const ObjectType*>(o)->*ptr); }
template<class T, class Enclosing>
virtual void* PLearn::Option< T, Enclosing >::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 120 of file Option.h.

    { return &(dynamic_cast<ObjectType*>(o)->*ptr); }
template<class T, class Enclosing>
virtual const void* PLearn::Option< T, Enclosing >::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 123 of file Option.h.

    { return &(dynamic_cast<const ObjectType*>(o)->*ptr); }
template<class T, class Enclosing>
virtual const Object* PLearn::Option< T, Enclosing >::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 117 of file Option.h.

    { return toIndexedObjectPtr(dynamic_cast<const ObjectType*>(o)->*ptr, i); };
template<class T, class Enclosing>
virtual Object* PLearn::Option< T, Enclosing >::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 114 of file Option.h.

    { return toIndexedObjectPtr(dynamic_cast<ObjectType*>(o)->*ptr, i); };
template<class T, class Enclosing>
OptionType ObjectType::* PLearn::Option< T, Enclosing >::getPtr ( ) const [inline]

Accessor to the member pointer wrapped by the option.

Definition at line 176 of file Option.h.

    {
        return ptr;
    }
template<class T, class Enclosing>
virtual int PLearn::Option< T, Enclosing >::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 168 of file Option.h.

    {
        const ObjectType* oto = dynamic_cast<const ObjectType*>(o);
        PLASSERT( oto );
        return indexableObjectSize(oto->*ptr);
    }
template<class T, class Enclosing>
virtual bool PLearn::Option< T, Enclosing >::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 162 of file Option.h.

    {
        static bool accessible = isConvertibleToObjectPtr(OptionType());
        return accessible;
    }
template<class T, class Enclosing>
Enclosing& PLearn::Option< T, Enclosing >::operator() ( const T &  newValue) [inline]

Definition at line 72 of file ArrayAllocator.h.

                                             {
        optionValue = newValue;
        return *enclosing;
    }
template<class T, class Enclosing>
const T& PLearn::Option< T, Enclosing >::operator() ( ) const [inline]

Definition at line 76 of file ArrayAllocator.h.

                                {
        return optionValue;
    }
template<class T, class Enclosing>
virtual string PLearn::Option< T, Enclosing >::optionHolderClassName ( const Object o) const [inline, virtual]

Returns the name of the class in to which this option belongs.

Implements PLearn::OptionBase.

Definition at line 145 of file Option.h.

    { return dynamic_cast<const ObjectType*>(o)->ObjectType::_classname_(); }
template<class T, class Enclosing>
virtual void PLearn::Option< T, Enclosing >::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 102 of file Option.h.

    { (void)(in >> dynamic_cast<ObjectType*>(o)->*ptr); }
template<class T, class Enclosing>
virtual void PLearn::Option< T, Enclosing >::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 105 of file Option.h.

    { (void)(out << dynamic_cast<ObjectType *>(const_cast<Object*>(o))->*ptr); }

Member Data Documentation

template<class T, class Enclosing>
Enclosing* PLearn::Option< T, Enclosing >::enclosing [private]

Definition at line 82 of file ArrayAllocator.h.

template<class T, class Enclosing>
T PLearn::Option< T, Enclosing >::optionValue [private]

Definition at line 81 of file ArrayAllocator.h.

template<class T, class Enclosing>
OptionType ObjectType::* PLearn::Option< T, Enclosing >::ptr [protected]

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