App::PropertyEnumeration Class Reference

Enum properties This property fullfill the need of enumarations. More...

#include <PropertyStandard.h>

Inheritance diagram for App::PropertyEnumeration:
App::PropertyInteger App::Property Base::Persistence Base::BaseClass

List of all members.

Public Member Functions

virtual const char * getEditorName (void) const
 Get the class name of the associated property editor item.
virtual PyObjectgetPyObject (void)
 This method returns the Python wrapper for a C++ object.
virtual Base::Type getTypeId (void) const
 PropertyEnumeration ()
 Standard constructor.
virtual void Restore (Base::XMLReader &reader)
 This method is used to restore properties from an XML document.
virtual void Save (Base::Writer &writer) const
 This method is used to save properties to an XML document.
virtual void setPyObject (PyObject *)
 ~PropertyEnumeration ()
 destructor



const char ** getEnums (void) const
 get the pointer to the enum list
std::vector< std::string > getEnumVector (void) const
 get all possible enum values as vector of strings
const char * getValueAsString (void) const
 get the value as string
bool isPartOf (const char *value) const
 checks if a string is included in the enumeration
bool isValue (const char *value) const
 checks if the property is set to a certain string value
void setEnums (const char **plEnums)
 Enumeration methods.
void setEnumVector (const std::vector< std::string > &)
 set all enum values as vector of strings
void setValue (long)
 set directly the enum value In DEBUG checks for boundaries.
void setValue (const char *value)
 set the enum by a string is slower the setValue(long).

Static Public Member Functions

static void * create (void)
static Base::Type getClassTypeId (void)
static void init (void)

Detailed Description

Enum properties This property fullfill the need of enumarations.

It holds basicly a state (integer) and a list of valid state names. If the valid state list is not set it act basicly like a IntegerProperty and do no checking. If the list is set it checks on the range and if you set the state with a string if its included in the enumarations. In DEBUG the boundaries get checked, otherwise the caller of setValue() has the responsebility to check the correctnes. This mean if you set by setValue(const char*) with an not included value and not using isPartOf() before, in DEBUG you get an assert() in release its set to 0.

Definition at line 134 of file PropertyStandard.h.


Constructor & Destructor Documentation

PropertyEnumeration::PropertyEnumeration (  ) 

Standard constructor.

Definition at line 266 of file PropertyStandard.cpp.

PropertyEnumeration::~PropertyEnumeration (  ) 

destructor

Definition at line 272 of file PropertyStandard.cpp.


Member Function Documentation

void * App::PropertyEnumeration::create ( void   )  [static]

Reimplemented from App::PropertyInteger.

Definition at line 260 of file PropertyStandard.cpp.

Base::Type App::PropertyEnumeration::getClassTypeId ( void   )  [static]

Reimplemented from App::PropertyInteger.

Definition at line 260 of file PropertyStandard.cpp.

Referenced by Gui::PropertyEditor::PropertyEnumItem::value().

virtual const char* App::PropertyEnumeration::getEditorName ( void   )  const [inline, virtual]

Get the class name of the associated property editor item.

Reimplemented from App::PropertyInteger.

Definition at line 177 of file PropertyStandard.h.

const char ** PropertyEnumeration::getEnums ( void   )  const

get the pointer to the enum list

Definition at line 407 of file PropertyStandard.cpp.

Referenced by Gui::ViewProviderDocumentObject::setActiveMode().

std::vector< std::string > PropertyEnumeration::getEnumVector ( void   )  const

get all possible enum values as vector of strings

Definition at line 374 of file PropertyStandard.cpp.

References result.

Referenced by Save().

PyObject * PropertyEnumeration::getPyObject ( void   )  [virtual]

This method returns the Python wrapper for a C++ object.

It's in the responsibility of the programmer to do the correct reference counting. Basically there are two ways how to implement that: Either always return a new Python object then reference counting is not a matter or return always the same Python object then the reference counter must be incremented by one. However, it's absolutely forbidden to return always the same Python object without incrementing the reference counter.

The default implementation returns 'None'.

Reimplemented from App::PropertyInteger.

Definition at line 456 of file PropertyStandard.cpp.

References getValueAsString().

Base::Type App::PropertyEnumeration::getTypeId ( void   )  const [virtual]

Reimplemented from App::PropertyInteger.

Definition at line 260 of file PropertyStandard.cpp.

const char * PropertyEnumeration::getValueAsString ( void   )  const

get the value as string

Definition at line 367 of file PropertyStandard.cpp.

