Top Up Prev Next Bottom Contents Index Search

1.8 Class NamedObj

NamedObj is the base class for most of the common Ptolemy objects. A NamedObj is, simply put, a named object; in addition to a name, a NamedObj has a pointer to a parent object, which is always a Block (a type of NamedObj). This pointer can be null. A NamedObj also has a descriptor. Warning! NamedObj assumes that the name and descriptor "live" as long as the NamedObj does. They are not deleted by the destructor, so that they can be compile-time strings. Important derived types of NamedObj include Block (see section 3.1), GenericPort (see section 6.1), State (see section 9.1), and Geodesic (see section 6.6).

1.8.1 NamedObj constructors and destructors

All constructors and destructors are public. NamedObj has a default constructor, which sets the name and descriptor to empty strings and the parent pointer to null, and a three-argument constructor:

NamedObj(const char* name,Block* parent, const char* descriptor) 
NamedObj's destructor is virtual and does nothing.

1.8.2 NamedObj public members

virtual const char* className() const; 
Return the name of the class. This needs to have a new implementation supplied for every derived class (except for abstract classes, where this is not necessary).

const char* name() const; 
Return the local portion of the name of the class (vs. the full name).

const char* descriptor() const; 
Return the descriptor.

Block* parent() const; 
Return a pointer to the parent block.

virtual StringList fullName() const; 
Return the full name of the object. This has no relation to the class name; it specifies the specific instance's place in the universe-galaxy-star hierarchy. The default implementation returns names that might look like for a porthole; this is the full name of the parent, with a period and the name of the object appended.

void setName(const char* name); 
Set the name of the object. The string must live at least as long as the object.

void setParent(Block* parent); 
Set the parent of the object, which is always a Block. The parent must live at least as long as the object.

void setNameParent (const char* my_name, Block* my_parent) 
Change the name and parent pointer of the object.

virtual void initialize() = 0; 
Initialize the object to prepare for system execution. This is a pure virtual method.

virtual StringList print (int verbose) const; 
Return a description of the object. If the argument verbose is 0, a somewhat more compact form is printed than if the argument is non-zero.

virtual int isA(const char* cname) const; 
Return TRUE if the argument is the name of the class or of one of its base classes. This method needs to be redefined for all classed derived from NamedObj. To make this easy to do, a macro ISA_FUNC is provided; for example, in the file we see the line


NamedObj is the base class from which Block is derived. This macro creates the function definition

int Block::isA(const char* cname) const { 
if (strcmp(cname,"Block") == 0) return TRUE;
else return NamedObj::isA(cname);
Methods isA and className are overridden in all derived classes; the redefinitions will not be described for each individual class.

1.8.3 Flags on named objects

FlagArray flags 
Many schedulers and targets need to be able to mark blocks in various ways, to count invocations, or flag that the block has been visited, or to classify it as a particular type of block. To support this, we provide an array of flags that are not used by class Block, and may be used in any way by a Target. The target may defer their use to its schedulers. The array can be of any size, and the size will be increased automatically as elements are referenced. For readability and consistency, the user should define an enum in the target or scheduler class to give the indices, so that mnemonic names can be associated with flags, and so that multiple schedulers for the same target are consistent. For instance, if b is a pointer to a Block, a target might contain the following:

enum {
visited = 0,
fired = 1
which can then be used in code to set and read flags in a readable way,

   b->flags[visited] = TRUE;
   if (b->flags[visited]) { ... }
WARNING: For efficiency, there is no checking to prevent two different pieces of code (say a target and scheduler) from using the same flags (which are indexed only by non-negative integers) for different purposes. The policy, therefore, is that the target is in charge. It is incumbent upon the writer of the target to know what flags are used by schedulers invoked by that target, and to avoid corrupting those flags if the scheduler needs them preserved. We weighed a more modular, more robust solution, but ruled in out in favor of something very lightweight and fast.

1.8.4 NamedObj protected members

void setDescriptor(const char* desc); 
Set the descriptor to desc. The string pointed to by desc must live as long as the NamedObj does.

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.