* ./hurricane/doc/hurricane :
- Documentation of DbU, replacing documentation of Unit. * ./hurricane/src/hurricane/hurricane/DBo.h : - Property set is now a mutable member, allowing const DBo to changes their properties. Strange side effect on SlotAdapter in which we need to declare two separate templates, one for const type and another for non-const type. - _getTypeName() defined to prevents noisy error message when a derived class (from DBo) do not want to implement support for the inspector.
This commit is contained in:
parent
4e134275f6
commit
59e8d945d6
|
@ -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 <b>long integer</b>
|
||||
* asociated with a <b>precision</b> 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 :
|
||||
* <ul>
|
||||
* <li><b>DbU::Unit</b> : the working type. It is currently associated
|
||||
* to a long integer and a precision/resolution. This way all
|
||||
* numbers are bound to the same precision (unlike floating
|
||||
* point numbers) preventing rounding errors.
|
||||
* <li><b>Real</b> length : length, expressed in steps of founder
|
||||
* grid. We have the straight relation ship :
|
||||
* grid = unit * resolution
|
||||
* <li><b>Symbolic</b> length : length, expressed in lambdas.
|
||||
* A lambda is an even multiple of the founder grid step.
|
||||
* lambda = grid / lambdaPerGrid
|
||||
* </ul>
|
||||
*
|
||||
* \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 :
|
||||
* <ul>
|
||||
* <li><b>DbU::getPrecision</b>
|
||||
* <li><b>DbU::getMaximalPrecisionAllowed</b>
|
||||
* <li><b>DbU::setPrecision</b>
|
||||
* <li><b>DbU::getPrecision()</b>
|
||||
* <li><b>DbU::getMaximalPrecision()</b>
|
||||
* <li><b>DbU::setPrecision()</b>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
|
@ -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)).
|
||||
*
|
||||
* <b>DbU::getResolution</b>
|
||||
* Related functions :
|
||||
* <b>DbU::getResolution()</b>
|
||||
*
|
||||
* \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 :
|
||||
* <ul>
|
||||
* <li><b>DbU::setRealsPerLambda()</b>
|
||||
* <li><b>DbU::getRealsPerLambda()</b>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* \section secDbUGrid Grid
|
||||
|
@ -55,19 +81,33 @@
|
|||
*
|
||||
* \section secDbUTranslators Translators
|
||||
*
|
||||
* Translate a DbU::Unit into grid or lambda length :
|
||||
* <ul>
|
||||
* <li><b>DbU::getUnit</b>
|
||||
* <li><b>DbU::getValue</b>
|
||||
* <li><b>DbU::getValueString</b>
|
||||
* <li><b>long DbU::getDb (DbU::Unit u)</b>
|
||||
* <li><b>double DbU::getReal (DbU::Unit u)</b>
|
||||
* <li><b>double DbU::getLambda(DbU::Unit u)</b>
|
||||
* </ul>
|
||||
*
|
||||
* Translate a lambda length into a DbU::Unit :
|
||||
* <ul>
|
||||
* <li><b>DbU::Unit DbU::db(long u)</b>
|
||||
* <li><b>DbU::Unit DbU::real(double u)</b>
|
||||
* <li><b>DbU::Unit DbU::lambda(double u)</b>
|
||||
* </ul>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*! \ingroup DbU
|
||||
/*! \ingroup DbUGroup
|
||||
*/
|
||||
// \{
|
||||
|
||||
/*! \class DbU
|
||||
* \brief DataBase Unit managment (\b API).
|
||||
*
|
||||
* <b>Explanations about this class are here \ref DbUGroup.</b>
|
||||
*/
|
||||
|
||||
/* \function bool DbU::isOnGrid(const Unit& unit, int n = 1);
|
||||
* \Return \true if the unit is on grid, else \false. The argument
|
||||
* \c \<n\> 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 \<s\> argument value.
|
||||
*/
|
||||
|
||||
/* \function DbU::Unit getUnit(double value);
|
||||
/*! \function void DbU::setRealsPerLambda(double realsPerLambda);
|
||||
* \Return Sets how many reals (founder grid steps) makes one <i>lambda</i>.
|
||||
* It must be an event integer otherwise an exception is thrown.
|
||||
*/
|
||||
|
||||
/*! \function double DbU::getRealsPerLambda();
|
||||
* \Return How many reals (founder grid steps) makes one <i>lambda</i>.
|
||||
*/
|
||||
|
||||
/*! \function DbU::Unit DbU::db(long u);
|
||||
* \Return the unit corresponding to the value \c \<value\> 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 <i>real</i> value \c \<value\>
|
||||
* according to the current precision.
|
||||
*/
|
||||
|
||||
/*! \function DbU::Unit DbU::lambda(double value);
|
||||
* \Return the unit corresponding to the <i>symbolic</i> value \c \<value\>
|
||||
* according to the current precision.
|
||||
*/
|
||||
|
||||
/*! \function long DbU::getDb(Unit unit);
|
||||
* \Return the external value associated to the unit \c \<unit\>
|
||||
* 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 \<unit\>.
|
||||
/*! \function double DbU::getReal(Unit unit);
|
||||
* \Return the real value (expressed as a number of founder grid steps)
|
||||
* associated to the unit \c \<unit\> 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 \<unit\> 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 \<unit\>. 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
|
||||
|
|
|
@ -81,7 +81,7 @@
|
|||
<h2 class="classHierarchy">Common Objects</h2>
|
||||
<table class="classHierarchy">
|
||||
<tr><td width="70"></td><td class="normal"><a href="classHurricane_1_1Tabulation.html">Tabulation</a></td></tr>
|
||||
<tr><td width="70"></td><td class="normal"><a href="group__Unit.html">Unit</a></td></tr>
|
||||
<tr><td width="70"></td><td class="normal"><a href="group__DbUGroup.html">Unit</a></td></tr>
|
||||
<tr><td width="70"></td><td class="normal"><a href="classHurricane_1_1Point.html">Point</a></td></tr>
|
||||
<tr><td width="70"></td><td class="normal"><a href="classHurricane_1_1Box.html">Box</a></td></tr>
|
||||
<tr><td width="70"></td><td class="normal"><a href="classHurricane_1_1Interval.html">Interval</a></td></tr>
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<ul>
|
||||
<li><b><a href="group__Generalities.html">Generalities</a></b><br>
|
||||
Naming conventions, Utilitarians, Generic Functions.
|
||||
<li><b><a href="group__Unit.html">Unit</a></b><br>
|
||||
<li><b><a href="group__DbUGroup.html">DbU/Unit</a></b><br>
|
||||
Object/Type used to model all coordinates in <a href="namespaceHurricane.html">Hurricane</a>.
|
||||
<li><b><a href="customHierarchy.html">Synthetic Class Hierarchy.</a></b>
|
||||
<li><b><a href="hierarchy.html">Complete Class Hierarchy (doxygen).</a></b>
|
||||
|
|
|
@ -130,6 +130,12 @@ void DBo::_preDestroy()
|
|||
// trace_out();
|
||||
}
|
||||
|
||||
string DBo::_getTypeName () const
|
||||
// ******************************
|
||||
{
|
||||
return "DBo";
|
||||
}
|
||||
|
||||
string DBo::_getString() const
|
||||
// ***************************
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;};
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -830,6 +830,57 @@ template<typename Element, typename Compare>
|
|||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Class : "SlotAdapterSet".
|
||||
|
||||
template<typename Element, typename Compare>
|
||||
class PointerSlotAdapter<set<Element,Compare> > : public SlotAdapter {
|
||||
|
||||
// Attributes.
|
||||
protected:
|
||||
set<Element,Compare>* _s;
|
||||
|
||||
// Constructor.
|
||||
public:
|
||||
PointerSlotAdapter ( set<Element,Compare>* m ) : _s(m) {};
|
||||
|
||||
// Destructor.
|
||||
public:
|
||||
virtual ~PointerSlotAdapter () {};
|
||||
|
||||
// Slot Management.
|
||||
public:
|
||||
virtual string _getTypeName () const { return "<PointerSlotAdapter<const set<Element>>"; };
|
||||
virtual string _getString () const;
|
||||
virtual Record* _getRecord () const;
|
||||
};
|
||||
|
||||
|
||||
template<typename Element, typename Compare>
|
||||
inline string PointerSlotAdapter<set<Element,Compare> >::_getString () const {
|
||||
string name = "set<Element>:";
|
||||
return name + getString(_s->size());
|
||||
}
|
||||
|
||||
|
||||
template<typename Element, typename Compare>
|
||||
inline Record* PointerSlotAdapter<set<Element,Compare> >::_getRecord () const {
|
||||
Record* record = NULL;
|
||||
if ( !_s->empty() ) {
|
||||
record = new Record ( "set<Element>" );
|
||||
unsigned n = 1;
|
||||
typename set<Element,Compare>::const_iterator iterator = _s->begin();
|
||||
while ( iterator != _s->end() ) {
|
||||
record->add ( getSlot(getString(n++), *iterator) );
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Class : "SlotAdapterMultiSet".
|
||||
|
||||
|
|
Loading…
Reference in New Issue