UFObject Class Reference

UFObjects are smart data containers, which are suppose to know everything that is needed to handle and manipulated their content. More...

#include <ufobject.h>

Inheritance diagram for UFObject:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual ~UFObject ()
 Trigger a uf_destroyed event and destroy the object.
UFName Name () const
 Retrieve the name of the UFObject.
void SetUserData (void *userData)
 Set pointer to general user data.
void * UserData ()
 Retrieve pointer to general user data.
 operator class UFNumber & ()
 Downcast UFObject to UFNumber.
 operator const class UFNumber & () const
 Downcast const UFObject to const UFNumber.
 operator class UFNumberArray & ()
 Downcast UFObject to UFNumberArray.
 operator const class UFNumberArray & () const
 Downcast const UFObject to const UFNumberArray.
 operator class UFString & ()
 Downcast UFObject to UFString.
 operator const class UFString & () const
 Downcast const UFObject to const UFString.
 operator class UFGroup & ()
 Downcast UFObject to UFGroup.
 operator const class UFGroup & () const
 Downcast const UFObject to const UFGroup.
 operator class UFArray & ()
 Downcast UFObject to UFArray.
 operator const class UFArray & () const
 Downcast const UFObject to const UFArray.
bool HasParent () const
 Return true if object belongs to a UFGroup.
UFGroupParent () const
 Return the UFGroup the object belongs too.
virtual const char * StringValue () const
 Translate object to a string.
virtual std::string XML (const char *indent="") const
 Create an XML block for the object.
virtual void Message (const char *format,...) const
 Send an informational message in case of an error or warning.
void Throw (const char *format,...) const
 Throw a UFException.
virtual void Set (const UFObject &object)=0
 Set the value of the object to the value of the object parameter.
virtual void Set (const char *string)=0
 Set the value of the object from the string value.
virtual bool IsDefault () const =0
 Return true if object has its default value.
virtual void SetDefault ()=0
 Set the current object value to its default value.
virtual void Reset ()=0
 Reset the object value to its default value.
void SetEventHandle (UFEventHandle *handle)
 Set a C-style event handler.
virtual void Event (UFEventType type)
 Handle any UFEventType event.
virtual void OriginalValueChangedEvent ()
 Handle a uf_value_changed event for the object that originated the change.

Protected Member Functions

 UFObject (_UFObject *object)
 UFObject is an abstract class, therefore it cannot be constructed directly.

Protected Attributes

class _UFObject *const ufobject
 UFObject 's internal implementation is hidden here.

Detailed Description

UFObjects are smart data containers, which are suppose to know everything that is needed to handle and manipulated their content.

UFObject is an abstract class. There are four UFObject implementations:

There are downcasting definitions from all these implementations down to UFObject. These are needed because each UFObject type has different methods. Downcasting eases the access to these methods. An std::bad_cast exception will be thrown if invalid downcasting is attempted.

Each UFObject has a UFName. This name identifies the object and should be unique. It is also used to access UFGroup members.

The C++ interface of UFObject throws an exception is case of failure. Therefore, there is no error indication in the return-value of any of the methods. Most exceptions indicated programming errors and can be avoided. Only in the case of UFObject::Set(const char *string), a UFException could result from a user input error.

The C interface of UFObject is shielded from all exception. Failure will be indicated in the return-value of the calling function and result in a call to UFObject::Message() that sends an error to the console by default. In the case of ufobject_set_string(), UFObject::Message() is not called, since it is assumes that the exception resulted from user input error.

Exceptions:
UFException is the common exception thrown in case of errors.
std::bad_cast is thrown when the downcasting operators fail.

Constructor & Destructor Documentation

virtual UFObject::~UFObject (  )  [virtual]

Trigger a uf_destroyed event and destroy the object.

An object that has a Parent() should never be destroyed directly. It will be destroyed when its parent is destroyed.

UFObject::UFObject ( _UFObject *  object  )  [explicit, protected]

UFObject is an abstract class, therefore it cannot be constructed directly.


Member Function Documentation

UFName UFObject::Name (  )  const

Retrieve the name of the UFObject.

void UFObject::SetUserData ( void *  userData  ) 

Set pointer to general user data.

A uf_user_data_set event is triggered.

void* UFObject::UserData (  ) 

Retrieve pointer to general user data.

UFObject::operator class UFNumber & (  ) 

Downcast UFObject to UFNumber.

UFObject::operator const class UFNumber & (  )  const

Downcast const UFObject to const UFNumber.

