Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

Unit.H

00001 #ifndef UNIT_H
00002 #define UNIT_H
00003 
00004 #include "config.H"
00005 #include "DimensionGroup.H"
00006 
00007 #define CITRUS_PLURAL_NONE      0
00008 #define CITRUS_PLURAL_NORMAL    1
00009 #define CITRUS_PLURAL_SPECIAL   2
00010 
00011 class UnitConfParserState ;
00012 
00013 class Unit {
00014 protected:
00016   char*                 m_name ;
00018   char*                 m_abbr ;
00020   double                m_scale ;
00027   double                m_offsetVal ;
00029   bool                  m_offsetPolicy ;
00031   DimensionGroup*       m_dgrp ;
00033   bool                  m_avoid ;
00035   bool                  m_one ;
00037   bool                  m_prefix ;
00039   int                   m_pluralPolicy ;
00041   char*                 m_pluralName ;
00043   Unit*                 m_next ;
00044 
00045   static Unit*          s_allUnits ;
00046   static Unit*          s_dimensionless ;
00047 
00048   friend class UnitConfParserState ;
00049 public:
00050   Unit( const char* name, const char* abbr, double scale,
00051         DimensionGroup* dgrp ) ;
00052   ~Unit() ;
00053 
00055   void avoid( const bool& state ) { m_avoid = state ; }
00057   bool avoid() { return m_avoid ; }
00059   void prefix( const bool& state ) { m_prefix = state ; }
00061   bool prefix() { return m_prefix ; }
00063   void one( const bool& state ) { m_one = state ; }
00065   bool one() { return m_one ; }
00067   void offset( double val ) 
00068   { m_offsetVal = val ; m_offsetPolicy = (val != 0.0 ? true : false) ; }
00070   bool offsetPolicy() { return m_offsetPolicy ; }
00072   double offsetValue() { return m_offsetVal ; }
00073   void plural( const char* name ) ;
00074   void plural( int type ) ;
00076   int pluralPolicy() { return m_pluralPolicy ; }
00078   char* pluralForm() 
00079   { return (m_pluralPolicy == CITRUS_PLURAL_SPECIAL ? m_pluralName : (char*)0 ); }
00081   char* name() { return m_name ; }
00083   char* abbr() { return m_abbr ; }
00085   DimensionGroup* dgrp() { return m_dgrp ; }
00087   Unit* next() { return m_next ; }
00091   double scale() { return m_scale ; }
00092 
00094   bool operator ==(Unit other) { return strcmp(m_abbr,other.m_abbr) ; }
00095 
00096   static Unit* dimensionless() ;
00097   static Unit* find( const char* ) ;
00098   static Unit* findByFullName( const char* ) ;
00099   static bool initialize( const char* init=0 ) ;
00100   static Unit* first() ;
00101 } ;
00102 
00103 
00104 
00105 #endif // UNIT_H
Citrus C++ Reference Manual  20010520