Example 5-2 exercises various C++ features including the Standard Template Library, user defined templates, Run-Time Type Identification, and exception handling. To try it out, create a project containing factory.cpp and factory.h and build and download linkedObjs.o. At the shell type:
-> testFactory
Full documentation on what you should except to see is given in the source code.
/* factory.cpp - implements an object factory */ /* Copyright 1993-1998 Wind River Systems, Inc. */ /* modification history -------------------- 01a,05oct98,sn wrote */ /* DESCRIPTION We implement an "object factory". The first step is to give classes human-readable names by registering them with a "global class registry". Then objects of a named type may be created and registered with an "object registry".
/* factory.h - class declarations for the object factory */ /* Copyright 1993-1998 Wind River Systems, Inc. */ /* modification history -------------------- 01a,05oct98,sn wrote */ #include <vxWorks.h> #include <iostream.h> #include <string> #include <typeinfo> #include <map> /* * object_t hierarchy * * object_t * | * +------------+------------+ * | | | * red_t blue_t green_t * */ struct object_t { virtual void method () {} }; struct red_t : object_t { }; struct blue_t : object_t { }; struct green_t : object_t { };