Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGBaseFunctions.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 
00040 #ifndef _OSGBASEFUNCTIONS_H_
00041 #define _OSGBASEFUNCTIONS_H_
00042 #ifdef __sgi
00043 #pragma once
00044 #endif
00045 
00046 #include <math.h>
00047 #include <string.h>
00048 
00049 #ifndef WIN32
00050 #include <strings.h>
00051 #include <unistd.h>
00052 #include <errno.h>
00053 #include <iostream>
00054 #endif
00055 
00056 #ifdef __sun
00057 #include <stdlib.h>
00058 #include <ieeefp.h>
00059 #endif
00060 
00061 #ifdef __sgi
00062 #include <ieeefp.h>
00063 #endif
00064 
00065 #include <OSGConfig.h>
00066 #include <OSGBase.h>
00067 #include <OSGBaseTypes.h>
00068 
00069 #ifdef OSG_USE_STDMATH
00070 #include <cmath>
00071 #endif
00072 
00073 
00074 #include <vector>
00075 #include <string>
00076 #include <iterator>
00077 #include <algorithm>
00078 
00079 #ifdef OSG_STL_HAS_HASH_MAP
00080 #ifdef OSG_USE_HASH_COMPARE
00081 #ifdef OSG_HASH_MAP_AS_EXT
00082 #include <ext/hash_map>
00083 #else
00084 #include <hash_map>
00085 #endif
00086 #endif
00087 #endif
00088 
00089 OSG_BEGIN_NAMESPACE
00090 
00091 /*---------------------------------------------------------------------*/
00092 /*                        Base Math Runtime Functions                  */
00093 
00094 template <class FloatTypeT> inline
00095 typename TypeTraits<FloatTypeT>::RealReturnType
00096     osgsqrt(const FloatTypeT rValue);
00097 
00098 
00099 template <class FloatTypeT> inline
00100 typename TypeTraits<FloatTypeT>::RealReturnType
00101     osgcos(const FloatTypeT rValue);
00102 
00103 
00104 template <class FloatTypeT> inline
00105 typename TypeTraits<FloatTypeT>::RealReturnType
00106     osgsin(const FloatTypeT rValue);
00107 
00108 
00109 template <class FloatTypeT> inline
00110 typename TypeTraits<FloatTypeT>::RealReturnType
00111     osgtan(const FloatTypeT rValue);
00112 
00113 
00114 template <class FloatTypeT> inline
00115 typename TypeTraits<FloatTypeT>::RealReturnType
00116     osgacos(const FloatTypeT rValue);
00117 
00118 
00119 template <class FloatTypeT> inline
00120 typename TypeTraits<FloatTypeT>::RealReturnType
00121     osgasin(const FloatTypeT rValue);
00122 
00123 
00124 template <class FloatTypeT> inline
00125 typename TypeTraits<FloatTypeT>::RealReturnType
00126     osgatan(const FloatTypeT rValue);
00127 
00128 
00129 template <class FloatTypeT> inline
00130 typename TypeTraits<FloatTypeT>::RealReturnType
00131     osgatan2(const FloatTypeT rValue1,
00132              const FloatTypeT rValue2);
00133 
00134 
00135 template <class FloatTypeT> inline
00136 FloatTypeT osgabs(const FloatTypeT rValue);
00137 
00138 
00139 template <class FloatTypeT> inline
00140 typename TypeTraits<FloatTypeT>::RealReturnType
00141     osgpow(const FloatTypeT rValue,
00142            const FloatTypeT rExp);
00143 
00144 
00145 template <class FloatTypeT> inline
00146 typename TypeTraits<FloatTypeT>::RealReturnType
00147     osglog(const FloatTypeT rValue);
00148 
00149 
00150 template <class FloatTypeT> inline
00151 typename TypeTraits<FloatTypeT>::RealReturnType
00152     osgexp(const FloatTypeT rValue);
00153 
00154 
00155 template <class FloatTypeT> inline
00156 typename TypeTraits<FloatTypeT>::RealReturnType
00157     osgfloor(const FloatTypeT rValue);
00158 
00159 template <class FloatTypeT> inline
00160 typename TypeTraits<FloatTypeT>::RealReturnType
00161     osgceil(const FloatTypeT rValue);
00162 
00163 
00164 template <class FloatTypeT> inline
00165 UInt32 osgfinite(const FloatTypeT rValue);
00166 
00167 /*---------------------------------------------------------------------*/
00168 /*                           Min / Max Functions                       */
00169 
00170 template <class TypeT> inline
00171 TypeT osgMin(const TypeT lVal, const TypeT rValue);
00172 
00173 
00174 template <class TypeT> inline
00175 TypeT osgMax(const TypeT lVal, const TypeT rValue);
00176 
00177 
00178 template <class TypeT> inline
00179 TypeT osgClamp(const TypeT minVal, const TypeT val, const TypeT maxVal);
00180 
00181 /*---------------------------------------------------------------------*/
00182 /*                               Swap Functions                        */
00183 
00184 template <class TypeT> inline
00185 void osgSwap(TypeT & lVal, TypeT & rValue);
00186 
00187 /*---------------------------------------------------------------------*/
00188 /*                               Sign Functions                        */
00189 
00190 template <class TypeT> inline
00191 Int8 osgSgn(TypeT val);
00192 
00193 /*---------------------------------------------------------------------*/
00194 /*                           Rad / Degree Functions                    */
00195 
00196 template <class FloatTypeT> inline
00197 typename TypeTraits<FloatTypeT>::RealReturnType
00198     osgdegree2rad(const FloatTypeT rValue);
00199 
00200 
00201 template <class FloatTypeT> inline
00202 typename TypeTraits<FloatTypeT>::RealReturnType
00203     osgrad2degree(const FloatTypeT rValue);
00204 
00205 
00206 template <class FloatTypeT> inline
00207 typename TypeTraits<FloatTypeT>::RealReturnType
00208     deg2rad(const FloatTypeT rValue);
00209 
00210 
00211 template <class FloatTypeT> inline
00212 typename TypeTraits<FloatTypeT>::RealReturnType
00213     rad2deg(const FloatTypeT rValue);
00214 
00215 /*---------------------------------------------------------------------*/
00216 /*                             Power 2 Functions                       */
00217 
00218 template <class TypeT> inline
00219 bool osgispower2(TypeT rValue);
00220 
00221 
00222 template <class TypeT> inline
00223 TypeT osgnextpower2(TypeT rValue);
00224 
00225 
00226 /*---------------------------------------------------------------------*/
00227 /*                   Ccompile Time Functions                           */
00228 
00229 /*---------------------------------------------------------------------*/
00239 template <Int32 uiValue1, Int32 uiValue2>
00240 struct OSG_BASE_DLLMAPPING osgStaticMax
00241 {
00242     enum _iMax { iMax = uiValue1 < uiValue2 ? uiValue2 : uiValue1 };
00243 };
00244 
00245 
00246 #if defined(__sgi) || defined(__linux) || defined(__sun) || defined(darwin) ||\
00247     defined(__hpux)
00248 
00249 /*---------------------------------------------------------------------*/
00259 struct TrueType  {};
00260 
00266 struct FalseType {};
00267 
00274 template<class IConditionV, class IThenT, class IElseT>
00275 struct osgTypeIF
00276 {
00277     typedef IThenT _IRet;
00278     typedef IElseT _IDummyRef;
00279 };
00280 
00287 template<class IThenT, class IElseT>
00288 struct osgTypeIF<FalseType, IThenT, IElseT>
00289 {
00290     typedef IElseT _IRet;
00291     typedef IThenT _IDummyRef;
00292 };
00293 
00294 /*---------------------------------------------------------------------*/
00305 template<bool IConditionV, class IThenT, class IElseT>
00306 struct osgIF
00307 {
00308     typedef IThenT _IRet;
00309     typedef IElseT _IDummyRef;
00310 };
00311 
00318 template<class IThenT, class IElseT>
00319 struct osgIF<false, IThenT, IElseT>
00320 {
00321     typedef IElseT _IRet;
00322     typedef IThenT _IDummyRef;
00323 };
00324 
00325 /*---------------------------------------------------------------------*/
00326 
00327 #else
00328 
00329 /*---------------------------------------------------------------------*/
00338 template <bool IConditionV>
00339 struct osgIFGen
00340 {
00341     template<class IThenT, class IElseT>
00342     struct osgIFSwitch
00343     {
00344         typedef IThenT _IRet;
00345         typedef IElseT _IDummyRef;
00346     };
00347 };
00348 
00353 template <>
00354 struct osgIFGen<false>
00355 {
00356     template<class IThenT, class IElseT>
00357     struct osgIFSwitch
00358     {
00359         typedef IElseT _IRet;
00360         typedef IThenT _IDummyRef;
00361     };
00362 };
00363 
00369 template<bool IConditionV, class IThenT, class IElseT>
00370 struct osgIF
00371 {
00372     typedef typename osgIFGen<IConditionV>::osgIFSwitch<IThenT, 
00373                                                         IElseT>::_IRet _IRet;
00374 };
00375 
00376 #endif
00377 
00378 /*---------------------------------------------------------------------*/
00379 /*                   Case String Runtime Functions                     */
00380 
00381 inline
00382 void stringDup(const Char8 *szInput, Char8 *&szOutput);
00383 
00384 inline
00385 Int32 stringncmp(const Char8 *string1, const Char8 *string2, size_t count);
00386 
00387 inline
00388 Int32 stringlen(const Char8 *string1);
00389 
00390 
00391 inline
00392 Int32 stringcmp(const Char8 *string1, const Char8 *string2);
00393 
00394 inline
00395 Int32 stringcasecmp(const Char8 *string1,
00396                     const Char8 *string2);
00397 
00404 struct LTString
00405 {
00406     bool operator()(const Char8 *s1, const Char8 *s2) const
00407     {
00408         return ::strcmp(s1, s2) < 0;
00409     }
00410 };
00411 
00418 struct EQString
00419 {
00420     bool operator()(const Char8 *s1, const Char8 *s2) const
00421     {
00422         return ::strcmp(s1, s2) == 0;
00423     }
00424 };
00425 
00426 #ifdef OSG_USE_HASH_COMPARE
00427 struct HashCmpString : 
00428     public OSG_STDEXTENSION_NAMESPACE::hash_compare<const Char8 *, LTString>
00429 {
00430     typedef       std::hash_compare<const Char8 *, LTString>   Inherited;
00431     typedef const Char8                                      *_Kty;
00432 
00433     HashCmpString(void) : Inherited() 
00434     {
00435     }
00436 
00437     size_t operator()(const _Kty& _Keyval) const
00438     {
00439         return OSG_STDEXTENSION_NAMESPACE::hash_value<const Char8 *>(_Keyval);
00440     }
00441 
00442     bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const
00443     {
00444         return Inherited::operator()(_Keyval1, _Keyval2);
00445     }
00446 };
00447 #endif
00448 
00449 // String Tokenizer
00450 
00451 struct OSG_BASE_DLLMAPPING string_token_iterator :
00452 #if defined(__GNUC__) && __GNUC__ < 3
00453     public std::input_iterator<std::string, std::ptrdiff_t>
00454 #else
00455     public std::iterator<std::input_iterator_tag, std::string>
00456 #endif
00457 {
00458   public:
00459     string_token_iterator();
00460 
00461     string_token_iterator(const std::string & str_,
00462                           const char        * separator_ = " ");
00463 
00464     string_token_iterator(const string_token_iterator & rhs);
00465 
00466     string_token_iterator & operator++();
00467 
00468     string_token_iterator operator++(int);
00469 
00470     std::string operator*() const;
00471 
00472     bool operator==(const string_token_iterator & rhs) const;
00473 
00474     bool operator!=(const string_token_iterator & rhs) const;
00475 
00476   private:
00477 
00478     void find_next(void);
00479 
00480     const char                   * _separator;
00481     const std::string            * _str;
00482           std::string::size_type   _start;
00483           std::string::size_type   _end;
00484 };
00485 
00486 
00487 
00507 template <class ContentT, class IndexT>
00508 class indirector
00509 {
00510     public:
00511     
00512         indirector(ContentT cont);
00513         
00514         bool operator()(IndexT a, IndexT b);
00515        
00516     private:
00517     
00518         ContentT _cont;
00519 };
00520 
00521 
00522 
00523 /*---------------------------------------------------------------------*/
00524 /*                    Miscellaneous Functions                          */
00525 
00526 template<class VecPntT> inline
00527 UInt32 getMaxIndexAbs3(const VecPntT &v);
00528 
00529 inline
00530 Int32 putenv(Char8 *string);
00531 
00532 inline
00533 void osgsleep(UInt32 millisecs);
00534 
00535 inline
00536 Real32 osgrand(void);
00537 
00538 inline
00539 bool osgIsBigEndian(void);
00540 
00541 #if defined(WIN32) && defined(_MSC_VER) && _MSC_VER <= 1200  // VC6
00542 
00543 inline
00544 std::ostream &operator<<(std::ostream &os, UInt64 v);
00545 
00546 inline
00547 std::ostream &operator<<(std::ostream &os, Int64 v);
00548 
00549 #endif 
00550 
00551 /*---------------------------------------------------------------------*/
00552 /*               big/little endian conversion functions                */
00553 
00554 // host to network
00555 
00556 inline
00557 UInt16 osghtons(UInt16 src);
00558 
00559 inline
00560 UInt32 osghtonl(UInt32 src);
00561 
00562 inline
00563 UInt64 osghtonll(UInt64 src);
00564 
00565 inline
00566 Real32 osghtonf(Real32 src);
00567 
00568 inline
00569 Real64 osghtond(Real64 src);
00570 
00571 inline
00572 Real128 osghtondd(Real128 src);
00573 
00574 // network to host
00575 
00576 inline
00577 UInt16 osgntohs(UInt16 src);
00578 
00579 inline
00580 UInt32 osgntohl(UInt32 src);
00581 
00582 inline
00583 UInt64 osgntohll(UInt64 src);
00584 
00585 inline
00586 Real32 osgntohf(Real32 src);
00587 
00588 inline
00589 Real64 osgntohd(Real64 src);
00590 
00591 inline
00592 Real128 osgntohd(Real128 src);
00593 
00594 /*---------------------------------------------------------------------*/
00595 /*                MemoryObject Reference Count Functions               */
00596 
00597 template <class T> inline
00598 void setRefP  (T *&pObject, T *&pNewObject);
00599 
00600 template <class T> inline
00601 void addRefP  (T *&pObject);
00602 
00603 template <class T> inline
00604 void subRefP  (T *&pObject);
00605 
00606 template <class T> inline
00607 void clearRefP(T *&pObject);
00608 
00609 template <class T> inline
00610 void clearRefPVector (std::vector<T *> &vVector);
00611 
00612 template <class T> inline
00613 void clearRefPVectorP(std::vector<T *> *pVector);
00614 
00615 /*---------------------------------------------------------------------*/
00616 /*                           Initialization                            */
00617 
00621 enum SystemState
00622 {
00623     Startup  = 0x01,
00624     Running  = 0x02,
00625     Shutdown = 0x03
00626 };
00627 
00628 extern OSG_BASE_DLLMAPPING SystemState GlobalSystemState;
00629 
00641 typedef bool (*InitFuncF)(void);
00642 
00653 typedef bool (*ExitFuncF)(void);
00654 
00655 
00662 struct OSG_BASE_DLLMAPPING InitFuncWrapper
00663 {
00664     /*---------------------------------------------------------------------*/
00668     InitFuncWrapper(const InitFuncF func);
00669 
00671 };
00672 
00679 struct OSG_BASE_DLLMAPPING StaticInitFuncWrapper
00680 {
00681     /*---------------------------------------------------------------------*/
00685     StaticInitFuncWrapper(const InitFuncF func);
00686 
00688 };
00689 
00690 
00691 OSG_BASE_DLLMAPPING
00692 void addInitFunction      (InitFuncF initFunc);
00693 
00694 OSG_BASE_DLLMAPPING
00695 void addSystemExitFunction(ExitFuncF exitFunc);
00696 
00697 OSG_BASE_DLLMAPPING
00698 void addPreMPInitFunction (InitFuncF initFunc);
00699 
00700 OSG_BASE_DLLMAPPING
00701 void addPostMPExitFunction(ExitFuncF exitFunc);
00702 
00703 OSG_BASE_DLLMAPPING
00704 void preloadSharedObject(const Char8 *szName);
00705 
00706 OSG_BASE_DLLMAPPING
00707 bool osgInit(Int32 argc, Char8 **argv);
00708 
00709 OSG_BASE_DLLMAPPING
00710 bool osgExit(void);
00711 
00712 OSG_END_NAMESPACE
00713 
00714 #include "OSGBaseFunctions.inl"
00715 
00716 #define OSGBASEFUNCTIONS_HEADER_CVSID "@(#)$Id: $"
00717 
00718 #endif /* OSGBASEFUNCTIONS_H */

Generated on Thu Aug 25 04:01:10 2005 for OpenSG by  doxygen 1.4.3