References App::PropertyInteger::getValue().

Referenced by getPyObject(), and Gui::ViewProviderDocumentObject::setActiveMode().

void App::PropertyEnumeration::init ( void   )  [static]

Reimplemented from App::PropertyInteger.

Definition at line 260 of file PropertyStandard.cpp.

bool PropertyEnumeration::isPartOf ( const char *  value  )  const

checks if a string is included in the enumeration

Definition at line 348 of file PropertyStandard.cpp.

Referenced by setPyObject().

bool PropertyEnumeration::isValue ( const char *  value  )  const

checks if the property is set to a certain string value

Definition at line 340 of file PropertyStandard.cpp.

References App::PropertyInteger::getValue().

void PropertyEnumeration::Restore ( Base::XMLReader  )  [virtual]

This method is used to restore properties from an XML document.

It uses the XMLReader class, which bases on SAX, to read the in Save() written information. Again the Vector as an example:

 void PropertyVector::Restore(Base::XMLReader &reader)
 {
   // read my Element
   reader.readElement("PropertyVector");
   // get the value of my Attribute
   _cVec.x = (float)reader.getAttributeAsFloat("valueX");
   _cVec.y = (float)reader.getAttributeAsFloat("valueY");
   _cVec.z = (float)reader.getAttributeAsFloat("valueZ");
 }

Reimplemented from App::PropertyInteger.

Definition at line 431 of file PropertyStandard.cpp.

References RobotExampleTrajectoryOutOfShapes::count, Base::XMLReader::getAttribute(), Base::XMLReader::getAttributeAsInteger(), Base::XMLReader::hasAttribute(), Base::XMLReader::readElement(), Base::XMLReader::readEndElement(), setEnumVector(), and setValue().

void PropertyEnumeration::Save ( Base::Writer  )  const [virtual]

This method is used to save properties to an XML document.

A good example you'll find in PropertyStandard.cpp, e.g. the vector:

  void PropertyVector::Save (Writer &writer) const
  {
     writer << writer.ind() << "<PropertyVector valueX=\"" <<  _cVec.x <<
                                            "\" valueY=\"" <<  _cVec.y <<
                                            "\" valueZ=\"" <<  _cVec.z <<"\"/>" << endl;
  }

The writer.ind() expression writes the indention, just for pretty printing of the XML. As you see, the writing of the XML document is not done with a DOM implementation because of performance reasons. Therefore the programmer has to take care that a valid XML document is written. This means closing tags and writing UTF-8.

See also:
Base::Writer

Reimplemented from App::PropertyInteger.

Definition at line 412 of file PropertyStandard.cpp.

References App::PropertyInteger::_lValue, Base::Writer::decInd(), App::Property::encodeAttribute(), getEnumVector(), Base::Writer::incInd(), Base::Writer::ind(), and Base::Writer::Stream().

void PropertyEnumeration::setEnums ( const char **  plEnums  ) 

Enumeration methods.

setting the enumaration string list The list is a NULL terminated array of pointers to a const char* string

 const char enums[] = {"Black","White","Other",NULL}

Definition at line 277 of file PropertyStandard.cpp.

References draftTools::p.

Referenced by Gui::ViewProviderDocumentObject::attach(), App::FeatureTest::FeatureTest(), Robot::TrajectoryDressUpObject::TrajectoryDressUpObject(), PartGui::ViewProviderPartBase::ViewProviderPartBase(), PartGui::ViewProviderPartExt::ViewProviderPartExt(), and Gui::ViewProviderDocumentObject::~ViewProviderDocumentObject().

void PropertyEnumeration::setEnumVector ( const std::vector< std::string > &  values  ) 

set all enum values as vector of strings

Definition at line 391 of file PropertyStandard.cpp.

Referenced by Restore(), and setPyObject().

void PropertyEnumeration::setPyObject ( PyObject value  )  [virtual]

Reimplemented from App::PropertyInteger.

Definition at line 466 of file PropertyStandard.cpp.

References draftlibs::dxfReader::error(), isPartOf(), setEnumVector(), and setValue().

void PropertyEnumeration::setValue ( long  value  ) 

set directly the enum value In DEBUG checks for boundaries.

Is faster then using setValue(const char*).

Reimplemented from App::PropertyInteger.

Definition at line 322 of file PropertyStandard.cpp.

References setValue().

void PropertyEnumeration::setValue ( const char *  value  ) 

The documentation for this class was generated from the following files:

Generated on Wed Nov 23 19:01:44 2011 for FreeCAD by  doxygen 1.6.1