From e32a20b23f2d8ae53821d80ae1dcfcc64909e632 Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 4 Oct 2008 15:44:15 +0000 Subject: [PATCH] * ./hurricane/src/hurricane/Name.h ./hurricane/src/hurricane/Name.cpp : - New feature : Allocate a static member "_emptyName" which could be used to manage effeciently empty Name (for functions returning reference on Name, by example). * ./hurricane/src/hurricane/Property.h ./hurricane/src/hurricane/Property.cpp : - Change : Now StandardPrivateProperty & StandardSharedProperty templates systematically uses static member for the property's name. This leads to suppress the "const Name&" argument when creating a property, and the _name member is no longer present in each object instance. - Change : Property must now be created/get through static methods : StandardPrivateProperty::get ( DBo* ); StandardPrivateProperty::create ( DBo* ); StandardPrivateProperty::create ( DBo*, const Value& ); Note that, as before, the Value type must provide a default constructor and a copy constructor. * ./hurricane/src/hviewer/DisplayStyle.cpp : Bug : early Graphics::enable() no longer makes application crash. --- hurricane/src/hurricane/DBo.cpp | 250 +++--- hurricane/src/hurricane/Error.cpp | 12 +- hurricane/src/hurricane/Name.cpp | 4 + hurricane/src/hurricane/Property.cpp | 249 +++--- hurricane/src/hurricane/Warning.cpp | 133 +++- hurricane/src/hurricane/hurricane/Commons.h | 91 ++- hurricane/src/hurricane/hurricane/DBo.h | 154 ++-- hurricane/src/hurricane/hurricane/Error.h | 6 + hurricane/src/hurricane/hurricane/Name.h | 3 + hurricane/src/hurricane/hurricane/Property.h | 784 ++++++++++--------- hurricane/src/hurricane/hurricane/Warning.h | 107 +-- hurricane/src/hviewer/DisplayStyle.cpp | 7 +- hurricane/src/hviewer/Graphics.cpp | 9 +- 13 files changed, 995 insertions(+), 814 deletions(-) diff --git a/hurricane/src/hurricane/DBo.cpp b/hurricane/src/hurricane/DBo.cpp index 66eb7d55..959c38df 100644 --- a/hurricane/src/hurricane/DBo.cpp +++ b/hurricane/src/hurricane/DBo.cpp @@ -1,166 +1,166 @@ -// **************************************************************************************************** -// File: DBo.cpp -// Authors: R. Escassut -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** + +// -*- C++ -*- +// +// This file is part of the Hurricane Software. +// Copyright (c) UPMC/LIP6 2008-2008, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Jean-Paul Chaput | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Module : "./DBo.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + #include "hurricane/DBo.h" #include "hurricane/Property.h" #include "hurricane/Quark.h" #include "hurricane/Error.h" + namespace Hurricane { +// ------------------------------------------------------------------- +// Class : "Hurricane::DBo". -// **************************************************************************************************** -// DBo implementation -// **************************************************************************************************** -DBo::DBo() -// ******* -: _propertySet() -{ -} + DBo::DBo (): _propertySet() + { } -DBo::~DBo() -// ******** -{ -} -void DBo::destroy() -// *************** -{ -// trace << "entering DBo::destroy: " << this << endl; -// trace_in(); + DBo::~DBo () + { } + + void DBo::_postCreate () + { } + + + void DBo::_preDestroy () + { + clearProperties (); + } + + + void DBo::destroy () + { _preDestroy(); - + delete this; + } -// trace << "exiting DBo::destroy:" << endl; -// trace_out(); -} -Property* DBo::getProperty(const Name& name) const -// *********************************************** -{ + Property* DBo::getProperty ( const Name& name ) const + { PropertySet::const_iterator iterator = _propertySet.begin(); - while (iterator != _propertySet.end()) { - Property* property = *iterator; - if (property->getName() == name) return property; - ++iterator; + while ( iterator != _propertySet.end() ) { + Property* property = *iterator; + if (property->getName() == name) return property; + ++iterator; } return NULL; -} + } -void DBo::put(Property* property) -// ****************************** -{ - if (!property) - throw Error("Can't put property : null property"); - Property* oldProperty = getProperty(property->getName()); - if (property != oldProperty) { - if (oldProperty) { - _propertySet.erase(oldProperty); - oldProperty->onReleasedBy(this); - } - _propertySet.insert(property); - property->onCapturedBy(this); + Properties DBo::getProperties () const + { + return getCollection(_propertySet); + } + + + void DBo::put ( Property* property ) + { + if ( !property ) + throw Error("DBo::put(): Can't put property : NULL property."); + + Property* oldProperty = getProperty ( property->getName() ); + if ( property != oldProperty ) { + if ( oldProperty ) { + _propertySet.erase ( oldProperty ); + oldProperty->onReleasedBy ( this ); + } + _propertySet.insert ( property ); + property->onCapturedBy ( this ); } -} + } -void DBo::remove(Property* property) -// ********************************* -{ - if (!property) - throw Error("Can't remove property : null property"); - if (_propertySet.find(property) != _propertySet.end()) { - _propertySet.erase(property); - property->onReleasedBy(this); - if (dynamic_cast(this) && _propertySet.empty()) destroy(); + void DBo::remove ( Property* property ) + { + if ( !property ) + throw Error("DBo::remove(): Can't remove property : NULL property."); + + if ( _propertySet.find(property) != _propertySet.end() ) { + _propertySet.erase ( property ); + property->onReleasedBy ( this ); + if ( dynamic_cast(this) && _propertySet.empty() ) + destroy(); } -} + } -void DBo::removeProperty(const Name& name) -// *************************************** -{ - Property* property = getProperty(name); - if (property) { - _propertySet.erase(property); - property->onReleasedBy(this); - if (dynamic_cast(this) && _propertySet.empty()) destroy(); + + void DBo::removeProperty ( const Name& name ) + { + Property* property = getProperty ( name ); + if ( property ) { + _propertySet.erase ( property ); + property->onReleasedBy ( this ); + if ( dynamic_cast(this) && _propertySet.empty() ) + destroy(); } -} + } -void DBo::clearProperties() -// ************************ -{ -// trace << "entering DBo::ClearProperties: " << this << endl; -// trace_in(); - while (!_propertySet.empty()) { - Property* property = *_propertySet.begin(); -// trace << property << endl; - _propertySet.erase(property); - property->onReleasedBy(this); + void DBo::_onDestroyed ( Property* property ) + { + if ( property && ( _propertySet.find(property) != _propertySet.end() ) ) { + _propertySet.erase ( property ); + if ( dynamic_cast(this) && _propertySet.empty() ) + destroy(); } - -// trace << "exiting DBo::ClearProperties:" << endl; -// trace_out(); -} - -void DBo::_postCreate() -// ******************** -{ -} - -void DBo::_preDestroy() -// ******************* -{ -// trace << "entering DBo::_Predestroy: " << this << endl; -// trace_in(); - - clearProperties(); + } -// trace << "exiting DBo::_Predestroy:" << endl; -// trace_out(); -} + void DBo::clearProperties () + { + while ( !_propertySet.empty() ) { + Property* property = *_propertySet.begin(); + _propertySet.erase ( property ); + property->onReleasedBy ( this ); + } + } -string DBo::_getTypeName () const -// ****************************** -{ - return "DBo"; -} -string DBo::_getString() const -// *************************** -{ + string DBo::_getTypeName () const + { + return "DBo"; + } + + + string DBo::_getString () const + { return "<" + _getTypeName() + ">"; -} + } -Record* DBo::_getRecord() const -// ********************** -{ - Record* record = new Record(getString(this)); - record->add(getSlot("Properties", &_propertySet)); - return record; -} -void DBo::_onDestroyed(Property* property) -// ************************************* -{ - if (property && (_propertySet.find(property) != _propertySet.end())) { - _propertySet.erase(property); - if (dynamic_cast(this) && _propertySet.empty()) destroy(); - } -} + Record* DBo::_getRecord () const + { + Record* record = new Record ( getString(this) ); + record->add ( getSlot("Properties", &_propertySet) ); + return record; + } + } // End of Hurricane namespace. - -// **************************************************************************************************** -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** diff --git a/hurricane/src/hurricane/Error.cpp b/hurricane/src/hurricane/Error.cpp index 82b1cea1..4eeb307d 100644 --- a/hurricane/src/hurricane/Error.cpp +++ b/hurricane/src/hurricane/Error.cpp @@ -39,21 +39,19 @@ namespace Hurricane { : Exception() , _reason(reason) , _code(0) - { - } + { } Error::Error ( int code, const string& reason ) : Exception() , _reason(reason) , _code(code) - { - } + { } Error::Error ( const char* format, ... ) : Exception() - , _reason("") + , _reason() , _code(0) { static char formatted [ 8192 ]; @@ -69,7 +67,7 @@ namespace Hurricane { Error::Error ( int code, const char* format, ... ) : Exception() - , _reason("") + , _reason() , _code(code) { static char formatted [ 8192 ]; @@ -95,7 +93,7 @@ namespace Hurricane { { return _TName("Error"); } - string Error::_getString() const + string Error::_getString () const { if ( !_code ) return "[ERROR] " + _reason; diff --git a/hurricane/src/hurricane/Name.cpp b/hurricane/src/hurricane/Name.cpp index 26e05f3b..5fc5e95b 100644 --- a/hurricane/src/hurricane/Name.cpp +++ b/hurricane/src/hurricane/Name.cpp @@ -15,6 +15,10 @@ namespace Hurricane { // Name implementation // **************************************************************************************************** + + const Name Name::_emptyName; + + Name::Name() // ********* : _sharedName(NULL) diff --git a/hurricane/src/hurricane/Property.cpp b/hurricane/src/hurricane/Property.cpp index af38d041..52fba60c 100644 --- a/hurricane/src/hurricane/Property.cpp +++ b/hurricane/src/hurricane/Property.cpp @@ -1,173 +1,192 @@ -// **************************************************************************************************** -// File: Property.cpp -// Authors: R. Escassut -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** -#include "hurricane/Property.h" -#include "hurricane/DBo.h" -#include "hurricane/Error.h" +// -*- C++ -*- +// +// This file is part of the Hurricane Software. +// Copyright (c) UPMC/LIP6 2008-2008, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Jean-Paul Chaput | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Module : "./Property.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#include "hurricane/Property.h" +#include "hurricane/DBo.h" +#include "hurricane/Error.h" + namespace Hurricane { +// Error messages. + const char* propertyTypeNameError = + "Property<%s>::get():\n Discrepency between type and property name on %s.\n"; -// **************************************************************************************************** -// Property implementation -// **************************************************************************************************** -Property::Property() -// ***************** -{ -} +// ------------------------------------------------------------------- +// Class : "Hurricane::Property". -Property::~Property() -// ****************** -{ -} -void Property::destroy() -// ******************** -{ + Name Property::_baseName = "Property"; + + + Name Property::staticGetName () + { + return _baseName; + } + + + Property::Property () + { } + + + Property::~Property () + { } + + + void Property::destroy () + { _preDestroy(); delete this; -} + } -string Property::_getString() const -// ******************************** -{ + + string Property::_getString () const + { string s = "<" + _getTypeName() + ">"; s.insert(s.length() - 1, " " + getString(getName())); return s; -} + } -Record* Property::_getRecord() const -// *************************** -{ + + Record* Property::_getRecord () const + { return new Record(getString(this)); -} + } +// ------------------------------------------------------------------- +// Class : "Hurricane::PrivateProperty". -// **************************************************************************************************** -// PrivateProperty implementation -// **************************************************************************************************** -PrivateProperty::PrivateProperty() -// ******************************* -: Inherit(), - _owner(NULL) -{ -} + PrivateProperty::PrivateProperty () + : Property() + , _owner(NULL) + { } -void PrivateProperty::_preDestroy() -// ******************************* -{ - Inherit::_preDestroy(); - if (_owner) _owner->_onDestroyed(this); -} + void PrivateProperty::_preDestroy () + { + Property::_preDestroy(); -void PrivateProperty::onCapturedBy(DBo* owner) -// ******************************************* -{ + if ( _owner ) _owner->_onDestroyed(this); + } + + + void PrivateProperty::onCapturedBy ( DBo* owner ) + { _owner = owner; -} + } -void PrivateProperty::onReleasedBy(DBo* owner) -// ******************************************* -{ - if (_owner == owner) onNotOwned(); -} -void PrivateProperty::onNotOwned() -// ******************************* -{ + void PrivateProperty::onReleasedBy ( DBo* owner ) + { + if ( _owner == owner ) onNotOwned(); + } + + + void PrivateProperty::onNotOwned () + { destroy(); -} + } -string PrivateProperty::_getString() const -// *************************************** -{ - return Inherit::_getString(); -} -Record* PrivateProperty::_getRecord() const -// ********************************** -{ - Record* record = Inherit::_getRecord(); + string PrivateProperty::_getString () const + { + return Property::_getString (); + } + + + Record* PrivateProperty::_getRecord () const + { + Record* record = Property::_getRecord(); if (record) { - record->add(getSlot("Owner", _owner)); + record->add(getSlot("Owner", _owner)); } return record; -} + } +// ------------------------------------------------------------------- +// Class : "Hurricane::SharedProperty". -// **************************************************************************************************** -// SharedProperty implementation -// **************************************************************************************************** -SharedProperty::SharedProperty() -// ***************************** -: Inherit(), - _ownerSet() -{ -} + SharedProperty::SharedProperty () + : Property() + , _ownerSet() + { } -void SharedProperty::_preDestroy() -// ****************************** -{ - Inherit::_preDestroy(); + + void SharedProperty::_preDestroy () + { + Property::_preDestroy(); while (!_ownerSet.empty()) { - DBo* owner = *_ownerSet.begin(); - _ownerSet.erase(owner); - owner->_onDestroyed(this); + DBo* owner = *_ownerSet.begin(); + _ownerSet.erase(owner); + owner->_onDestroyed(this); } -} + } -void SharedProperty::onCapturedBy(DBo* owner) -// ****************************************** -{ + + void SharedProperty::onCapturedBy ( DBo* owner ) + { _ownerSet.insert(owner); -} + } -void SharedProperty::onReleasedBy(DBo* owner) -// ****************************************** -{ + + void SharedProperty::onReleasedBy ( DBo* owner ) + { _ownerSet.erase(owner); if (_ownerSet.empty()) onNotOwned(); -} + } -void SharedProperty::onNotOwned() -// ****************************** -{ + + void SharedProperty::onNotOwned () + { destroy(); -} + } -string SharedProperty::_getString() const -// ************************************** -{ - return Inherit::_getString(); -} -Record* SharedProperty::_getRecord() const -// ********************************* -{ - Record* record = Inherit::_getRecord(); + string SharedProperty::_getString () const + { + return Property::_getString (); + } + + + Record* SharedProperty::_getRecord () const + { + Record* record = Property::_getRecord(); if (record) { - record->add(getSlot("Owners", &_ownerSet)); + record->add(getSlot("Owners", &_ownerSet)); } return record; -} - + } } // End of Hurricane namespace. - -// **************************************************************************************************** -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** diff --git a/hurricane/src/hurricane/Warning.cpp b/hurricane/src/hurricane/Warning.cpp index 1a30bba3..e9127be6 100644 --- a/hurricane/src/hurricane/Warning.cpp +++ b/hurricane/src/hurricane/Warning.cpp @@ -1,55 +1,112 @@ -// **************************************************************************************************** -// File: Warning.cpp -// Authors: R. Escassut -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** -#include "hurricane/Warning.h" +// -*- C++ -*- +// +// This file is part of the Hurricane Software. +// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Remy Escassut | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Module : "./Warning.cpp" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +# include + +# include "hurricane/Warning.h" + namespace Hurricane { +// ------------------------------------------------------------------- +// Class : "Hurricane::Warning". -// **************************************************************************************************** -// Warning implementation -// **************************************************************************************************** -Warning::Warning(const string& reason, int code) -// ********************************************* -: Inherit(), - _reason(reason), - _code(code) -{ -} + Warning::Warning ( const string& reason ) + : Exception() + , _reason(reason) + , _code(0) + { } -Warning::Warning(const Warning& warning) -// ************************************* -: Inherit(), - _reason(warning._reason), - _code(warning._code) -{ -} -Warning& Warning::operator=(const Warning& warning) -// ************************************************ -{ + Warning::Warning ( int code, const string& reason ) + : Exception() + , _reason(reason) + , _code(code) + { } + + + Warning::Warning ( const char* format, ... ) + : Exception() + , _reason() + , _code(0) + { + static char formatted [ 8192 ]; + va_list args; + + va_start ( args, format ); + vsnprintf ( formatted, 8191, format, args ); + va_end ( args ); + + _reason = formatted; + } + + + Warning::Warning ( int code, const char* format, ... ) + : Exception() + , _reason() + , _code(code) + { + static char formatted [ 8192 ]; + va_list args; + + va_start ( args, format ); + vsnprintf ( formatted, 8191, format, args ); + va_end ( args ); + + _reason = formatted; + } + + + Warning::Warning ( const Warning& warning ) + : Exception() + , _reason(warning._reason) + , _code(warning._code) + { } + + + Warning& Warning::operator= ( const Warning& warning ) + { _reason = warning._reason; - _code = warning._code; + _code = warning._code; return *this; -} + } -string Warning::_getString() const -// ******************************* -{ - if (!_code) return "[WARNING] " + _reason; + + string Warning::_getTypeName () const + { return _TName("Warning"); } + + + string Warning::_getString () const + { + if (!_code) + return "[WARNING] " + _reason; return "[WARNING:" + getString(_code) + "] " + _reason; -} - + } } // End of Hurricane namespace. - -// **************************************************************************************************** -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** diff --git a/hurricane/src/hurricane/hurricane/Commons.h b/hurricane/src/hurricane/hurricane/Commons.h index e0ff1178..245d26b7 100644 --- a/hurricane/src/hurricane/hurricane/Commons.h +++ b/hurricane/src/hurricane/hurricane/Commons.h @@ -129,7 +129,7 @@ template inline Hurricane::Slot* getSlot ( const std::string& nam // Default match. template inline std::string getString ( Data data ) -{ return ""; } +{ return ""; } // "const *" flavors. @@ -524,26 +524,28 @@ inline Hurricane::Record* getRecord ( const std::multiset* s ) } +# define GETSTRING_POINTER_SUPPORT(Data) \ + template<> inline std::string getString( Data* data ) \ + { if (!data) return "NULL " #Data; return data->_getString(); } \ + \ + template<> inline std::string getString( const Data* data ) \ + { if (!data) return "NULL const " #Data; return data->_getString(); } + + # define IOSTREAM_POINTER_SUPPORT(Data) \ - inline std::ostream& operator<< ( std::ostream& o, Data* d ) \ - { \ - if (!d) return o << "NULL"; \ - return o << "&" << getString(d); \ - } \ - inline std::ostream& operator<< ( std::ostream& o, const Data* d ) \ - { \ - if (!d) return o << "NULL"; \ - return o << "&" << getString(d); \ + inline std::ostream& operator<< ( std::ostream& o, Data* d ) \ + { \ + if (!d) return o << "NULL"; \ + return o << "&" << getString(d); \ + } \ + inline std::ostream& operator<< ( std::ostream& o, const Data* d ) \ + { \ + if (!d) return o << "NULL"; \ + return o << "&" << getString(d); \ } -# define INSPECTOR_POINTER_SUPPORT(Data) \ - template<> inline std::string getString( Data* data ) \ - { if (!data) return "NULL " #Data; return data->_getString(); } \ - \ - template<> inline std::string getString( const Data* data ) \ - { if (!data) return "NULL const " #Data; return data->_getString(); } \ - \ +# define GETRECORD_POINTER_SUPPORT(Data) \ template<> inline Hurricane::Record* getRecord( Data* data ) \ { if (!data) return NULL; return data->_getRecord(); } \ \ @@ -551,21 +553,23 @@ inline Hurricane::Record* getRecord ( const std::multiset* s ) { if (!data) return NULL; return data->_getRecord(); } \ +# define GETSTRING_REFERENCE_SUPPORT(Data) \ + template<> inline std::string getString( Data& data ) \ + { return data._getString(); } \ + \ + template<> inline std::string getString( const Data& data ) \ + { return data._getString(); } + + # define IOSTREAM_REFERENCE_SUPPORT(Data) \ - inline std::ostream& operator<< ( std::ostream& o, Data& d ) \ - { return o << getString(d); } \ - \ - inline std::ostream& operator<< ( std::ostream& o, const Data& d ) \ + inline std::ostream& operator<< ( std::ostream& o, Data& d ) \ + { return o << getString(d); } \ + \ + inline std::ostream& operator<< ( std::ostream& o, const Data& d ) \ { return o << getString(d); } -# define INSPECTOR_REFERENCE_SUPPORT(Data) \ - template<> inline std::string getString( Data& data ) \ - { return data._getString(); } \ - \ - template<> inline std::string getString( const Data& data ) \ - { return data._getString(); } \ - \ +# define GETRECORD_REFERENCE_SUPPORT(Data) \ template<> inline Hurricane::Record* getRecord( Data& data ) \ { return data._getRecord(); } \ \ @@ -573,44 +577,53 @@ inline Hurricane::Record* getRecord ( const std::multiset* s ) { return data._getRecord(); } +# define GETSTRING_VALUE_SUPPORT(Data) \ + template<> inline std::string getString( Data data ) \ + { return data._getString(); } + + # define IOSTREAM_VALUE_SUPPORT(Data) \ inline std::ostream& operator<< ( std::ostream& o, Data d ) \ { return o << getString(d); } -# define INSPECTOR_VALUE_SUPPORT(Data) \ - template<> inline std::string getString( Data data ) \ - { return data._getString(); } \ - \ +# define GETRECORD_VALUE_SUPPORT(Data) \ template<> inline Hurricane::Record* getRecord( Data data ) \ { return data._getRecord(); } # define INSPECTOR_P_SUPPORT(Data) \ - INSPECTOR_POINTER_SUPPORT(Data) \ + GETRECORD_POINTER_SUPPORT(Data) \ + GETSTRING_POINTER_SUPPORT(Data) \ IOSTREAM_POINTER_SUPPORT(Data) # define INSPECTOR_R_SUPPORT(Data) \ - INSPECTOR_REFERENCE_SUPPORT(Data) \ + GETRECORD_REFERENCE_SUPPORT(Data) \ + GETSTRING_REFERENCE_SUPPORT(Data) \ IOSTREAM_REFERENCE_SUPPORT(Data) # define INSPECTOR_V_SUPPORT(Data) \ - INSPECTOR_VALUE_SUPPORT(Data) \ + GETRECORD_VALUE_SUPPORT(Data) \ + GETSTRING_VALUE_SUPPORT(Data) \ IOSTREAM_VALUE_SUPPORT(Data) # define INSPECTOR_PR_SUPPORT(Data) \ - INSPECTOR_POINTER_SUPPORT(Data) \ - INSPECTOR_REFERENCE_SUPPORT(Data) \ + GETRECORD_POINTER_SUPPORT(Data) \ + GETSTRING_POINTER_SUPPORT(Data) \ + GETRECORD_REFERENCE_SUPPORT(Data) \ + GETSTRING_REFERENCE_SUPPORT(Data) \ IOSTREAM_POINTER_SUPPORT(Data) \ IOSTREAM_REFERENCE_SUPPORT(Data) # define INSPECTOR_PV_SUPPORT(Data) \ - INSPECTOR_POINTER_SUPPORT(Data) \ - INSPECTOR_VALUE_SUPPORT(Data) \ + GETRECORD_POINTER_SUPPORT(Data) \ + GETSTRING_POINTER_SUPPORT(Data) \ + GETRECORD_VALUE_SUPPORT(Data) \ + GETSTRING_VALUE_SUPPORT(Data) \ IOSTREAM_POINTER_SUPPORT(Data) \ IOSTREAM_VALUE_SUPPORT(Data) diff --git a/hurricane/src/hurricane/hurricane/DBo.h b/hurricane/src/hurricane/hurricane/DBo.h index 2b93de75..283f52b6 100644 --- a/hurricane/src/hurricane/hurricane/DBo.h +++ b/hurricane/src/hurricane/hurricane/DBo.h @@ -1,97 +1,87 @@ -// **************************************************************************************************** -// File: DBo.h -// Authors: R. Escassut -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** -#ifndef HURRICANE_DBO -#define HURRICANE_DBO +// -*- C++ -*- +// +// This file is part of the Hurricane Software. +// Copyright (c) UPMC/LIP6 2008-2008, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Jean-Paul Chaput | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Header : "./DBo.h" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +#ifndef __HURRICANE_DBO__ +#define __HURRICANE_DBO__ + +#include "hurricane/DBos.h" +#include "hurricane/Properties.h" +#include "hurricane/Name.h" -#include "hurricane/DBos.h" -#include "hurricane/Name.h" -#include "hurricane/Property.h" namespace Hurricane { + class Property; -// **************************************************************************************************** -// DBo declaration -// **************************************************************************************************** -class DBo { -// ******** +// ------------------------------------------------------------------- +// Class : "Hurricane::DBo". -#if !defined(__DOXYGEN_PROCESSOR__) -// Types -// ***** + class DBo { - public: typedef set PropertySet; + public: + // Types. + typedef set PropertySet; + // Methods. + virtual void destroy(); + inline PropertySet& _getPropertySet (); + void _onDestroyed ( Property* property ); + Property* getProperty ( const Name& ) const; + Properties getProperties () const; + inline bool hasProperty () const; + void put ( Property* ); + void remove ( Property* ); + void removeProperty ( const Name& ); + void clearProperties (); + // Hurricane Managment. + virtual string _getTypeName () const; + virtual string _getString () const; + virtual Record* _getRecord () const; -// Attributs -// ********* + private: + // Internal: Attributes. + mutable PropertySet _propertySet; - private: mutable PropertySet _propertySet; + protected: + // Internal: Constructors & Destructors. + DBo (); + virtual ~DBo (); + virtual void _postCreate (); + virtual void _preDestroy (); + private: + // Forbidden: Copies. + DBo ( const DBo& ); + DBo& operator= ( const DBo& ); + }; -// Constructors -// ************ - protected: DBo(); - - private: DBo(const DBo& dbo); // not implemented to forbid copy construction - -// Destructors -// *********** - - protected: virtual ~DBo(); - -// Operators -// ********* - - private: DBo& operator=(const DBo& dbo); // not implemented to forbid assignment - -// Others -// ****** - - protected: virtual void _postCreate(); - - protected: virtual void _preDestroy(); - - public: virtual string _getTypeName() const; - public: virtual string _getString() const; - public: virtual Record* _getRecord() const; - public: PropertySet& _getPropertySet() {return _propertySet;}; - - public: void _onDestroyed(Property* property); - -#endif - -// Destructors -// *********** - - public: virtual void destroy(); - -// Accessors -// ********* - - public: Property* getProperty(const Name& name) const; - public: Properties getProperties() const {return getCollection(_propertySet);}; - -// Predicates -// ********** - - public: bool hasProperty() const {return !_propertySet.empty();}; - -// Updators -// ******** - - public: void put(Property* property); - public: void remove(Property* property); - public: void removeProperty(const Name& name); - public: void clearProperties(); - -}; +// Inline Functions. + inline DBo::PropertySet& DBo::_getPropertySet () { return _propertySet; } + inline bool DBo::hasProperty () const { return !_propertySet.empty(); } } // End of Hurricane namespace. @@ -114,8 +104,4 @@ inline Hurricane::Slot* getSlot ( const std::string& name, std::set + static DerivedProperty* get ( const DBo* ); + static Name staticGetName (); + // Constructor. + template + static DerivedProperty* create (); + template + static DerivedProperty* create ( const Value& ); + // Destructor. + virtual void destroy (); + // Methods. + virtual Name getName () const = 0; + virtual void onCapturedBy ( DBo* owner ) = 0; + virtual void onReleasedBy ( DBo* owner ) = 0; + // Hurricane Managment. + virtual string _getTypeName () const = 0; + virtual string _getString () const; + virtual Record* _getRecord () const; + + private: + static Name _baseName; + protected: + // Internal: Constructors & Destructors. + Property (); + virtual ~Property (); + virtual void _postCreate () {}; + virtual void _preDestroy () {}; + private: + Property ( const Property& ); + Property& operator= ( const Property& ); + }; + + + template + DerivedProperty* Property::create () + { + DerivedProperty* property = new DerivedProperty(); + property->_postCreate(); + return property; + } + + + template + DerivedProperty* Property::create ( const Value& value ) + { + DerivedProperty* property = new DerivedProperty(value); + property->_postCreate(); + return property; + } + + + template + DerivedProperty* Property::get ( const DBo* object ) + { + Property* property1 = object->getProperty ( DerivedProperty::staticGetName() ); + DerivedProperty* property2 = dynamic_cast ( property1 ); + + if ( property1 && !property2 ) + throw Error ( propertyTypeNameError + , getString(DerivedProperty::staticGetName()).c_str() + , getString(object).c_str() ); + + return property2; + } + + +// ------------------------------------------------------------------- +// Class : "Hurricane::PrivateProperty". + + + class PrivateProperty : public Property { + + public: + // Methods. + inline DBo* getOwner () const; + virtual void onCapturedBy ( DBo* owner ); + virtual void onReleasedBy ( DBo* owner ); + virtual void onNotOwned (); + virtual string _getString () const; + virtual Record* _getRecord () const; + + private: + // Internal: Attributes. + DBo* _owner; + protected: + // Internal: Constructor & Destructors. + PrivateProperty (); + virtual void _preDestroy (); + }; + + +// Inline Functions. + inline DBo* PrivateProperty::getOwner () const { return _owner; }; + + +// ------------------------------------------------------------------- +// Template Class : "Hurricane::StandardPrivateProperty". + + + template class StandardPrivateProperty : public PrivateProperty { + + public: + static Name staticGetName (); + static StandardPrivateProperty* get ( const DBo* ); + // Constructors. + static StandardPrivateProperty* create (); + static StandardPrivateProperty* create ( const Value& ); + // Methods. + virtual Name getName () const; + Value& getValue () const; + void setValue ( const Value& ); + virtual string _getTypeName () const; + virtual string _getString () const; + virtual Record* _getRecord () const; + + private: + // Internal: Attributes. + static Name _name; + mutable Value _value; + + protected: + // Internal: Constructor. + StandardPrivateProperty (); + StandardPrivateProperty ( const Value& ); + }; + + + template + Name StandardPrivateProperty::staticGetName () + { + return _name; + } + + + template + StandardPrivateProperty* StandardPrivateProperty::create () + { + StandardPrivateProperty* property = new StandardPrivateProperty(); + property->_postCreate(); + return property; + } + + + template + StandardPrivateProperty* StandardPrivateProperty::create ( const Value& value ) + { + StandardPrivateProperty* property = new StandardPrivateProperty(value); + property->_postCreate(); + return property; + } + + + template + StandardPrivateProperty* StandardPrivateProperty::get ( const DBo* object ) + { + Property* property1 = object->getProperty ( StandardPrivateProperty::staticGetName() ); + StandardPrivateProperty* property2 = dynamic_cast*> ( property1 ); + + if ( property1 && !property2 ) + throw Error ( propertyTypeNameError + , getString(StandardPrivateProperty::staticGetName()).c_str() + , getString(object).c_str() ); + + return property2; + } + + + template + StandardPrivateProperty::StandardPrivateProperty () + : PrivateProperty(), _value() + { } + + + template + StandardPrivateProperty::StandardPrivateProperty ( const Value& value ) + : PrivateProperty(), _value(value) + { } + + + template + Name StandardPrivateProperty::getName() const + { + return staticGetName(); + } + + + template + Value& StandardPrivateProperty::getValue () const + { + return _value; + } + + + template + void StandardPrivateProperty::setValue ( const Value& value ) + { + _value = value; + } + + + template + string StandardPrivateProperty::_getTypeName () const + { + return _TName("StandardPrivateProperty"); + } + + template + string StandardPrivateProperty::_getString () const + { + string s = PrivateProperty::_getString(); + s.insert(s.length() - 1, " " + getString(_value)); + return s; + } + + template + Record* StandardPrivateProperty::_getRecord () const + { + Record* record = PrivateProperty::_getRecord(); + if (record) { + record->add ( getSlot("Name" , staticGetName()) ); + record->add ( getSlot("Value",&_value) ); + } + return record; + } + + +// ------------------------------------------------------------------- +// Class : "Hurricane::SharedProperty". + + + class SharedProperty : public Property { + + public: + // Types. + typedef set DBoSet; + // Methods. + inline DBos getOwners () const; + virtual void onCapturedBy ( DBo* owner ); + virtual void onReleasedBy ( DBo* owner ); + virtual void onNotOwned (); + inline DBoSet& _getOwnerSet (); + virtual string _getString () const; + virtual Record* _getRecord () const; + + private: + // Internal: Attributes. + DBoSet _ownerSet; + + protected: + // Internal: Constructor & Destructor. + SharedProperty (); + virtual void _preDestroy (); + }; + + +// Inline Functions. + DBos SharedProperty::getOwners () const { return getCollection(_ownerSet); } + SharedProperty::DBoSet& SharedProperty::_getOwnerSet () { return _ownerSet; } + + +// ------------------------------------------------------------------- +// Template Class : "Hurricane::StandardSharedProperty". + + + template class StandardSharedProperty : public SharedProperty { -// **************************************************************************************************** -// Property declaration -// **************************************************************************************************** - -class Property { -// ************* - -// Constructors -// ************ - - protected: Property(); - - private: Property(const Property& property); // not implemented to forbid copy construction - -// Destructors -// *********** - - protected: virtual ~Property(); - - public: virtual void destroy(); - -// Operators -// ********* - - private: Property& operator=(const Property& property); // not implemented to forbid assignment - -// Accessors -// ********* - - public: virtual Name getName() const = 0; - -// Managers -// ******** - - public: virtual void onCapturedBy(DBo* owner) = 0; - public: virtual void onReleasedBy(DBo* owner) = 0; - -// Others -// ****** - - protected: virtual void _postCreate() {}; - - protected: virtual void _preDestroy() {}; - - public: virtual string _getTypeName() const = 0; - public: virtual string _getString() const; - public: virtual Record* _getRecord() const; - -}; - - - -// **************************************************************************************************** -// PrivateProperty declaration -// **************************************************************************************************** - -class PrivateProperty : public Property { -// ************************************ - -// Types -// ***** - - public: typedef Property Inherit; - -// Attributes -// ********** - - private: DBo* _owner; - -// Constructors -// ************ - - protected: PrivateProperty(); - -// Accessors -// ********* - - public: DBo* getOwner() const {return _owner;}; - -// Managers -// ******** - - public: virtual void onCapturedBy(DBo* owner); - public: virtual void onReleasedBy(DBo* owner); - public: virtual void onNotOwned(); - -// Others -// ****** - - protected: virtual void _preDestroy(); - - public: virtual string _getString() const; - public: virtual Record* _getRecord() const; - -}; - - - -// **************************************************************************************************** -// StandardPrivateProperty declaration -// **************************************************************************************************** - -template class StandardPrivateProperty : public PrivateProperty { -// ************************************************************************* - -// Types -// ***** - - public: typedef PrivateProperty Inherit; - -// Attributes -// ********** - - private: Name _name; - private: Value _value; - -// Constructors -// ************ - - protected: StandardPrivateProperty(const Name& name, const Value& value) - // ********************************************************************* - : Inherit(), - _name(name), - _value(value) - { - }; - - public: static StandardPrivateProperty* create(const Name& name, const Value& value ) - // ********************************************************************************** - { - StandardPrivateProperty* property = new StandardPrivateProperty(name, value); - - property->_postCreate(); - - return property; - }; - -// Accessors -// ********* - - public: virtual Name getName() const - // ********************************* - { - return _name; - }; - - public: const Value& getValue() const - // ********************************** - { - return _value; - }; - -// Modifieurs -// ********** - - public: void setValue(const Value& value) - // ************************************** - { - _value = value; - }; - -// Others -// ****** - - public: virtual string _getTypeName() const - // **************************************** - { - return _TName("StandardPrivateProperty"); - }; - - public: virtual string _getString() const - // ************************************** - { - string s = Inherit::_getString(); - s.insert(s.length() - 1, " " + getString(_value)); - return s; - }; - - public: virtual Record* _getRecord() const - // ********************************* - { - Record* record = Inherit::_getRecord(); - if (record) { - record->add(getSlot("Name", &_name)); - record->add(getSlot("Value", _value)); - } - return record; - }; - -}; - - - -// **************************************************************************************************** -// SharedProperty declaration -// **************************************************************************************************** - -class SharedProperty : public Property { -// *********************************** - -// Types -// ***** - - public: typedef Property Inherit; - public: typedef set DBoSet; - -// Attributes -// ********** - - private: DBoSet _ownerSet; - -// Constructors -// ************ - - protected: SharedProperty(); - -// Accessors -// ********* - - public: DBos getOwners() const {return getCollection(_ownerSet);}; - -// Managers -// ******** - - public: virtual void onCapturedBy(DBo* owner); - public: virtual void onReleasedBy(DBo* owner); - public: virtual void onNotOwned(); - -// Accessors -// ********* - - protected: virtual void _preDestroy(); - - public: virtual string _getString() const; - public: virtual Record* _getRecord() const; - - public: DBoSet& _getOwnerSet() {return _ownerSet;}; - -}; - - - -// **************************************************************************************************** -// StandardSharedProperty declaration -// **************************************************************************************************** - -template class StandardSharedProperty : public SharedProperty { -// *********************************************************************** - -// Types -// ***** - - public: typedef SharedProperty Inherit; - -// Attributes -// ********** - - private: Name _name; - private: Value _value; - -// Constructors -// ************ - - protected: StandardSharedProperty(const Name& name, const Value& value) - // ******************************************************************** - : Inherit(), - _name(name), - _value(value) - { - }; - - public: static StandardSharedProperty* create(const Name& name, const Value& value ) - // ********************************************************************************* - { - StandardSharedProperty* property = new StandardSharedProperty(name, value); - - property->_postCreate(); - - return property; - }; - -// Accessors -// ********* - - public: virtual Name getName() const - // ********************************* - { - return _name; - }; - - public: const Value& getValue() const - // ********************************** - { - return _value; - }; - -// Modifieurs -// ********** - - public: void setValue(const Value& value) - // ************************************** - { - _value = value; - }; - -// Others -// ****** - - public: virtual string _getTypeName() const - // **************************************** - { - return _TName("StandardSharedProperty"); - }; - - public: virtual string _getString() const - // ************************************** - { - string s = Inherit::_getString(); - s.insert(s.length() - 1, " " + getString(_value)); - return s; - }; - - public: virtual Record* _getRecord() const - // ********************************* - { - Record* record = Inherit::_getRecord(); - if (record) { - record->add(getSlot("Name", &_name)); - record->add(getSlot("Value", &_value)); - } - return record; - }; - -}; + public: + static Name staticGetName (); + static StandardSharedProperty* get ( const DBo* ); + // Constructors. + static StandardSharedProperty* create (); + static StandardSharedProperty* create ( const Value& ); + // Methods. + virtual Name getName () const; + Value& getValue () const; + void setValue ( const Value& ); + virtual string _getTypeName () const; + virtual string _getString () const; + virtual Record* _getRecord () const; + + private: + // Internal: Attributes. + static Name _name; + mutable Value _value; + + protected: + // Internal: Constructor. + StandardSharedProperty (); + StandardSharedProperty ( const Value& ); + }; + + +// Template function members. + template + Name StandardSharedProperty::staticGetName () + { + return _name; + } + + + template + StandardSharedProperty* StandardSharedProperty::create () + { + StandardSharedProperty* property = new StandardSharedProperty(); + property->_postCreate(); + return property; + } + + + template + StandardSharedProperty* StandardSharedProperty::create ( const Value& value ) + { + StandardSharedProperty* property = new StandardPrivateProperty(value); + property->_postCreate(); + return property; + } + + + template + StandardSharedProperty* StandardSharedProperty::get ( const DBo* object ) + { + Property* property1 = object->getProperty ( StandardSharedProperty::staticGetName() ); + StandardSharedProperty* property2 = dynamic_cast*> ( property1 ); + + if ( property1 && !property2 ) + throw Error ( propertyTypeNameError + , getString(StandardSharedProperty::staticGetName()).c_str() + , getString(object).c_str() ); + + return property2; + } + + + template + StandardSharedProperty::StandardSharedProperty () + : SharedProperty(), _value() + { } + + + template + StandardSharedProperty::StandardSharedProperty ( const Value& value ) + : SharedProperty(), _value(value) + { } + + + template + Name StandardSharedProperty::getName() const + { + return staticGetName(); + } + + + template + Value& StandardSharedProperty::getValue() const + { + return _value; + } + + + template + void StandardSharedProperty::setValue(const Value& value) + { + _value = value; + } + + + template + string StandardSharedProperty::_getTypeName() const + { + return _TName("StandardSharedProperty"); + } + + + template + string StandardSharedProperty::_getString() const + { + string s = SharedProperty::_getString(); + s.insert(s.length() - 1, " " + getString(_value)); + return s; + } + + + template + Record* StandardSharedProperty::_getRecord() const + { + Record* record = SharedProperty::_getRecord(); + if (record) { + record->add ( getSlot("Name" , staticGetName()) ); + record->add ( getSlot("Value", &_value) ); + } + return record; + } } // End of Hurricane namespace. @@ -358,8 +446,4 @@ template class StandardSharedProperty : public SharedProperty { INSPECTOR_P_SUPPORT(Hurricane::Property); -#endif // HURRICANE_PROPERTY - -// **************************************************************************************************** -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** +#endif // __HURRICANE_PROPERTY__ diff --git a/hurricane/src/hurricane/hurricane/Warning.h b/hurricane/src/hurricane/hurricane/Warning.h index f90de68d..c9cb966a 100644 --- a/hurricane/src/hurricane/hurricane/Warning.h +++ b/hurricane/src/hurricane/hurricane/Warning.h @@ -1,68 +1,73 @@ -// **************************************************************************************************** -// File: Warning.h -// Authors: R. Escassut -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** -#ifndef HURRICANE_WARNING -#define HURRICANE_WARNING +// -*- C++ -*- +// +// This file is part of the Hurricane Software. +// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved +// +// =================================================================== +// +// $Id$ +// +// x-----------------------------------------------------------------x +// | | +// | H U R R I C A N E | +// | V L S I B a c k e n d D a t a - B a s e | +// | | +// | Author : Remy Escassut | +// | E-mail : Jean-Paul.Chaput@lip6.fr | +// | =============================================================== | +// | C++ Header : "./Warning.h" | +// | *************************************************************** | +// | U p d a t e s | +// | | +// x-----------------------------------------------------------------x + + +# ifndef __HURRICANE_WARNING__ +# define __HURRICANE_WARNING__ #include "hurricane/Exception.h" + namespace Hurricane { + class Warning : public Exception { -// **************************************************************************************************** -// Warning declaration -// **************************************************************************************************** + public: + // Constructors. + Warning ( const string& reason ); + Warning ( const char* format, ... ); + Warning ( int code, const string& reason ); + Warning ( int code, const char* format, ... ); + Warning ( const Warning& warning ); + Warning& operator= ( const Warning& warning ); + // Methods. + inline string getReason () const; + inline int getCode () const; + // Hurricane Managment. + virtual string _getTypeName () const; + virtual string _getString () const; -class Warning : public Exception { -// ***************************** + protected: + // Internal: Attributes. + string _reason; + int _code; + }; -// Types -// ***** - public: typedef Exception Inherit; - -// Attributes -// ********** - - private: string _reason; - private: int _code; - -// Constructors -// ************ - - public: Warning(const string& reason, int code = 0); - - public: Warning(const Warning& warning); - -// Operators -// ********* - - public: Warning& operator=(const Warning& warning); - -// Accessors -// ********* - - public: string getReason() const {return _reason;}; - public: int getCode() const {return _code;}; - -// Others -// ****** - - public: virtual string _getTypeName() const { return _TName("Warning"); }; - public: virtual string _getString() const; - -}; +// Inline Functions. + inline string Warning::getReason () const { return _reason; } + inline int Warning::getCode () const { return _code; } } // End of Hurricane namespace. -#endif // HURRICANE_WARNING +GETSTRING_POINTER_SUPPORT(Hurricane::Warning); +GETSTRING_VALUE_SUPPORT(Hurricane::Warning); +IOSTREAM_POINTER_SUPPORT(Hurricane::Warning); +IOSTREAM_VALUE_SUPPORT(Hurricane::Warning); -// **************************************************************************************************** -// Copyright (c) BULL S.A. 2000-2004, All Rights Reserved -// **************************************************************************************************** + +# endif // __HURRICANE_WARNING__ diff --git a/hurricane/src/hviewer/DisplayStyle.cpp b/hurricane/src/hviewer/DisplayStyle.cpp index 7ca18987..809f5df6 100644 --- a/hurricane/src/hviewer/DisplayStyle.cpp +++ b/hurricane/src/hviewer/DisplayStyle.cpp @@ -53,6 +53,7 @@ # include # include "hurricane/viewer/DisplayStyle.h" +# include "hurricane/viewer/Graphics.h" @@ -112,7 +113,11 @@ namespace Hurricane { , float threshold ) { - return new DrawingStyle ( name, pattern, red, green, blue, borderWidth, threshold ); + DrawingStyle* style = new DrawingStyle ( name, pattern, red, green, blue, borderWidth, threshold ); + //if ( Graphics::isEnabled() ) + // style->qtAllocate (); + + return style; } diff --git a/hurricane/src/hviewer/Graphics.cpp b/hurricane/src/hviewer/Graphics.cpp index 7a833052..71b75506 100644 --- a/hurricane/src/hviewer/Graphics.cpp +++ b/hurricane/src/hviewer/Graphics.cpp @@ -76,9 +76,6 @@ namespace Hurricane { , _active(NULL) , _qtEnabled(false) { - _styles.push_back ( new DisplayStyle("Fallback") ); - _active = _styles[0]; - _active->setDescription ( "Builtin fallback style" ); } @@ -90,8 +87,12 @@ namespace Hurricane { Graphics* Graphics::getGraphics () { - if ( !_singleton ) + if ( !_singleton ) { _singleton = new Graphics (); + DisplayStyle* fallback = new DisplayStyle("Fallback"); + fallback->setDescription ( "Builtin fallback style" ); + _singleton->_addStyle ( fallback ); + } return _singleton; }