Creating ooc classes by typing from scratch may be labor-intensive, error prone, but mostly boring. Fortunatley ooc has a tool that helps you create classes from templates, or from other classes that are already implemented. This tool is suprisingly called ooc and is used as follows. Type at the prompt:
~$ ooc --new MyClass
This instruction creates a class called MyClass from the default ooc template, and puts it into the current working directory. Using the default template the following files will be created in the current working directory:
This is the MyClass header containing the declaration of MyClass class plus its virtual functions. These are the publicly available declarations for MyClass, this class is to be included by the users of the class. Extend this file with your method declarations as needed.
This is the class implementation file. It contains the class allocation, constructor, descructor etc. skeletons. You must extend this file with your method definitions, and other code.
This is the implementation header. This cointains the declaration of class data members, that are publicly not available. This file must be included by the subclasses of MyClass. (If you create your classes with the ooc tool with --from or --source switches then these includes are handled automatically.)
As you have created your class using the ooc tool, check the created skeletons, and modify them as needed. The created class can not be compiled without some modifications, and this is intentional: this forces you to set the construction parameters properly for example.
The following switches can be used with ooc. The switches can be combined!
Prints the version information and a short help message.
Creates a new class named as ClassName.
Creates a testsuite from the current directory. (Copies all makefiles and testsuite script/batch, that is required for unit testing.)
Modifiers for the ooc --new ClassName command:
The created class is created as a subclass for ParentClassName. If
--parent switch is missing, then
Base will be used as parent class.
Uses SampleClassName as a template. If
--from switch is missing, then the default
SampleClass template is used.
--source switch is not defined then the template class is searched for in the files called
implement/sampleclassname.h in the default template directory (usually
implement/filename.h files as the template file.
filename is a simple filename (not absolute path) then it is located in the standard template directory (usually
--from switch is not defined then the default
SampleClass is looked for as a template in
Puts the results into
implement/filename.h files in the current working directory. (Depending on the template used, some files may not be used.)
Does not overwrite the files, appends the new content to the end of the files.
The next example creates a Foo class with header and implementation files, and adds FooException to the files as an additional class.
~$ ooc --new Foo --parent Bar ~$ ooc --new FooException --parent Exception --template private --target foo
You will have
implement/foo.h files with class definitions and implementations for
The following templates are available:
The default template. This generates a class with ’protected’ data members and implementation header. This class can be subclassed. (This is the default if you do not specify a --template or --source.)
Class definition with private members only. This type of class can not be subclassed! (there is no implementation header)
A minimal class definition, only with a class implementation file (no headers). Use this for internal classes within a class.
Mixin declaration and implementation files.
Unit testing base class template.