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

nv_attribute.h

00001 // Copyright NVIDIA Corporation 2002-2004
00002 // TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
00003 // *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
00004 // OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
00005 // AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS
00006 // BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES
00007 // WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS,
00008 // BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS)
00009 // ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS
00010 // BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES 
00011 
00012 #ifndef _nv_attribute_h_
00013 #define _nv_attribute_h_
00014 
00015 #pragma warning (disable:4251) 
00016 
00017 #include <map>
00018 #include <string>
00019 
00020 //  it's not neccessary to document this helper class !
00021 #if ! defined( DOXYGEN_IGNORE )
00022 class nv_attribute
00023 {
00024     typedef std::map<std::string,nv_attribute*> _dico;
00025     typedef _dico::value_type                   _dico_pair;
00026     typedef _dico::iterator                     _dico_it;
00027     typedef _dico::const_iterator               _dico_cit;
00028 public:
00029 
00030     enum
00031     {
00032         NV_FLOAT                = 0x00000001,
00033         NV_CHAR                 = 0x00000002,
00034         NV_UNSIGNED_CHAR        = 0x00000004,
00035         NV_UNSIGNED_INT         = 0x00000008,
00036         NV_INT                  = 0x00000010,
00037         NV_SHORT                = 0x00000040,
00038         
00039         NV_ARRAY                = 0x00010000,
00040         NV_FLOAT_ARRAY          = 0x00010001,
00041         NV_CHAR_ARRAY           = 0x00010002,
00042         NV_UNSIGNED_CHAR_ARRAY  = 0x00010004,
00043         NV_UNSIGNED_INT_ARRAY   = 0x00010008,
00044         NV_INT_ARRAY            = 0x00010010,
00045         NV_ATTRIBUTE_ARRAY      = 0x00010020,
00046         NV_SHORT_ARRAY          = 0x00010040,    
00047         NV_STRING               = 0x00010002,
00048         
00049         NV_UNASSIGNED           = 0xFFFFFFFF
00050     };
00051 
00052     nv_attribute();
00053     nv_attribute(const nv_attribute & attr);
00054     ~nv_attribute();
00055 
00056     // l-value assignation
00057     nv_attribute &          operator=           (const char * str);
00058     nv_attribute &          operator=           (const float & val);
00059     nv_attribute &          operator=           (const unsigned int & val);
00060     nv_attribute &          operator=           (const int & val);
00061     nv_attribute &          operator=           (const unsigned char & val);
00062     nv_attribute &          operator=           (const char & val);
00063     nv_attribute &          operator=           (const short & val);
00064     nv_attribute &          operator=           (const nv_attribute & attr);
00065 
00066     // validation tests
00067     bool                    is_null             () const;
00068     bool                    is_valid            () const;
00069 
00070     // accessor interface
00071     nv_attribute &          operator[]          (const char * name);
00072 
00073     // array assignation
00074     void                    array               (const nv_attribute * attribs, unsigned int size);
00075     void                    array               (const float * fvector, unsigned int size);
00076     void                    array               (const char * str, unsigned int size);
00077     void                    array               (const unsigned char * str, unsigned int size);
00078     void                    array               (const unsigned int * array, unsigned int size);
00079     void                    array               (const int * array, unsigned int size);
00080     void                    array               (const short * array, unsigned int size);
00081     
00082     // r-value accessors...
00083     float                   as_float            () const;
00084     unsigned int            as_unsigned_int     () const;
00085     unsigned int            as_int              () const;
00086     short                   as_word             () const;
00087     unsigned char           as_uchar            () const;
00088     char                    as_char             () const;
00089     const char *            as_char_array       () const;
00090     const unsigned char *   as_unsigned_char_array() const;
00091     const int *             as_int_array        () const;
00092     const unsigned int *    as_unsigned_int_array() const;
00093     const float *           as_float_array      () const;
00094     const short *           as_short_array      () const;
00095     const char *            as_string           () const;
00096     const nv_attribute *    as_attribute_array  () const;
00097 
00098     // retrieve the size array of the array
00099     const unsigned int      get_size            () const;
00100 
00101     // retrieve the type of the attribute
00102     const unsigned int      get_type            () const;
00103 
00104     unsigned int            get_num_attributes  () const;
00105     const char *            get_attribute_name  (unsigned int i) const;
00106     const nv_attribute *    get_attribute       (unsigned int i) const;
00107 
00108     friend std::ostream & operator << (std::ostream& os, const nv_attribute & attr);
00109 
00110 protected:
00111     // delete the container and reset the value to zero
00112     void                    erase               ();
00113     void                    copy_from           (const nv_attribute * attr);
00114 
00115 private: 
00116     // dictionnary
00117     _dico                   _attr;
00118 
00119     // 32 bit union for data storage
00120     union
00121     {
00122         void *              _pdata;
00123         unsigned char       _ubyte;
00124         unsigned char       _byte;
00125         short               _word;
00126         unsigned int        _udword;
00127         unsigned int        _sdword;
00128         float               _float;
00129     };
00130     
00131     // to be only used for arrays only. The size is always in reference to the type.
00132     // example: if the type is float and size is 4, there is 3 floats in the array
00133     unsigned int    _size; 
00134 
00135     // used to tell whether an attribute contains a valid value as well as its type
00136     unsigned int    _flag;
00137 };
00138 #endif  //  DOXYGEN_IGNORE
00139 
00140 #endif // _nv_attribute_h_

Generated on Tue Mar 1 13:19:18 2005 for NVSGSDK by NVIDIA