xlong.h

Go to the documentation of this file.
00001 // $Id: xlong.h 1261 2006-06-06 11:58:26Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 /*
00100  */ 
00101 
00102 /********************************************************************************************
00103 
00104 >   class XLONG
00105 
00106     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00107     Created:    26/4/1993
00108     SeeAlso:    CCMaths.h
00109     SeeAlso:    Xlongasm.h
00110     SeeAlso:    Mul64Div32
00111     Purpose:    
00112         An XLONG is a signed 64-bit value. Its purpose is to represent very large numbers.
00113     Errors:     None.
00114 
00115 ********************************************************************************************/
00116 
00117 #ifndef INC_XLONG
00118 #define INC_XLONG
00119 
00120 class CCAPI fixed16;
00121 
00122 #if defined(USE_NATIVE_XLONG)
00123 
00124 #if defined(__WXMSW__)
00125 typedef __int64         xlong;
00126 #else
00127 typedef INT64       xlong;
00128 #endif
00129 
00130 xlong &operator*=( xlong &, fixed16 );
00131 xlong operator*( const xlong &, fixed16 );
00132 
00133 #else
00134 
00135 class CCAPI xlong
00136 {
00137 private:
00138     UINT32 low;
00139     INT32 high;
00140 public:
00141     // Constructors
00142 
00143     inline xlong() {};              
00144     inline xlong(const xlong&);
00145     inline xlong(INT32);    
00146     inline xlong(INT32);    
00147     
00148     void ToString(String* out) const;
00149 
00150     // Friend Functions - Basic Operators 
00151 
00152     friend xlong CCAPI operator+ (const xlong&, const xlong&);
00153     friend xlong CCAPI operator+ (const xlong&, INT32); 
00154     friend xlong CCAPI operator+ (const xlong&, INT32); 
00155     
00156     friend xlong CCAPI operator- (const xlong&, const xlong&);
00157     friend xlong CCAPI operator- (const xlong&, INT32);  
00158     friend xlong CCAPI operator- (const xlong&, INT32);  
00159     friend xlong CCAPI operator- (const xlong&);
00160     
00161     friend xlong CCAPI operator* (const xlong&, const xlong&);
00162     friend xlong CCAPI operator* (const xlong&, INT32);  
00163     friend xlong CCAPI operator* (const xlong&, INT32);  
00164     friend xlong CCAPI operator* (const xlong&, fixed16);  
00165     
00166     friend xlong CCAPI operator/ (const xlong&, const xlong&);
00167     friend xlong CCAPI operator/ (const xlong&, INT32); 
00168     friend xlong CCAPI operator/ (const xlong&, INT32); 
00169     
00170     friend xlong CCAPI operator>> (const xlong&, UINT32);
00171     friend xlong CCAPI operator<< (const xlong&, UINT32);
00172 
00173     // Relational operators
00174 
00175     friend INT32 CCAPI operator== (const xlong&, const xlong&);
00176     friend INT32 CCAPI operator== (const xlong&, INT32);
00177     friend INT32 CCAPI operator== (const xlong&, INT32);
00178 
00179     friend INT32 CCAPI operator!= (const xlong&, const xlong&);
00180     friend INT32 CCAPI operator!= (const xlong&, INT32);
00181     friend INT32 CCAPI operator!= (const xlong&, INT32);
00182     
00183     friend INT32 CCAPI operator< (const xlong&, const xlong&);
00184     friend INT32 CCAPI operator< (const xlong&, INT32); 
00185     friend INT32 CCAPI operator< (const xlong&, INT32);
00186     
00187     friend INT32 CCAPI operator> (const xlong&, const xlong&);
00188     friend INT32 CCAPI operator> (const xlong&, INT32); 
00189     friend INT32 CCAPI operator> (const xlong&, INT32);
00190     
00191     friend INT32 CCAPI operator<= (const xlong&, const xlong&);
00192     friend INT32 CCAPI operator<= (const xlong&, INT32);
00193     friend INT32 CCAPI operator<= (const xlong&, INT32);
00194     
00195     friend INT32 CCAPI operator>= (const xlong&, const xlong&);
00196     friend INT32 CCAPI operator>= (const xlong&, INT32);
00197     friend INT32 CCAPI operator>= (const xlong&, INT32);
00198 
00199     // Assignment Operators
00200     
00201     xlong& CCAPI operator= (const xlong&);
00202     xlong& CCAPI operator= (INT32);  
00203     
00204     xlong& CCAPI operator+= (const xlong&);
00205     xlong& CCAPI operator+= (INT32); 
00206     
00207     xlong& CCAPI operator-= (const xlong&); 
00208     xlong& CCAPI operator-= (INT32);   
00209     
00210     xlong& CCAPI operator*= (const xlong&); 
00211     xlong& CCAPI operator*= (INT32);
00212     xlong& CCAPI operator*= (fixed16);
00213     
00214     xlong& CCAPI operator/= (const xlong&); 
00215     xlong& CCAPI operator/= (INT32 ); 
00216     
00217     xlong& CCAPI operator<<= (UINT32); 
00218     xlong& CCAPI operator>>= (UINT32); 
00219 
00220     // Increment\Decrement Operators
00221 
00222     xlong& CCAPI operator++ ();                         // prefix
00223     xlong CCAPI operator++ (INT32);                     // postfix   
00224     
00225     xlong& CCAPI operator-- ();                         // prefix 
00226     xlong CCAPI operator-- (INT32);                     // postfix 
00227     
00228     // Integer Conversion
00229 
00230     inline INT32 MakeLong () const;                             
00231     inline INT32 MakeInt () const;
00232     inline double MakeDouble () const;
00233     fixed16 MakeFixed16 () const;
00234             
00235     operator INT32() const { return (INT32)low; }
00236 
00237     void GetHighLow(INT32* pdwHigh, UINT32* pdwLow) const;
00238     void SetHighLow(INT32 dwHigh, UINT32 dwLow);
00239 };
00240 
00241 // Constructors
00242 
00243 /********************************************************************************************
00244 
00245 >   inline XLONG::XLONG () 
00246 
00247     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00248     Created:    26/4/93
00249     Inputs:     None
00250     Outputs:    None
00251     Returns:    None
00252     Purpose:    Default Constructor for the XLONG class. Its do not actually do anything!
00253     Errors:     None.
00254 
00255 ********************************************************************************************/
00256 
00257 /********************************************************************************************
00258 
00259 >   inline XLONG::XLONG (const XLONG& initValue) 
00260 
00261     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00262     Created:    26/4/93
00263     Inputs:     XLONG initilisation value.
00264     Outputs:    None
00265     Returns:    None.
00266     Purpose:    Initialise an XLONG to a specific value
00267     Errors:     None.
00268 
00269 ********************************************************************************************/
00270 /*
00271 Technical notes:
00272 
00273 ********************************************************************************************/
00274 
00275 inline xlong::xlong(const xlong& initValue)
00276 {                
00277     this->low = initValue.low;
00278     this->high = initValue.high;
00279 }
00280 
00281 /********************************************************************************************
00282                         
00283 >   inline XLONG::XLONG (INT32 initValue) 
00284 
00285     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00286     Created:    26/4/93
00287     Inputs:     Long initilisation value.
00288     Outputs:    None
00289     Returns:    None.
00290     Purpose:    Initialise an XLONG to a specific value
00291     Errors:     None.
00292 
00293 ********************************************************************************************/
00294 /*
00295 Technical notes:
00296 
00297 ********************************************************************************************/
00298 
00299 inline xlong::xlong(INT32 initValue)
00300 {                
00301     xlong temp;
00302 
00303     LongToXlong(initValue, temp);       // convert initValue from INT32 to xlong 
00304 
00305     this->low = temp.low;
00306     this->high = temp.high;
00307 }
00308 
00309 /********************************************************************************************
00310                         
00311 >   inline XLONG::XLONG (INT32 initValue) 
00312 
00313     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00314     Created:    26/4/93
00315     Inputs:     Integer initilisation value.
00316     Outputs:    None
00317     Returns:    None.
00318     Purpose:    Initialise an XLONG to a specific value
00319     Errors:     None.
00320 
00321 ********************************************************************************************/
00322 /*
00323 Technical notes:
00324 
00325 ********************************************************************************************/
00326 
00327 inline xlong::xlong(INT32 initValue)
00328 {                
00329     xlong   temp;
00330     INT32   initTemp = initValue;
00331 
00332     LongToXlong(initTemp, temp);        // convert initValue from INT32 to xlong 
00333 
00334     this->low = temp.low;
00335     this->high = temp.high;
00336 }
00337 
00338 /********************************************************************************************
00339 
00340 >   inline INT32 XLONG::MakeLong () const
00341     
00342     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00343     Created:    26/4/93
00344     SeeAlso:    XlonToLong()
00345     Inputs:     None.
00346     Outputs:    None.
00347     Returns:    Long value.
00348     Purpose:    To convert an XLONG value to a INT32. 
00349     Errors:     None.
00350 
00351 ********************************************************************************************/
00352 /*
00353 Technical notes:
00354 
00355 ********************************************************************************************/
00356   
00357 inline INT32 xlong::MakeLong () const
00358 {
00359     return XlongToLong( *this );
00360 }
00361 
00362 /********************************************************************************************
00363 
00364 >   inline INT32 XLONG::MakeInt () const
00365     
00366     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00367     Created:    26/4/93
00368     SeeAlso:    MakeLong
00369     Inputs:     None.
00370     Outputs:    None.
00371     Returns:    INT32 value.
00372     Purpose:    To convert an XLONG value to an integer. 
00373     Errors:     None.
00374         If XLONG is not in the integer range this will produce some unexpected 
00375         results.
00376 
00377 ********************************************************************************************/
00378 /*
00379 Technical notes:
00380 
00381 ********************************************************************************************/
00382 
00383 inline INT32 xlong::MakeInt() const
00384 { 
00385     return (INT32) this->MakeLong();    
00386 }                              
00387 
00388 /********************************************************************************************
00389 
00390 >   inline double XLONG::MakeDouble () const
00391     
00392     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00393     Created:    26/4/93
00394     SeeAlso:    XlongToDouble()
00395     Inputs:     None.
00396     Outputs:    None.
00397     Returns:    INT32 value.
00398     Purpose:    To convert an XLONG value to a double. 
00399     Errors:     None.
00400 
00401 ********************************************************************************************/
00402 /*
00403 Technical notes:
00404 
00405 ********************************************************************************************/
00406 
00407 inline double xlong::MakeDouble() const
00408 {
00409     return XlongToDouble(*this); 
00410 }
00411 
00412 
00413 /********************************************************************************************
00414 >   inline void xlong::GetHighLow(INT32* pdwHigh, UINT32* pdwLow) const
00415 
00416     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00417     Created:    22/4/94
00418     Inputs:     Pointers to a INT32 and UINT32 that will receive the high and low parts
00419                 of the xlong.
00420     Outputs:    -
00421     Returns:    -
00422     Purpose:    Used when serializing XLONGs
00423     Errors:     -
00424     SeeAlso:    xlong::SetHighLow
00425 ********************************************************************************************/
00426 
00427 
00428 inline void xlong::GetHighLow(INT32* pdwHigh, UINT32* pdwLow) const
00429 {
00430     *pdwHigh = high;
00431     *pdwLow = low;
00432 }
00433 
00434 
00435 
00436 /********************************************************************************************
00437 >   inline void xlong::SetHighLow(INT32 dwHigh, UINT32 dwLow)
00438 
00439     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00440     Created:    22/4/94
00441     Inputs:     The high and low part of the xlong
00442     Outputs:    -
00443     Returns:    -
00444     Purpose:    Used when serializing XLONGs.
00445     Errors:     -
00446     SeeAlso:    xlong::GetHighLow
00447 ********************************************************************************************/
00448 
00449 inline void xlong::SetHighLow(INT32 dwHigh, UINT32 dwLow)
00450 {
00451     high = dwHigh;
00452     low = dwLow;
00453 }
00454 
00455 #endif
00456 
00457 // prottypes for maths routines. This must be kept in snyc
00458 // with the maths routines themselves, currently:
00459 // xlong.cpp
00460 
00461 // beware that although references are used to pass some parameters,
00462 // this may not always be the case. For example, if it is more efficient then
00463 // some versions might just pass the parameters directly
00464 
00465 // Note that the some reference parameters get modified by these calls
00466 // Although this is contrary to the Style Guide, this is the only way we can alter
00467 // the calling convention without breaking existing code
00468 
00469 
00470 // These functions are private to the xlong class - no-one else should call them
00471 // hence the use of xlong in lower-case
00472 
00473 extern "C"
00474 {
00475 
00476 // these are dyadic fns which take two input args and return a third
00477     void XlongAdd( const xlong& ,const xlong& , xlong& );
00478     void XlongSub( const xlong& ,const xlong& , xlong& );
00479     void XMul64(   const xlong& ,const xlong& , xlong& );
00480     void XDiv64(   const xlong& ,const xlong& , xlong& );
00481     void XlongAsl64( const xlong& input, INT32 shift, xlong& result);
00482     void XlongAsr64( const xlong& input, INT32 shift, xlong& result);
00483 
00484 // these are dyadic fns who pass a reference which is modified by the calls, hence
00485 // the use of the One postfix on the names
00486     void XlongAddOne( const xlong& , xlong& );
00487     void XlongSubOne( const xlong& , xlong& );
00488     void XMul64One(   const xlong& , xlong& );
00489     void XDiv64One(   const xlong& , xlong& );
00490     void XlongNegOne( xlong& );
00491     void XlongAsl64One( INT32 shift, xlong& result);
00492     void XlongAsr64One( INT32 shift, xlong& result);
00493 
00494 // xlong conversion functions
00495     void LongToXlong( const INT32, xlong& );
00496     INT32 XlongToLong( const xlong& );
00497     double XlongToDouble( const xlong& );
00498     void DoubleToXlong( const double, xlong& );
00499 
00500 // xlong comparison functions
00501     INT32 XlongCmpGT( const xlong& first, const xlong& second);
00502     INT32 XlongCmpGE( const xlong& first, const xlong& second);
00503     INT32 XlongCmpLT( const xlong& first, const xlong& second);
00504     INT32 XlongCmpLE( const xlong& first, const xlong& second);
00505     INT32 XlongCmpEQ( const xlong& first, const xlong& second);
00506     INT32 XlongCmpNE( const xlong& first, const xlong& second);
00507 
00508 // xlong inc & dec functions
00509     void XlongIncrement( xlong& );
00510     void XlongDecrement( xlong& );
00511 
00512 // utility - might be useful to others: should it be in the public block below
00513     void XMul32(INT32, INT32, xlong& );
00514 
00515 // string conversions
00516     void XlongToAscii( const xlong&, LPSTR );
00517     void XlongToUnicode( const xlong&, WCHAR * );
00518 
00519 
00520     void XlongByFixed16One( xlong*, fixed16 );
00521 
00522     
00523 };
00524 
00525 // these functions can be called by others
00526 // although they are prototyped using xlong, params should always be passed as XLONG
00527 // the lower-case version is to allow this file to be included correctly by ccmath.cpp
00528 
00529 extern "C"
00530 {
00531     INT32 Mul32Div32( INT32, INT32, INT32 );
00532 #ifndef WIN32
00533     xlong Mul64Div32( xlong, xlong, INT32);
00534 #endif
00535     void XMatrixCalc( fixed16, const xlong&, fixed16, const xlong&, xlong& );
00536 };
00537 
00538 #endif

Generated on Sat Nov 10 03:47:24 2007 for Camelot by  doxygen 1.4.4