UFObject::operator class UFNumberArray & (  ) 

Downcast UFObject to UFNumberArray.

UFObject::operator const class UFNumberArray & (  )  const

Downcast const UFObject to const UFNumberArray.

UFObject::operator class UFString & (  ) 

Downcast UFObject to UFString.

UFObject::operator const class UFString & (  )  const

Downcast const UFObject to const UFString.

UFObject::operator class UFGroup & (  ) 

Downcast UFObject to UFGroup.

UFObject::operator const class UFGroup & (  )  const

Downcast const UFObject to const UFGroup.

UFObject::operator class UFArray & (  ) 

Downcast UFObject to UFArray.

UFObject::operator const class UFArray & (  )  const

Downcast const UFObject to const UFArray.

bool UFObject::HasParent (  )  const

Return true if object belongs to a UFGroup.

UFGroup& UFObject::Parent (  )  const

Return the UFGroup the object belongs too.

A std::logic_error will be thrown if the objects belongs to no group.

Exceptions:
UFException is thrown if the object has no parent. This exception can be avoided with the use of HasParent().
virtual const char* UFObject::StringValue (  )  const [virtual]

Translate object to a string.

UFObject takes care of the memory allocation and freeing of the string.

Reimplemented in UFNumber, UFNumberArray, and UFArray.

virtual std::string UFObject::XML ( const char *  indent = ""  )  const [virtual]

Create an XML block for the object.

If the object value is its default, create and empty XML block.

Parameters:
indent - Controls the XML block indentations.

Reimplemented in UFGroup, and UFArray.

virtual void UFObject::Message ( const char *  format,
  ... 
) const [virtual]

Send an informational message in case of an error or warning.

This method is used internally in the implementation of UFObject. Override this method to implement your own message handling. The default handling is to send the message to the parent object. If no patent exists, send the message to stderr.

Parameters:
format - a printf-like string format.
void UFObject::Throw ( const char *  format,
  ... 
) const

Throw a UFException.

Use this method to throw exceptions from within customized Event() methods.

Parameters:
format - a printf-like string format.
virtual void UFObject::Set ( const UFObject object  )  [pure virtual]

Set the value of the object to the value of the object parameter.

Objects must be of same type and must have the same name. If the value changes, a uf_value_changed event is triggered.

Exceptions:
UFException is thrown if the two objects do not have the same Name(). This is probably a programming error.
virtual void UFObject::Set ( const char *  string  )  [pure virtual]

Set the value of the object from the string value.

This is the reverse of the StringValue() method. If the value changes, an uf_value_changed event is triggered.

Exceptions:
UFException is thrown if the the string can not be converted to the object type. This could result from a user input error.

Implemented in UFNumber, UFNumberArray, UFString, UFGroup, and UFArray.

virtual bool UFObject::IsDefault (  )  const [pure virtual]

Return true if object has its default value.

For numerical objects, the values has to the same up to the prescribed accuracy.

Implemented in UFNumber, UFNumberArray, UFString, UFGroup, and UFArray.

virtual void UFObject::SetDefault (  )  [pure virtual]

Set the current object value to its default value.

A uf_default_changed event is triggered.

Implemented in UFNumber, UFNumberArray, UFString, UFGroup, and UFArray.

virtual void UFObject::Reset (  )  [pure virtual]

Reset the object value to its default value.

If the value changes, a uf_value_changed event is triggered.

Implemented in UFNumber, UFNumberArray, UFString, UFGroup, and UFArray.

void UFObject::SetEventHandle ( UFEventHandle handle  ) 

Set a C-style event handler.

C++ events can be set by overriding the Event() virtual member.

virtual void UFObject::Event ( UFEventType  type  )  [virtual]

Handle any UFEventType event.

Override this method to implement your own event handling. The default handling is to call the event handle set by SetEventHandle() and in the case of uf_value_changed, to call also the parent's Event(). If you override this method, you probably want to call UFObject::Event() from your own implementation of Event().

virtual void UFObject::OriginalValueChangedEvent (  )  [virtual]

Handle a uf_value_changed event for the object that originated the change.

This method should be overridden if one wants to change the values of other objects when the original object value has changed. It is needed to prevent infinite loops where several objects keep changing each other. The default method does not do anything.


Member Data Documentation

class _UFObject* const UFObject::ufobject [protected]

UFObject 's internal implementation is hidden here.


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

Generated on Wed Mar 17 21:05:33 2010 for UFRaw by  doxygen 1.6.1