/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */ /* $Id: cmnClassServicesBase.h,v 1.12 2007/04/26 19:33:57 anton Exp $ Author(s): Anton Deguet Created on: 2004-08-18 (C) Copyright 2004-2007 Johns Hopkins University (JHU), All Rights Reserved. --- begin cisst license - do not edit --- This software is provided "as is" under an open source license, with no warranty. The complete license can be found in license.txt and http://www.cisst.org/cisst/license.txt. --- end cisst license --- */ /*! \file \brief Defines the cmnClassServicesBase */ #ifndef _cmnClassServicesBase_h #define _cmnClassServicesBase_h #include #include #include #include #include /*! \brief Base class for class services \sa cmnClassServices */ class CISST_EXPORT cmnClassServicesBase { public: /*! Type used to define the logging level of detail. */ typedef cmnLogger::LoDType LoDType; /*! Constructor. Sets the name of the class and the Level of Detail setting for the class. \param className The name to be associated with the class. \param typeInfo Runtime type as defined by C++ RTTI \param lod The Log Level of Detail setting to be used with this class. */ cmnClassServicesBase(const std::string & className, const std::type_info * typeInfo, LoDType lod = 5): TypeInfoMember(typeInfo), LoDMember(lod) { NameMember = cmnClassRegister::Register(this, className); } /*! Virtual destructor. Does nothing. */ virtual ~cmnClassServicesBase() {} /*! Create a new empty object of the same type as represented by this object. This can be used whenever an object needs to be dynamically created (e.g. deserialization, object factory). This method uses the C++ "new" operator and the programmers should remember to use a matching "delete" if needed. \return a pointer to the newly created object or null if object cannot be created. */ virtual cmnGenericObject* Create(void) = 0; /*! Get the name associated with the class. \return The name of the class as a string. */ inline const std::string & GetName(void) const { return (*NameMember); } /*! Get the type_info corresponding to the registered class. \return Pointer to the class type_info as defined by C++ RTTI. */ inline const std::type_info * TypeInfoPointer(void) const { return TypeInfoMember; } /*! Get the log Level of Detail associated with the class. This is the level used to filter the log messages. \return The log Level of Detail. */ inline const LoDType & GetLoD(void) const { return LoDMember; } /*! Change the Level of Detail setting for the class. \param newLoD The log Level of Detail setting. */ inline void SetLoD(LoDType newLoD) { LoDMember = newLoD; } private: /*! The name of the class. */ const std::string * NameMember; const std::type_info * TypeInfoMember; /*! The log Level of Detail. */ LoDType LoDMember; }; /*! Class services instantiation. This function is templated by the type of the class to be registered. Its implementation is defined by the macro #CMN_IMPLEMENT_SERVICES or CMN_IMPLEMENT_SERVICES_TEMPLATED. In both case, the function creates the class services (cmnClassServices) and registers it within the class register (cmnClassRegister) based on its std::type_info (see typeid and C++RTTI for more details) to ensure its uniqueness. */ template cmnClassServicesBase * cmnClassServicesInstantiate(void); #endif // _cmnClassServicesBase_h // **************************************************************************** // Change History // **************************************************************************** // // $Log: cmnClassServicesBase.h,v $ // Revision 1.12 2007/04/26 19:33:57 anton // All files in libraries: Applied new license text, separate copyright and // updated dates, added standard header where missing. // // Revision 1.11 2006/11/20 20:33:19 anton // Licensing: Applied new license to cisstCommon, cisstVector, cisstNumerical, // cisstInteractive, cisstImage and cisstOSAbstraction. // // Revision 1.10 2006/11/03 04:28:00 anton // cisstCommon: Major update of Doxygen documentation following changes re. // ticket #234. // // Revision 1.9 2006/10/06 14:29:33 anton // All libraries: Re-ordered #include to include cmnPortability.h before any // other file, including system header files. // // Revision 1.8 2006/05/11 03:33:47 anton // cisstCommon: New implementation of class services and registration to // support templated classes. This code has not been extensively tested and // needs further work. // // Revision 1.7 2006/05/10 18:40:25 anton // cisstCommon class register: Updated to use a std::map to store class services // and added std::type_info to the class services for a more reliable type // identification of templated classes. // // Revision 1.6 2005/09/26 15:41:46 anton // cisst: Added modelines for emacs and vi. // // Revision 1.5 2005/05/19 19:29:00 anton // cisst libs: Added the license to cisstCommon and cisstVector // // Revision 1.4 2004/10/25 13:52:05 anton // Doxygen documentation: Cleanup all the useless \ingroup. // // Revision 1.3 2004/09/03 19:32:03 anton // cisstCommon: Documentation of the new log and class registration system, // see check-in [718] // // Revision 1.2 2004/09/01 21:12:02 anton // cisstCommon: Major update of the class register and the logging system. // The class register is now a singleton (as in "Design Patterns") and doesn't // store any information related to the logging (i.e. global lod, multiplexer // for the output). The data related to the log is now regrouped in the // singleton cmnLogger. This code is still fairly experimental (but tested) // and the documentation is missing. These changes should solve the tickets // #30, #38 and #46. // // Revision 1.1 2004/08/19 21:00:41 anton // cisstCommon: Major update of the class register and class services. This // follows the numerous meetings regarding the registration of classes, the // dynamic creation and the runtime type information. Please see the LaTeX // documents "Base class and base tools". Other minor changes include: // *: Two macros have been introduced, CMN_DECLARE_SERVICES and // CMN_IMPLEMENT_SERVICES. This solves the issue #31. // *: Removed the cumbersome registered/not registered status which was // introduced to allow users to set preferences before the class was // registered. The new design forces the registration before "main()". This // solves the issue #29. // *: LoD is now logLoD which tells a bit more about this Level Of Detail. // *: Test programs have been updated too. // // // ****************************************************************************