diff --git a/hurricane/doc/hurricane/DbU.dox b/hurricane/doc/hurricane/DbU.dox index 6f0db853..8a7711e8 100644 --- a/hurricane/doc/hurricane/DbU.dox +++ b/hurricane/doc/hurricane/DbU.dox @@ -4,17 +4,30 @@ namespace Hurricane { - /*! \defgroup DbU DbU/Unit description + /*! \defgroup DbUGroup DbU/Unit description * * \section secDbUIntro Introduction * - * Those objects are used to model a geometric lengths, that is - * abscissas, ordinates, widths, offsets ... + * The DbU class provides the DbU::Unit type for modelling geometric + * length, that is abscissas, ordinates, widths, offsets and a set of + * functions to convert DbU::Unit to and from external coordinates. * - * They are represented internally by a long integer - * asociated with a precision and not by a double in - * order to avoid floating point round errors. - * + * \remark The DbU class contains only static methods, and is not meant to + * be instanciated. The working type is DbU::Unit. + * + * The DbU class manage three king of length : + * * * \section secDbUPrecision Precision * @@ -24,13 +37,14 @@ * This precision represents the maximal number of decimal * digits allowed (it applies globally to all units). Therefore * for a precision of 3, the unit will represent a value of - * 0.001 and the effective value 23.54 will be represented by a + * 0.001 and the founder grid value 23.54 will be represented by a * unit equal to 23540. * + * Related functions : * * * @@ -38,9 +52,21 @@ * * The resolution is associated to the precision. Indeed it * represents the external value associated to the smallest - * unit, that is the value returned by getValue(getUnit(1)). + * unit, that is the value returned by getReal(Unit::db(1)). * - * DbU::getResolution + * Related functions : + * DbU::getResolution() + * + * \section secDbURealsPerLamba Reals per Lambda ratio + * + * Set the ratio between reals and lambdas. This must be an + * even integer. Once sets, musn't be changed. + * + * Related functions : + * * * * \section secDbUGrid Grid @@ -55,19 +81,33 @@ * * \section secDbUTranslators Translators * + * Translate a DbU::Unit into grid or lambda length : * + * + * Translate a lambda length into a DbU::Unit : + * */ - /*! \ingroup DbU + /*! \ingroup DbUGroup */ // \{ + /*! \class DbU + * \brief DataBase Unit managment (\b API). + * + * Explanations about this class are here \ref DbUGroup. + */ + /* \function bool DbU::isOnGrid(const Unit& unit, int n = 1); * \Return \true if the unit is on grid, else \false. The argument * \c \ allows to consider on grid only multiples of @@ -76,15 +116,33 @@ */ - /* \function unsigned DbU::getPrecision(); - * \Return the current precision (whose default is fixed to 0). + /*! \typedef long DbU::Unit; + * The working DataBase type for storing dimensions. */ - /* \function unsigned DbU::getMaximalPrecisionAllowed(); + /*! \enum DbU::StringMode + * Select how units are to be printed by getValueString(). + */ + /*! \var Dbu::StringMode DbU::Db + * Units are printed "as is", their true value as stored in the + * DataBase. + */ + /*! \var Dbu::StringMode DbU::Real + * Units are printed as real (founder grid steps). + */ + /*! \var Dbu::StringMode DbU::Symbolic + * Units are printed as symbolic (lambdas). + */ + + /*! \function unsigned DbU::getPrecision(); + * \Return the current precision (whose default is fixed to 1). + */ + + /*! \function unsigned DbU::getMaximalPrecision(); * \Return the maximal precision allowed (currently fixed to 3). */ - /* \function double DbU::getResolution(); + /*! \function double DbU::getResolution(); * \Return the current resolution. */ @@ -101,27 +159,65 @@ * \remark Throw an exception for any other \c \ argument value. */ - /* \function DbU::Unit getUnit(double value); + /*! \function void DbU::setRealsPerLambda(double realsPerLambda); + * \Return Sets how many reals (founder grid steps) makes one lambda. + * It must be an event integer otherwise an exception is thrown. + */ + + /*! \function double DbU::getRealsPerLambda(); + * \Return How many reals (founder grid steps) makes one lambda. + */ + + /*! \function DbU::Unit DbU::db(long u); * \Return the unit corresponding to the value \c \ according to - * the current precision. + * the current precision. This function do nothing apart from a + * cast. */ - /* \function double DbU::getValue(const Unit& unit); + /*! \function DbU::Unit DbU::real(double value); + * \Return the unit corresponding to the real value \c \ + * according to the current precision. + */ + + /*! \function DbU::Unit DbU::lambda(double value); + * \Return the unit corresponding to the symbolic value \c \ + * according to the current precision. + */ + + /*! \function long DbU::getDb(Unit unit); * \Return the external value associated to the unit \c \ - * according to the current precision. + * according to the current precision. This function do + * nothing apart from a type cast. */ - /* \function string DbU::getValueString(const Unit& unit); - * \Return a character string representing the external value of - * \c \. + /*! \function double DbU::getReal(Unit unit); + * \Return the real value (expressed as a number of founder grid steps) + * associated to the unit \c \ according to the current + * precision. + */ + + /*! \function double DbU::getLambda(Unit unit); + * \Return the symbolic value (expressed as a number lambdas) + * associated to the unit \c \ according to the current + * precision. + */ + + /*! \function void DbU::setStringMode(unsigned int mode); + * Sets in which length the units are to be displayed by + * getValueString(). Avalaibles modes are : + */ + + /*! \function string DbU::getValueString(Unit unit); + * \return A character string representing the external value of + * \c \. The value is converted in the length according + * to setStringMode(): database, real or symbolic. * * \remark This string is shorter than the one we could print from the * external value because non needed decimals are not drawn (nor * the point if value is integer). */ - - /* \function void DbU::setPrecision(unsigned precision); + /*! \function void DbU::setPrecision(unsigned int precision); * Allows to set the precision at a requested value. This must * be done at the begining of the program (before the creation * of the first unit) and not changed for the following (unless diff --git a/hurricane/doc/hurricane/customHierarchy.html b/hurricane/doc/hurricane/customHierarchy.html index 33927698..c2171c51 100644 --- a/hurricane/doc/hurricane/customHierarchy.html +++ b/hurricane/doc/hurricane/customHierarchy.html @@ -81,7 +81,7 @@

Common Objects

- + diff --git a/hurricane/doc/hurricane/customSummary.html b/hurricane/doc/hurricane/customSummary.html index 0ddcfb02..72453e75 100644 --- a/hurricane/doc/hurricane/customSummary.html +++ b/hurricane/doc/hurricane/customSummary.html @@ -31,7 +31,7 @@
  • Generalities
    Naming conventions, Utilitarians, Generic Functions. -
  • Unit
    +
  • DbU/Unit
    Object/Type used to model all coordinates in Hurricane.
  • Synthetic Class Hierarchy.
  • Complete Class Hierarchy (doxygen). diff --git a/hurricane/src/hurricane/DBo.cpp b/hurricane/src/hurricane/DBo.cpp index a215bc1e..7b1de69a 100644 --- a/hurricane/src/hurricane/DBo.cpp +++ b/hurricane/src/hurricane/DBo.cpp @@ -130,6 +130,12 @@ void DBo::_preDestroy() // trace_out(); } +string DBo::_getTypeName () const +// ****************************** +{ + return "DBo"; +} + string DBo::_getString() const // *************************** { diff --git a/hurricane/src/hurricane/DbU.cpp b/hurricane/src/hurricane/DbU.cpp index 9d929e1d..21eff2df 100644 --- a/hurricane/src/hurricane/DbU.cpp +++ b/hurricane/src/hurricane/DbU.cpp @@ -36,7 +36,7 @@ namespace Hurricane { const unsigned int DbU::_maximalPrecision = 3; unsigned int DbU::_precision = 1; double DbU::_resolution = 0.1; - double DbU::_unitsPerLambda = 10.0; + double DbU::_realsPerLambda = 10.0; unsigned int DbU::_stringMode = DbU::Symbolic; const DbU::Unit DbU::Min = LONG_MIN; const DbU::Unit DbU::Max = LONG_MAX; @@ -75,20 +75,20 @@ namespace Hurricane { } - void DbU::setUnitsPerLambda ( double unitsPerLambda ) + void DbU::setRealsPerLambda ( double realsPerLambda ) { - if ( ( rint(unitsPerLambda) != unitsPerLambda ) - || ( remainder(unitsPerLambda,2.0) != 0.0 ) ) - throw Error ( "DbU::Unit::setUnitPerLambdas(): \"unitsPerLambda\" (%f) must be an even integer." - , unitsPerLambda + if ( ( rint(realsPerLambda) != realsPerLambda ) + || ( remainder(realsPerLambda,2.0) != 0.0 ) ) + throw Error ( "DbU::Unit::setRealPerLambdas(): \"realsPerLambda\" (%f) must be an even integer." + , realsPerLambda ); - _unitsPerLambda = unitsPerLambda; + _realsPerLambda = realsPerLambda; } - double DbU::getUnitsPerLambda () - { return _unitsPerLambda; } + double DbU::getRealsPerLambda () + { return _realsPerLambda; } void DbU::setStringMode ( unsigned int mode ) @@ -154,21 +154,35 @@ namespace Hurricane { string DbU::getValueString ( DbU::Unit u ) { char buffer[1024]; + char unitSymbol = 'u'; + + if ( _stringMode == Real ) { + if ( u == 0 ) return "0g"; + + unitSymbol = 'g'; + snprintf ( buffer, 1024, "%.1f", getReal(u) ); + } else if ( _stringMode == Symbolic ) { + if ( u == 0 ) return "0l"; + + unitSymbol = 'l'; + snprintf ( buffer, 1024, "%.1f", getLambda(u) ); + } else { + if ( _stringMode != Db ) + cerr << "[ERROR] Unknown Unit representation mode: " << _stringMode << endl; - if ( _stringMode == Db ) { if ( u == 0 ) return "0u"; - snprintf ( buffer, 1024, "%ldu", u ); - } else if ( _stringMode == Real ) { - if ( u == 0 ) return "0g"; - - snprintf ( buffer, 1024, "%.1fg", getReal(u) ); - } else if ( _stringMode == Symbolic ) { - if ( u == 0 ) return "0g"; - - snprintf ( buffer, 1024, "%.1flbd", getLambda(u) ); + snprintf ( buffer, 1024, "%ld", u ); } + size_t length = strlen(buffer) - 1; + for ( ; length > 0 ; length-- ) { + if ( (buffer[length] != '0') && (buffer[length] != '.') ) + break; + } + buffer[++length] = unitSymbol; + buffer[++length] = '\0'; + return buffer; } diff --git a/hurricane/src/hurricane/hurricane/DBo.h b/hurricane/src/hurricane/hurricane/DBo.h index b17ac876..84bcdabc 100644 --- a/hurricane/src/hurricane/hurricane/DBo.h +++ b/hurricane/src/hurricane/hurricane/DBo.h @@ -32,7 +32,7 @@ class DBo : public NestedSlotAdapter { // Attributs // ********* - private: PropertySet _propertySet; + private: mutable PropertySet _propertySet; // Constructors // ************ @@ -58,7 +58,7 @@ class DBo : public NestedSlotAdapter { protected: virtual void _preDestroy(); - public: virtual string _getTypeName() const = 0; + public: virtual string _getTypeName() const; public: virtual string _getString() const; public: virtual Record* _getRecord() const; public: PropertySet& _getPropertySet() {return _propertySet;}; diff --git a/hurricane/src/hurricane/hurricane/DbU.h b/hurricane/src/hurricane/hurricane/DbU.h index b7ac5711..6cd70d15 100644 --- a/hurricane/src/hurricane/hurricane/DbU.h +++ b/hurricane/src/hurricane/hurricane/DbU.h @@ -56,8 +56,8 @@ namespace Hurricane { static double getResolution (); static void setPrecision ( unsigned int precision ); // Lamba Managment. - static void setUnitsPerLambda ( double unitsPerLambda ); - static double getUnitsPerLambda (); + static void setRealsPerLambda ( double realsPerLambda ); + static double getRealsPerLambda (); // Grid Managment. //static void setGridStep ( const Unit& gridStep ); //static const Unit getGridStep (); @@ -79,7 +79,7 @@ namespace Hurricane { static const unsigned int _maximalPrecision; static unsigned int _precision; static double _resolution; - static double _unitsPerLambda; + static double _realsPerLambda; static unsigned int _stringMode; }; @@ -87,10 +87,10 @@ namespace Hurricane { // Inline Functions. inline DbU::Unit DbU::db ( long value ) { return value; } inline DbU::Unit DbU::real ( double value ) { return (long)rint( value/_resolution ); } - inline DbU::Unit DbU::lambda ( double value ) { return real(value*_unitsPerLambda); } + inline DbU::Unit DbU::lambda ( double value ) { return real(value*_realsPerLambda); } inline long DbU::getDb ( DbU::Unit u ) { return u; } inline double DbU::getReal ( DbU::Unit u ) { return _resolution*(double)u; } - inline double DbU::getLambda ( DbU::Unit u ) { return getReal(u)/_unitsPerLambda; } + inline double DbU::getLambda ( DbU::Unit u ) { return getReal(u)/_realsPerLambda; } } // End of Hurricane namespace. diff --git a/hurricane/src/hurricane/hurricane/SlotAdapter.h b/hurricane/src/hurricane/hurricane/SlotAdapter.h index 102c3062..469f13e6 100644 --- a/hurricane/src/hurricane/hurricane/SlotAdapter.h +++ b/hurricane/src/hurricane/hurricane/SlotAdapter.h @@ -830,6 +830,57 @@ template +// ------------------------------------------------------------------- +// Class : "SlotAdapterSet". + +template + class PointerSlotAdapter > : public SlotAdapter { + + // Attributes. + protected: + set* _s; + + // Constructor. + public: + PointerSlotAdapter ( set* m ) : _s(m) {}; + + // Destructor. + public: + virtual ~PointerSlotAdapter () {}; + + // Slot Management. + public: + virtual string _getTypeName () const { return ">"; }; + virtual string _getString () const; + virtual Record* _getRecord () const; + }; + + +template + inline string PointerSlotAdapter >::_getString () const { + string name = "set:"; + return name + getString(_s->size()); + } + + +template + inline Record* PointerSlotAdapter >::_getRecord () const { + Record* record = NULL; + if ( !_s->empty() ) { + record = new Record ( "set" ); + unsigned n = 1; + typename set::const_iterator iterator = _s->begin(); + while ( iterator != _s->end() ) { + record->add ( getSlot(getString(n++), *iterator) ); + ++iterator; + } + } + return record; + } + + + + // ------------------------------------------------------------------- // Class : "SlotAdapterMultiSet".
Tabulation
Unit
Unit
Point
Box
Interval