mi32/unitconv.h

Go to the documentation of this file.
00001 /**
00002  * \file mi32/unitconv.h
00003  * \brief Include file for unit type selection functions
00004  *
00005  * \if NODOC
00006  * $Id: unitconv.h_v 1.35 2003/10/01 22:13:29 dwilliss Exp $
00007  *
00008  * $Log: unitconv.h_v $
00009  * Revision 1.35  2003/10/01 22:13:29  dwilliss
00010  * doxygen
00011  *
00012  * Revision 1.34  2003/09/22 20:44:58  mju
00013  * Remove last deprecated unit_type (dist).
00014  *
00015  * Revision 1.33  2003/09/15 13:49:56  fileserver!dwilliss
00016  * Doxygen
00017  *
00018  * Revision 1.32  2003/09/05 17:08:04  mju
00019  * Remove stuff replaced by UOM system.
00020  *
00021  * Revision 1.31  2003/08/14 14:30:11  mju
00022  * Make UNIT_TYPE an enum.
00023  * Deprecate old unit type values.
00024  *
00025  * Revision 1.30  2003/06/03 20:08:22  scowan
00026  * Added associate with.
00027  *
00028  * Revision 1.29  2001/06/08 16:55:21  mju
00029  * Add #defines for UNIT_Time_...
00030  *
00031  * Revision 1.28  2001/03/07 15:15:57  scowan
00032  * Fixed lack of include file problem.
00033  *
00034  * Revision 1.27  2001/03/06 15:15:51  mju
00035  * Add another UNITCONV ctor and IniRead/Write methods.
00036  *
00037  * Revision 1.26  2001/02/13 17:47:48  mju
00038  * Use const in ConvertUnit...
00039  *
00040  * Revision 1.25  2000/12/04 18:17:44  mju
00041  * Ignore internal fns in genitor.
00042  * Add standard header comments.
00043  * \endif
00044 **/
00045 
00046 #ifndef INC_MI32_UNITCONV_H
00047 #define INC_MI32_UNITCONV_H
00048 
00049 #ifndef  INC_MI32_STDDEFNS_H
00050    #include <mi32/stddefns.h>
00051 #endif
00052 
00053 #ifndef  INC_MI32_INIDEFNS_H
00054    #include <mi32/inidefns.h>
00055 #endif
00056 
00057 #ifndef  INC_MI32_UOM_H
00058 #include <mi32/uom.h>
00059 #endif
00060 
00061 #ifndef  INC_STRING_H
00062 #include <string.h>     // Includes defn for memset()
00063 #define  INC_STRING_H
00064 #endif
00065 
00066 #ifdef GEOMDLL
00067    #define GEOMLIBEXPORT MI_DLLEXPORT
00068 #else
00069    #define GEOMLIBEXPORT MI_DLLIMPORT
00070 #endif
00071 
00072 
00073 //! Unit conversion parameters.
00074 struct UNITCONV {
00075    // This structure is used extensively within other structure and in DLLs.
00076    // Therefore, members may not be added or removed, nor may non-inline or virtual methods be added.
00077 
00078       double fr_offset;
00079       double to_offset;
00080       double scale;                       //!< Scale factor
00081       UINT8 type;                         //!< UNIT_TYPE_...
00082       UINT8 to;                           //!< Units to convert to, specific to type
00083       UINT8 from;                         //!< Units to convert from, specific to type
00084       UINT8 do_string;
00085 
00086    public:
00087 
00088       //! Default constructor.
00089       UNITCONV (
00090          ) { memset(this,0,sizeof(UNITCONV)); scale = 1.0; }
00091 
00092       //! Construct with specified scale
00093       explicit UNITCONV (
00094          double inscale
00095          ) { memset(this,0,sizeof(UNITCONV)); scale = inscale; }
00096 
00097       //! Construct with specified unit type and units.
00098       inline explicit UNITCONV (
00099          int UnitType,                       //!< Unit type (UNIT_TYPE_...)
00100          int FromCode = 0,                   //!< Units to convert from specific to type
00101          int ToCode = 0                      //!< Units to convert to specific to type
00102          );
00103 
00104       //! Read unit code from INI file and set conversion.
00105       //! This will set the units to convert TO, unit to convert from will be previous 'from' value.
00106       inline void IniRead (
00107          INIHANDLE IniHandle,
00108          const char *IniGroup,
00109          const char *IniName,
00110          int UnitType = -1,
00111          int UnitCode = 0
00112          );
00113 
00114       //! Write unit code to INI file.
00115       void IniWrite (
00116          INIHANDLE IniHandle,
00117          const char *IniGroup,
00118          const char *IniName
00119          ) const { ::IniWrite(IniHandle,IniGroup,IniName,this->to); return; }
00120       
00121    };
00122 
00123 
00124 /*----------------------------------------------------------------------------*/
00125 /*    Date formatting flags                                                   */
00126 /*----------------------------------------------------------------------------*/
00127 
00128 #define  DATECONV_NoCent      0x80
00129 
00130 #define  DATECONV_ORDERMASK   0x03
00131 #define  DATECONV_YMD         0x00
00132 #define  DATECONV_YDM         0x01
00133 #define  DATECONV_MDY         0x02
00134 #define  DATECONV_DMY         0x03
00135 
00136 #define  DATECONV_MONTHMASK   0x0C
00137 #define  DATECONV_MonthNum    0x00
00138 #define  DATECONV_MonthAbbr   0x04
00139 #define  DATECONV_MonthName   0x08
00140 
00141 #define  DATECONV_SEPMASK     0x70
00142 #define  DATECONV_SepNone     0x00
00143 #define  DATECONV_SepSpace    0x10
00144 #define  DATECONV_SepDash     0x20
00145 #define  DATECONV_SepDot      0x30
00146 #define  DATECONV_SepSlash    0x40
00147 #define  DATECONV_SepComma    0x50  //!<  23 January, 1996 
00148 
00149 /*----------------------------------------------------------------------------*/
00150 /*    Functions and Macros                                                    */
00151 /*----------------------------------------------------------------------------*/
00152 
00153 #if defined(__cplusplus)
00154 extern "C" {
00155 #endif
00156 
00157 //!:Associate with "Unit Conversions"
00158 //!\addtogroup UnitConv Unit Conversion
00159 //!@{
00160 
00161 //! Perform unit conversion on numeric value.
00162 //! @return Converted value
00163 GEOMLIBEXPORT double ConvertUnit (
00164    double val,                         //!< Value to convert
00165    const UNITCONV *c
00166    );
00167 
00168 //! Perform inverse unit conversion on numeric value.
00169 //! @return Converted unit
00170 GEOMLIBEXPORT double ConvertUnitInv (
00171    double val,                         //!< Value to convert
00172    const UNITCONV *conv
00173    );
00174 
00175 //! Special unit conversion for string data types (string to number).
00176 //! @return The date as a double in YYYYMMDD format
00177 //! Currently only implements conversion for UNIT_TYPE_DATE.
00178 //! the "to" field of the conv can be any of the following.
00179 //!
00180 //!   \li\b DATECONV_YMD         Year Month Day order
00181 //!   \li\b DATECONV_YDM         Year Day Month order
00182 //!   \li\b DATECONV_MDY         Month Day Year order
00183 //!   \li\b DATECONV_DMY         Day Month Year order
00184 //!
00185 //! Other DATECONV flags can be ORd in too, but will be ignored.
00186 //! It copes with any type of month representation and seperator.
00187 GEOMLIBEXPORT double ConvertUnitStrInv (
00188    char *str,
00189    const UNITCONV *conv
00190    );
00191 
00192 //! Special unit conversion for string data types (number to string).
00193 //! @return str
00194 //! Currently only implements conversion for UNIT_TYPE_DATE.
00195 //! the "to" field of the conv can be any of the following ORd together
00196 //!
00197 //!   \li\b DATECONV_NoCent      2 digit year instead of 4 digit
00198 //!   \li\b DATECONV_YMD         Year Month Day order
00199 //!   \li\b DATECONV_YDM         Year Day Month order
00200 //!   \li\b DATECONV_MDY         Month Day Year order
00201 //!   \li\b DATECONV_DMY         Day Month Year order
00202 //!   \li\b DATECONV_MonthNum    Numeric month values
00203 //!   \li\b DATECONV_MonthAbbr   Use 3 letter month abbreviation
00204 //!   \li\b DATECONV_MonthName   Use full month names
00205 //!   \li\b DATECONV_SepNone     No seperator
00206 //!   \li\b DATECONV_SepSpace    Use space for seperator
00207 //!   \li\b DATECONV_SepDash     Use dash for seperator
00208 //!   \li\b DATECONV_SepDot      Use dot for seperator
00209 //!   \li\b DATECONV_SepSlash    Use slash for seperator
00210 //!   \li\b DATECONV_SepComma    Use comma for seperator
00211 GEOMLIBEXPORT char * ConvertUnitStr (
00212    char *str,
00213    int len,
00214    double val,
00215    const UNITCONV *conv
00216    );
00217 
00218 //! Setup unit conversion structure between units of given type.
00219 //! @return Pointer to specified unit conversion structure
00220 GEOMLIBEXPORT UNITCONV *GetUnitConversion (
00221    int type,                           //!< Unit type (UNIT_TYPE_...)
00222    int fromcode,                       //!< Unit code to convert from
00223    int tocode,                         //!< Unit code to convert to
00224    UNITCONV *conv                      //!< Unit conversion structure to fill in
00225    );
00226 
00227 //! Setup "identity" unit conversion for given type.
00228 //! @return Pointer to specified unit conversion structure
00229 GEOMLIBEXPORT UNITCONV *GetUnitConversionIdentity (
00230    int type,                           //!< Unit type (UNIT_TYPE_...)
00231    UNITCONV *conv                      //!< Unit conversion structure to fill in
00232    );
00233 
00234 #if defined(__cplusplus)
00235 }
00236 #endif
00237 
00238 //! Get name for given unit type/number.
00239 //! @return Localized unit name.
00240 GEOMLIBEXPORT const MISTRING& GetUnitName (
00241    int type,                           //!< Unit type (UNIT_TYPE_...)
00242    int num                             //!< Unit number within type
00243    );
00244 
00245 //! Get "symbol" for given unit type/number.
00246 //! @return Localized unit "symbol".
00247 GEOMLIBEXPORT const MISTRING& GetUnitSymbol (
00248    int type,                           //!< Unit type (UNIT_TYPE_...)
00249    int num                             //!< Unit number within type
00250    );
00251 
00252 #ifndef GENERATING_DOXYGEN_OUTPUT
00253 // Inlines
00254 
00255 inline UNITCONV::UNITCONV (
00256    int UnitType,                       //!< Unit type (UNIT_TYPE_...)
00257    int FromCode,                       //!< Units to convert from specific to type
00258    int ToCode                          //!< Units to convert to specific to type
00259    ) {
00260    GetUnitConversion(UnitType,FromCode,ToCode,this);
00261    }
00262 
00263 inline void UNITCONV::IniRead (
00264    INIHANDLE IniHandle,
00265    const char *IniGroup,
00266    const char *IniName,
00267    int UnitType,
00268    int UnitCode
00269    ) {
00270    if (UnitType == -1) UnitType = this->type;
00271    ::IniRead(IniHandle,IniGroup,IniName,UnitCode);
00272    GetUnitConversion(UnitType,this->from,UnitCode,this);
00273    return;
00274    }
00275 
00276 #endif // GENERATING_DOXYGEN_OUTPUT
00277 
00278 //!@}
00279 
00280 #endif

Generated on Thu Aug 12 06:19:11 2004 for TNTsdk by doxygen 1.3.4-20031026