CodeStream myCode;These are protected members of class CGTarget. They are the default entries in
codeStringLists, the list of code streams that CGTarget maintains.
CodeStreamList codeStringLists;This is a protected member of class CGTarget. We can add a CodeStream to
codeStringListsby using the following method of class CGTarget:
void addStream(const char* name, CodeStream* code);This is a public method of class CGTarget. The first argument is the name of the CodeStream, and the second argument is a pointer to the CodeStream. This method should be called in the constructor of a target class. If a target attempts to add a CodeStream with an existing name, an error will be signaled.
CodeStream* getStream(const char* name=NULL);This is a public method of class CGTarget. This method returns a pointer to the CodeStream with the given name. If no stream with the given name is found, this method returns
=NULL, a pointer to
defaultStreamis returned. Class CGStar has a corresponding method to get the CodeStream with the given name from the CGStar's target.
The following method allows CGStars to construct a new CodeStream and add it to the CGTarget's list of CodeStreams. Some of the possible uses for this method are:
CodeStream* newStream(const char* name);This is a public method of class CGTarget. There is a corresponding protected method of CGStar. This method adds a new CodeStream with the given name to the
codeStringListsmember of the CGTarget, and returns a pointer to the new CodeStream.
Now we will explain the public methods and members of class CodeStream.
int put(const char* code, const char* name=NULL);This method puts the given segment of code at the end of the CodeStream. Optionally, the name of the code segment can be given. If
=NULL,we append the code unconditionally. Otherwise, we check to see if code with the same name has already ben added, by examining the
sharedNamesmember of the CodeStream. If no code segment with the same name is found, the code segment is appended. This method returns
TRUEif code was successfully added to the stream,
UniqueStringList sharedNames;This is a public member of class CodeStream. It is used to store the names of code segments added by name to the CodeStream. Class UniqueStringList is privately derived from class StringList.
void initialize();This is a public method of class CodeStream. It is used to initialize both the code list and
int isUnique(const char* name);This is a public method of class UniqueStringList. This method returns
FALSEif the argument string already exists in the UniqueStringList. If not, then the method adds the string to the list and returns
Class CodeStreamList contains a list of CodeStreams. It is publicly derived from class NamedList since each CodeStream is assigned a name. There are four public methods in the CodeStreamList class:
int append(CodeStream* stream, const char* name);The first two methods append a CodeStream to the list. They differ from each other in the order of arguments. The third method returns a CodeStream with the given name while the last method removes the CodeStream with the given name from the list.
int add(const char* name, CodeStream* stream);
CodeStream* get(const char* name) const;
int remove(const char* name);
int append(Pointer object, const char* name);These methods put an object,
void prepend(Pointer object, const char* name);
object, with name
nameat the end and the beginning of the list, respectively. In the first method, we may not append multiple objects with the same name. If an object with the same name exists in the list,
FALSEis returned. On the other hand, the second method allows multiple objects with the same name to be prepended. Only the most recently prepended object will be visible.
Pointer get(const char* name=NULL);This method returns the object with the given name. If no name is given, it returns the object at the head of the list. If no object is found, it returns
int remove(const char* name=NULL);This method removes the object with the given name. If no name is given, it removes the first object at the head of the list. If no object is found it returns
FALSE, otherwise it returns
There is an iterator class associated with the NamedList class, called NamedListIter. It returns a pointer to the next object in the list as it iterates through the list.