pl-nk v0.4.5
Plonk|Plink|Plank are a set of cross-platform C/C++ frameworks for audio software development
plonk_Int24.h
00001 /*
00002  -------------------------------------------------------------------------------
00003  This file is part of the Plink, Plonk, Plank libraries
00004   by Martin Robinson
00005  
00006  http://code.google.com/p/pl-nk/
00007  
00008  Copyright University of the West of England, Bristol 2011-14
00009  All rights reserved.
00010  
00011  Redistribution and use in source and binary forms, with or without
00012  modification, are permitted provided that the following conditions are met:
00013  
00014  * Redistributions of source code must retain the above copyright
00015    notice, this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright
00017    notice, this list of conditions and the following disclaimer in the
00018    documentation and/or other materials provided with the distribution.
00019  * Neither the name of University of the West of England, Bristol nor 
00020    the names of its contributors may be used to endorse or promote products
00021    derived from this software without specific prior written permission.
00022  
00023  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00024  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00025  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00026  DISCLAIMED. IN NO EVENT SHALL UNIVERSITY OF THE WEST OF ENGLAND, BRISTOL BE 
00027  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00028  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 
00029  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00030  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00031  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00032  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00033  
00034  This software makes use of third party libraries. For more information see:
00035  doc/license.txt included in the distribution.
00036  -------------------------------------------------------------------------------
00037  */
00038 
00039 #ifndef PLONK_INT24_H
00040 #define PLONK_INT24_H
00041 
00042 #include "../core/plonk_CoreForwardDeclarations.h"
00043 
00044 #if PLONK_WIN
00045     #pragma pack (push, 1)
00046     #define PLONK_PACKED
00047 #elif PLONK_GCC || PLONK_LLVM || PLANK_APPLE_LLVM
00048     #define PLONK_PACKED __attribute__((packed))
00049 #else
00050     #warning Data packing macros have not been handled for this build system
00051 #endif
00052 
00058 class Int24
00059 {
00060 public:
00061     typedef PlankI24 Internal;
00062     
00063     Int24() throw();
00064     Int24 (const char value) throw();
00065     Int24 (const short value) throw();
00066     Int24 (const int value) throw();
00067     Int24 (const LongLong value) throw();
00068     Int24 (const float value) throw();
00069     Int24 (const double value) throw();
00070 
00071     Int24 (const Internal value) throw();
00072     
00073     template<class OtherType>
00074     Int24 (const OtherType value) throw()
00075     :   data (pl_ConvertIToI24 (int (value)))
00076     {
00077     }
00078     
00079     Int24 (Int24 const& copy) throw();
00080     Int24& operator= (Int24 const& other) throw();
00081     
00082     template<class OtherType>
00083     Int24& operator= (const OtherType other) throw()
00084     {
00085         data = pl_ConvertIToI24 (int (other));
00086         return *this;        
00087     }
00088 
00089     operator char() const throw();
00090     operator short() const throw();
00091     operator int() const throw();
00092     operator LongLong() const throw();
00093     operator float() const throw();
00094     operator double() const throw();
00095     operator Internal() const throw();
00096     
00097     int toInt() const throw();
00098     int toShort() const throw();
00099     float toFloat() const throw();
00100     double toDouble() const throw();
00101     inline const Internal& getRaw() const throw() { return data; }
00102     
00103     Int24 operator~() const throw();
00104     Int24 operator-() const throw();
00105     Int24& operator++() throw();
00106     Int24& operator--() throw();
00107     Int24 operator++ (int) throw();
00108     Int24 operator-- (int) throw();
00109     
00110     int operator+ (Int24 const& rightOperand) const throw();
00111     int operator- (Int24 const& rightOperand) const throw();
00112     int operator* (Int24 const& rightOperand) const throw();
00113     int operator/ (Int24 const& rightOperand) const throw();
00114     Int24 operator% (Int24 const& rightOperand) const throw();
00115     Int24 operator| (Int24 const& rightOperand) const throw();
00116     Int24 operator& (Int24 const& rightOperand) const throw();
00117     Int24 operator^ (Int24 const& rightOperand) const throw();
00118     
00119     float operator+ (const float rightOperand) const throw();
00120     float operator- (const float rightOperand) const throw();
00121     float operator* (const float rightOperand) const throw();
00122     float operator/ (const float rightOperand) const throw();
00123 
00124     double operator+ (double const& rightOperand) const throw();
00125     double operator- (double const& rightOperand) const throw();
00126     double operator* (double const& rightOperand) const throw();
00127     double operator/ (double const& rightOperand) const throw();
00128 
00129     int operator+ (const int rightOperand) const throw();
00130     int operator- (const int rightOperand) const throw();
00131     int operator* (const int rightOperand) const throw();
00132     int operator/ (const int rightOperand) const throw();
00133 
00134     long operator+ (const long rightOperand) const throw();
00135     long operator- (const long rightOperand) const throw();
00136     long operator* (const long rightOperand) const throw();
00137     long operator/ (const long rightOperand) const throw();
00138 
00139     int operator+ (const short rightOperand) const throw();
00140     int operator- (const short rightOperand) const throw();
00141     int operator* (const short rightOperand) const throw();
00142     int operator/ (const short rightOperand) const throw();
00143     
00144 
00145     LongLong operator+ (LongLong const& rightOperand) const throw();
00146     LongLong operator- (LongLong const& rightOperand) const throw();
00147     LongLong operator* (LongLong const& rightOperand) const throw();
00148     LongLong operator/ (LongLong const& rightOperand) const throw();
00149 
00150     Int24 pow (Int24 const& rightOperand) const throw();
00151     
00152     Int24& operator+= (Int24 const& rightOperand) throw();
00153     Int24& operator-= (Int24 const& rightOperand) throw();
00154     Int24& operator*= (Int24 const& rightOperand) throw();
00155     Int24& operator/= (Int24 const& rightOperand) throw();
00156     Int24& operator%= (Int24 const& rightOperand) throw();
00157     Int24& operator|= (Int24 const& rightOperand) throw();
00158     Int24& operator&= (Int24 const& rightOperand) throw();
00159     Int24& operator^= (Int24 const& rightOperand) throw();
00160     
00161     Int24& operator+= (const float rightOperand) throw();
00162     Int24& operator-= (const float rightOperand) throw();
00163     Int24& operator*= (const float rightOperand) throw();
00164     Int24& operator/= (const float rightOperand) throw();
00165 
00166     Int24& operator+= (double const& rightOperand) throw();
00167     Int24& operator-= (double const& rightOperand) throw();
00168     Int24& operator*= (double const& rightOperand) throw();
00169     Int24& operator/= (double const& rightOperand) throw();
00170 
00171     Int24& operator+= (const short rightOperand) throw();
00172     Int24& operator-= (const short rightOperand) throw();
00173     Int24& operator*= (const short rightOperand) throw();
00174     Int24& operator/= (const short rightOperand) throw();
00175 
00176     Int24& operator+= (const int rightOperand) throw();
00177     Int24& operator-= (const int rightOperand) throw();
00178     Int24& operator*= (const int rightOperand) throw();
00179     Int24& operator/= (const int rightOperand) throw();
00180 
00181     Int24& operator+= (const long rightOperand) throw();
00182     Int24& operator-= (const long rightOperand) throw();
00183     Int24& operator*= (const long rightOperand) throw();
00184     Int24& operator/= (const long rightOperand) throw();
00185     
00186     bool operator== (Int24 const& rightOperand) const throw();
00187     bool operator!= (Int24 const& rightOperand) const throw();
00188     bool operator< (Int24 const& rightOperand) const throw();
00189     bool operator<= (Int24 const& rightOperand) const throw();
00190     bool operator> (Int24 const& rightOperand) const throw();
00191     bool operator>= (Int24 const& rightOperand) const throw();
00192 
00193     bool operator&& (Int24 const& rightOperand) const throw();
00194     bool operator|| (Int24 const& rightOperand) const throw();
00195 
00196     Int24 operator<< (const int shift) const throw();
00197     Int24 operator>> (const int shift) const throw();
00198     Int24& operator<<= (const int shift) throw();
00199     Int24& operator>>= (const int shift) throw();
00200     
00201 #if !PLONK_ANDROID
00202     friend std::istream& operator>> (std::istream &inputStream, Int24& value);
00203     friend std::ostream& operator<< (std::ostream &outputStream, Int24 const& value);
00204 #endif
00205     
00206 private:
00207     Internal data;
00208 } PLONK_PACKED;
00209 
00210 #if PLANK_WIN
00211 #pragma pack (pop)
00212 #endif
00213 
00214 #undef PLONK_PACKED
00215 
00216 template<> class BinaryOpTypeUtility<double,Int24>   { public: typedef double CalcType; };
00217 template<> class BinaryOpTypeUtility<Int24,double>   { public: typedef double CalcType; };
00218 template<> class BinaryOpTypeUtility<char,Int24>     { public: typedef int CalcType; };
00219 template<> class BinaryOpTypeUtility<Int24,char>     { public: typedef int CalcType; };
00220 template<> class BinaryOpTypeUtility<short,Int24>    { public: typedef LongLong CalcType; };
00221 template<> class BinaryOpTypeUtility<Int24,short>    { public: typedef LongLong CalcType; };
00222 template<> class BinaryOpTypeUtility<Int24,LongLong> { public: typedef LongLong CalcType; };
00223 template<> class BinaryOpTypeUtility<LongLong,Int24> { public: typedef LongLong CalcType; };
00224 template<> class BinaryOpTypeUtility<Int24,Int24>    { public: typedef LongLong CalcType; };
00225 
00226 template<class OtherType>
00227 class Int24Ops
00228 {
00229 public:
00230     typedef typename BinaryOpTypeUtility<OtherType,Int24>::CalcType CalcType;
00231     typedef CalcType ReturnType;
00232 
00233     static inline ReturnType addop (OtherType const& leftOperand, Int24 const& rightOperand) throw()
00234     {
00235         return CalcType (leftOperand) + CalcType (rightOperand);
00236     }
00237     
00238     static inline ReturnType subop (OtherType const& leftOperand, Int24 const& rightOperand) throw()
00239     {
00240         return CalcType (leftOperand) - CalcType (rightOperand);
00241     }
00242 
00243     static inline ReturnType mulop (OtherType const& leftOperand, Int24 const& rightOperand) throw()
00244     {
00245         return CalcType (leftOperand) * CalcType (rightOperand);
00246     }
00247 
00248     static inline ReturnType divop (OtherType const& leftOperand, Int24 const& rightOperand) throw()
00249     {
00250         return CalcType (leftOperand) / CalcType (rightOperand);
00251     }
00252 
00253 };
00254 
00255 #if !PLONK_ANDROID
00256 std::istream& operator>> (std::istream &inputStream, Int24& value);
00257 std::ostream& operator<< (std::ostream &outputStream, Int24 const& value);
00258 #endif
00259 
00260 float operator+ (const float leftOperand, Int24 const& rightOperand) throw();
00261 float operator- (const float leftOperand, Int24 const& rightOperand) throw();
00262 float operator* (const float leftOperand, Int24 const& rightOperand) throw();
00263 float operator/ (const float leftOperand, Int24 const& rightOperand) throw();
00264 
00265 double operator+ (double const& leftOperand, Int24 const& rightOperand) throw();
00266 double operator- (double const& leftOperand, Int24 const& rightOperand) throw();
00267 double operator* (double const& leftOperand, Int24 const& rightOperand) throw();
00268 double operator/ (double const& leftOperand, Int24 const& rightOperand) throw();
00269 
00270 int operator+ (const int leftOperand, Int24 const& rightOperand) throw();
00271 int operator- (const int leftOperand, Int24 const& rightOperand) throw();
00272 int operator* (const int leftOperand, Int24 const& rightOperand) throw();
00273 int operator/ (const int leftOperand, Int24 const& rightOperand) throw();
00274 
00275 int operator+ (const short leftOperand, Int24 const& rightOperand) throw();
00276 int operator- (const short leftOperand, Int24 const& rightOperand) throw();
00277 int operator* (const short leftOperand, Int24 const& rightOperand) throw();
00278 int operator/ (const short leftOperand, Int24 const& rightOperand) throw();
00279 
00280 long operator+ (const long leftOperand, Int24 const& rightOperand) throw();
00281 long operator- (const long leftOperand, Int24 const& rightOperand) throw();
00282 long operator* (const long leftOperand, Int24 const& rightOperand) throw();
00283 long operator/ (const long leftOperand, Int24 const& rightOperand) throw();
00284 
00285 LongLong operator+ (LongLong const& leftOperand, Int24 const& rightOperand) throw();
00286 LongLong operator- (LongLong const& leftOperand, Int24 const& rightOperand) throw();
00287 LongLong operator* (LongLong const& leftOperand, Int24 const& rightOperand) throw();
00288 LongLong operator/ (LongLong const& leftOperand, Int24 const& rightOperand) throw();
00289 
00290 
00291 
00292 #endif // PLONK_INT24_H
 All Classes Functions Typedefs Enumerations Enumerator Properties