<<<<<<<<<<<<<<<<<

class_generator(lymb) LYMB class_generator(lymb)

NAME

class_generator

SUPERCLASS

object

DESCRIPTION

The Class Generator is a LYMB object that generates C code for a class from a user's description. The class generator relieves the user from much of the repetitive work involved in creating a class in C. It allows the intermixing of C code, stored in files, with automatically generated methods.

INSTANCE VARIABLES

MESSAGES

add_methods[+=]arguments adds to or sets the names of instance variables for which add methods will be automatically generated.

append_class_initialize[+=] adds to or sets the class initializers for private instance variables.

append_file=file sets the name of the file that contains C code to be appended to the generated code. This file contains methods that the class generator cannot generate.

append_hdr[+=]arguments adds to or sets the struct components that will be appended to the .hdr file. These represent "private" instance variables, normally invisible to the LYMB script writer.

append_instance_initialize[+=] adds to or sets the initializers for private instance variables.

append_print[+=] adds to or sets the appended print code. This is usually used to reference private instance variables.

boolean_methods[+=] adds to or sets the names instance variable for which boolean methods will be automatically generated.

class_methods[+=]arguments adds to or sets the names of class methods. The Class Generator prefixes each argument with the

object_name to get the method (procedure) name. The arguments are the names of instances of strings. The message corresponding to the method is the value of the string.

directives[+=] adds to or sets the list of C preprocessor directives that will be prepended to the generated .c file.

constants[+=] adds to or sets the list of LYMB scalar or string objects that that will be prepended to the generated .c file as C preprocessor macros.

file_name=file sets the prefix of the name of the file to contain the generated class description. If the file_name is not defined, the name of the Class Generator instance is used. Three files will be generated. file.c contains the C source for the class. file.hdr contains the C source for the class's instance variable data structure. file.def contains the C source for macros for the class.

generate! generates the class. Sends a bunch of other generate_* messages that are not documented here.

get_methods[+=]arguments adds to or sets the names of instance variables for which the class generator will automatically generate get methods.

instance_methods[+=]arguments adds to or sets the names of instance methods. The Class Generator prefixes each argument with the object_name to get the method name. The arguments are the names of instances of strings. The message corresponding to the method is the value of the string.

instance_variables[+=]arguments adds to or sets the names of instance variables.

net_variables[+=]arguments adds to or sets the names of the network variables. Network variables are used to automatically propagate information via the network class. When an instance variable XXX is declared to be a net_variable then whenever the XXX= method is used to set the value, the change will be forwarded to "network_interface" which may be either an instance of network or a collection of network instances.

In order to set a network variable without propagating the change an XXX_locally= method is provided. If net_variables is non-null then a net_new: method is also generated which will cause new instances to be propagated via network_interface.

no_def_file! Suppresses generation of the .def file.

no_hdr_file! Suppresses generation of the .hdr file.

no_macro_file! Synonymous with no_hdr_file!.

no_print_method! Suppresses generation of the print method for the class altogether. This is useful if something out of the ordinary is desired. See the code for the memdbg class for an example of such a use.

no_new_method! Suppresses generation of the new method for the class altogether. This is useful if something out of the ordinary is desired. See the code for the structure class for an example of such a use.

object_name=argument sets the name of the object to be generated.

set_methods[+=]arguments adds to or sets the names of instance variables for which the class generator will automatically generate set methods.

super_object=argument sets the name of the super class of the object being generated. If no super_object is specified, object is assumed.

super_prefix= sets the file prefix for the super class's .def and .hdr files.

EXAMPLE

class_generator new: circle instance_variables=(radius) class_methods=(get_radius) instance_methods=( get_radius, set_radius, add_radius, set_coefficients,

add_coefficients ) get_methods=(radius) object_name=circle super_object="ellipse" append_file="circle.cls" ;

/* Circle's instance variables */ scalar new: radius = 1; vector coefficients dimension= 6;

/* Circle's methods */ string new: set_radius = "radius="; string new: get_radius = "radius?"; string new: add_radius = "radius+"; string new: set_coefficients = "coefficients="; string new: add_coefficients = "coefficients+"; circle generate!;

For more detailed examples see the class generator scripts in the LYMB source directory.

SEE ALSO

object(lymb), parser(lymb), collection(lymb), memdbg(lymb)


Please send comments and suggestions to
consult@rpi.edu