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

Utility.h

Go to the documentation of this file.
00001 #ifndef CORONA_UTILITY_H
00002 #define CORONA_UTILITY_H
00003 
00004 
00005 #include <algorithm>
00006 #include "corona.h"
00007 #include "Types.h"
00008 
00009 
00010 #define COR_EXPORT(ret)  COR_FUNCTION(ret)
00011 
00012 
00013 #if defined(_MSC_VER) && _MSC_VER <= 1200
00014 
00015 // define our own std::min and std::max in VC6
00016 namespace std {
00017   template<typename T>
00018   T min(T a, T b) {
00019     return a < b ? a : b;
00020   }
00021   template<typename T>
00022   T max(T a, T b) {
00023     return a > b ? a : b;
00024   }
00025 }
00026 
00027 #endif
00028 
00029 
00030 namespace corona {
00031 
00032 
00033   template<typename T>
00034   class auto_array {
00035   public:
00036     explicit auto_array(T* initial = 0) {
00037       array = initial;
00038     }
00039     
00040     ~auto_array() {
00041       delete[] array;
00042     }
00043 
00044     operator T*() const {
00045       return array;
00046     }
00047 
00048     T* get() const {
00049       return array;
00050     }
00051 
00052     T* release() {
00053       T* old = array;
00054       array = 0;
00055       return old;
00056     }
00057 
00058     auto_array<T>& operator=(T* a) {
00059       if (array != a) {
00060         delete array;
00061         array = a;
00062       }
00063       return *this;
00064     }
00065 
00066   private:
00067     T* array;
00068   };
00069 
00070 
00071   inline u16 read16_le(const byte* b) {
00072     return b[0] + (b[1] << 8);
00073   }
00074 
00075   inline void write16_le(byte* b, u16 value) {
00076     b[0] = value & 0xFF;
00077     b[1] = value >> 8;
00078   }
00079 
00080   inline u16 read16_be(const byte* b) {
00081     return (b[0] << 8) + b[1];
00082   }
00083 
00084   inline void write16_be(byte* b, u16 value) {
00085     b[0] = value >> 8;
00086     b[1] = value & 0xFF;
00087   }
00088 
00089   inline u32 read32_le(const byte* b) {
00090     return read16_le(b) + (read16_le(b + 2) << 16);
00091   }
00092 
00093   inline u32 read32_be(const byte* b) {
00094     return (read16_be(b) << 16) + read16_be(b + 2);
00095   }
00096 
00097 
00098   struct RGB {
00099     byte red;
00100     byte green;
00101     byte blue;
00102   };
00103 
00104   struct RGBA {
00105     byte red;
00106     byte green;
00107     byte blue;
00108     byte alpha;
00109   };
00110 
00111   struct BGR {
00112     byte blue;
00113     byte green;
00114     byte red;
00115   };
00116 
00117   struct BGRA {
00118     byte blue;
00119     byte green;
00120     byte red;
00121     byte alpha;
00122   };
00123 
00124 }
00125 
00126 
00127 #endif

Generated on Thu Oct 2 12:59:32 2003 for corona by doxygen1.3-rc1