Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

UBrick Class Reference

Ubit Brick: base class for objects that can be added to the instance graph (abstract class). More...

#include <ubrick.hpp>

Inheritance diagram for UBrick:

UElem UFloat UGenCallImpl UInput UIntg UMode UProp UTimer List of all members.

Public Member Functions

 UBrick (u_modes b_modes=0)
 standard constructor; see class UBrick and UBrick::~UBrick.
virtual ~UBrick ()
 see important notes on recursive deletion
virtual const char * getClassName () const
 returns the name of the class of this object.
void setAutoUpdate (bool)
 specifies whether update() is invoked when set(), add() or remove() are called.
bool isAutoUpdate () const
virtual int getParentCount () const
 returns the number of parents.
virtual UGroup ** getParents () const
virtual UGroup ** getParents (int &parent_count) const
 returns a copy of the object's parent list.
virtual int getParents (std::vector< UGroup * > &parent_vect) const
 returns a copy of the object's parent list (and the parent count).
virtual UGroupgetParent (int pos) const
 returns the nth parent.
virtual bool isChildOf (class UGroup *possible_parent, bool indirect) const
 is this object a child of 'possible_parent'?.
virtual void removeFromParents (bool update_parents=true)
 removes the brick from all parents.
bool isBmode (u_modes some_Bmodes) const
 [impl] is ONE of these Brick modes verified ? (see class UMode for details).
u_modes getBmodes () const
 [impl] returns current Brick mode bitmask.
void setBmodes (u_modes bmodes, bool on_off)
 [impl] sets Brick modes to ON (resp OFF) if last arg is true (resp false).
void * operator new (size_t)
void operator delete (void *)
void addRef ()
void removeRef ()
u_count getRefCount () const
 [impl] implementation: memory management.
virtual void fire (class UEvent &, const class UOn &) const
 [impl] calls callback functions.
virtual class UProppropCast ()
virtual class UElemelemCast ()
virtual class UStrstrCast ()
virtual class UGroupgroupCast ()
virtual class UBoxboxCast ()
virtual class UWinwinCast ()
virtual class UGroupgetSubGroup ()
 [impl] implementation: simulates dynamic cast.
virtual void addingTo (class ULink *selflink, class UGroup *parent)
virtual void removingFrom (class ULink *selflink, class UGroup *parent)
virtual void destructs ()
 [impl] see important note on subclassing.

Static Public Member Functions

static const char * getUbitVersion ()
 returns the version of the Ubit package.
template<class CC>
static bool isInstance (const UBrick *_obj)
 is 'obj' an instance of 'CC'
static void error (const char *id, const char *msg)
static void error (const char *id, const char *msg, long arg)
static void error (const char *id, const char *msg, const char *arg)
static void error (const char *id, const char *msg, const UStr &arg)

Friends

class ULink & operator/ (const UCond &, UBrick &)
class ULink & operator/ (const UCond &, UBrick *)
 conditional operator (for callback functions and conditionnal objects).

Detailed Description

Ubit Brick: base class for objects that can be added to the instance graph (abstract class).

IMPORTANT NOTES:

1. When an object is destroyed, its direct and indirect children are also destroyed except if:

2. C++ pointers and references are unsafe and should only be used for temporary variables. Ubit provides "smart pointers" that manage memory in a simple and safe way (see template uptr<>).

Objects pointed by smart pointers:

Hence, these objects pointed are automatically destroyed when needed:

     uptr<UBox> box = new UBox();
     uptr<UButton> btn = ubutton("my button");
     box->add(*btn);
     btn = null;    // 'btn' does not point any longer to the UButton
     box = null;    // destroys the UBox and its UButton child
                    // if they do no have other parents and are not
                    // pointed by other smart pointers
   

3. Alternatively, C++ variables can also be "plain objects" instead of pointers. Objects created in this way are destroyed automatically. Note that:

  void foo() {
     UStr str ="abcde";
  }  // the UStr is destroyed
  

