PLearn 0.1
|
Template class for option definitions. More...
#include <ArrayAllocator.h>
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 Object * | getAsObject (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 Object * | getAsObject (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 Object * | getIndexedObject (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 Object * | getIndexedObject (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 | |
T | optionValue |
Enclosing * | 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.
typedef Enclosing PLearn::Option< T, Enclosing >::enclosing_type |
Definition at line 65 of file ArrayAllocator.h.
typedef OptionBase PLearn::Option< T, Enclosing >::inherited [private] |
Reimplemented in PLearn::TVecOption< ObjectType, VecElementType >.
typedef T PLearn::Option< T, Enclosing >::value_type |
Definition at line 64 of file ArrayAllocator.h.
PLearn::Option< T, Enclosing >::Option | ( | const T & | defaultValue, |
Enclosing * | encl | ||
) | [inline] |
Definition at line 68 of file ArrayAllocator.h.
: optionValue(defaultValue), enclosing(encl) {}
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.
: inherited(optionname, flags, optiontype, defaultval, description, level), ptr(member_ptr) { }
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); }
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); }
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); }
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); }
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); }
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); };
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); };
OptionType ObjectType::* PLearn::Option< T, Enclosing >::getPtr | ( | ) | const [inline] |
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()
.
o | The object containing the object |
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); }
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; }
Enclosing& PLearn::Option< T, Enclosing >::operator() | ( | const T & | newValue | ) | [inline] |
Definition at line 72 of file ArrayAllocator.h.
{ optionValue = newValue; return *enclosing; }
const T& PLearn::Option< T, Enclosing >::operator() | ( | ) | const [inline] |
Definition at line 76 of file ArrayAllocator.h.
{ return optionValue; }
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_(); }
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.
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); }
Enclosing* PLearn::Option< T, Enclosing >::enclosing [private] |
Definition at line 82 of file ArrayAllocator.h.
T PLearn::Option< T, Enclosing >::optionValue [private] |
Definition at line 81 of file ArrayAllocator.h.
OptionType ObjectType::* PLearn::Option< T, Enclosing >::ptr [protected] |
Definition at line 89 of file Option.h.
Referenced by PLearn::Option< DeallocatorType, self >::getAsObject(), PLearn::Option< DeallocatorType, self >::getAsVoidPtr(), PLearn::Option< DeallocatorType, self >::getIndexedObject(), PLearn::Option< DeallocatorType, self >::getPtr(), PLearn::Option< DeallocatorType, self >::indexableSize(), PLearn::Option< DeallocatorType, self >::read(), and PLearn::Option< DeallocatorType, self >::write().