PLearn 0.1
|
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>
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 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 |
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 |
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.
typedef OptionBase PLearn::StaticOption< OptionType >::inherited [private] |
Reimplemented in PLearn::TVecStaticOption< VecElementType >.
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.
: inherited(optionname, flags, optiontype, defaultval, description, level), ptr(member_ptr) { }
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; }
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); }
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); }
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; }
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; }
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); };
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); };
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()
.
o | The object containing the object |
Implements PLearn::OptionBase.
Definition at line 277 of file Option.h.
{ return indexableObjectSize(*ptr); }
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; }
virtual string PLearn::StaticOption< OptionType >::optionHolderClassName | ( | const Object * | o | ) | const [inline, virtual] |
Implements PLearn::OptionBase.
Definition at line 252 of file Option.h.
{ return "static"; }
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.
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; }
OptionType* PLearn::StaticOption< OptionType >::ptr [protected] |
Definition at line 194 of file Option.h.
Referenced by PLearn::StaticOption< TVec< VecElementType > >::getAsObject(), PLearn::StaticOption< TVec< VecElementType > >::getAsVoidPtr(), PLearn::StaticOption< TVec< VecElementType > >::getIndexedObject(), PLearn::StaticOption< TVec< VecElementType > >::indexableSize(), PLearn::StaticOption< TVec< VecElementType > >::read(), and PLearn::StaticOption< TVec< VecElementType > >::write().