4. The = operator copies the content of C++ objects. UBrick and most of its subclasses forbid this operator (the set() method must be used instead)

See also: UBrick::~UBrick and uptr<>


Constructor & Destructor Documentation

UBrick::UBrick u_modes  b_modes = 0  ) 
 

standard constructor; see class UBrick and UBrick::~UBrick.

argument 'b_mode' is used internally and should not be set by clients.

virtual UBrick::~UBrick  )  [virtual]
 

see important notes on recursive deletion

All destructors destroys the children and descendants of the object being deleted if:

  • they do not have other (undeleted) parents, and
  • they are not referenced by an uptr (Ubit smart pointer), and
  • they have been created in the heap (ie. by using the 'new' primivite or a 'creator shortcut' such as ugroup())

Advices:

  • avoid using the delete primivite and prefer the UGroup::remove() or UGroup::removeAll() functions

  • 'delete' does not update graphics and may produce unexpected results or generate errors because objects:
    1. can be shared (= they can have several parents)
    2. can be created in the static memory or in the stack
    3. can be referenced by uptr's (Ubit smart pointers) deleting objects is illegal in the two later cases and will generate an error or an exception.


Member Function Documentation

void UBrick::addingTo class ULink *  selflink,
class UGroup parent
[virtual]
 

... inutile pour les UCONST!!!;

Reimplemented in UMode, UPos, and UViewStyle.

void UBrick::destructs  )  [virtual]
 

[impl] see important note on subclassing.

destructs() unlinks the object from its parents and destroys children (when applicable). Any class that redefines removingFrom() MUST HAVE A DESTRUCTOR that calls destructs().

UGroup * UBrick::getParent int  pos  )  const [virtual]
 

returns the nth parent.

args:

  • 'pos' = 0 means "first parent" and 'pos' = -1 means "last parent"
  • returns null and issues a warning message if 'pos' is out of range notes:
  • remember that bricks can have several parents!
  • use getParents() is you need to access several parents: this will be more efficient than multiple calls to getParent()

int UBrick::getParents std::vector< UGroup * > &  parent_vect  )  const [virtual]
 

returns a copy of the object's parent list (and the parent count).

args:

  • 'parent_vect' will contain a copy of the parent list. note that this vector is not cleared: parents are appended to its current elements if it is not empty.
  • return value: the number of parents. notes:
  • remember that bricks can have several parents!

UGroup ** UBrick::getParents int &  parent_count  )  const [virtual]
 

returns a copy of the object's parent list.

args:

  • returns null if the object has no parent and a copy of the parent list otherwise.
  • the returned list must be destroyed by using: delete[] notes:
  • remember that bricks can have several parents!

bool UBrick::isChildOf class UGroup possible_parent,
bool  indirect
const [virtual]
 

is this object a child of 'possible_parent'?.

args:

  • second argument specifies if we accept indirect childhood (indirect' is true) or if we just consider direct children ('indirect' is false)

void UBrick::removeFromParents bool  update_parents = true  )  [virtual]
 

removes the brick from all parents.

notes: 1) Ubit objects can have several parents! 2) this function is potentially dangerous: the UGroup::remove() and UGroup::removeAll() methods should be prefered when possible.

void UBrick::removingFrom class ULink *  selflink,
class UGroup parent
[virtual]
 

... inutile pour les UCONST!!!;

Reimplemented in UMode, UPos, and UViewStyle.


Friends And Related Function Documentation

class ULink& operator/ const UCond cond,
UBrick b
[friend]
 

conditional operator (for callback functions and conditionnal objects).

this operator is used for specifying call-back functions or conditionnal objects (see classes UCall, UOn and UFlag).


The documentation for this class was generated from the following files:
Generated on Fri Jun 3 03:30:15 2005 for Ubit[Eric.Lecolinet@enst.fr] by  doxygen 1.4.2