NCBI C++ ToolKit
promote.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef UTIL_MATH___PROMOTE__HPP
2 #define UTIL_MATH___PROMOTE__HPP
3 
4 /* $Id: promote.hpp 33815 2007-05-04 17:18:18Z kazimird $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistd.hpp>
36 
38 
39 //
40 //
41 // Promotion classes
42 //
43 //
44 
45 // the basic promotion type
46 // we then provide a *lot* of specialized classes to perform the
47 // correct promotions
48 template <typename T, typename U> struct SPromoteTraits
49 {
50 public:
51  typedef T TPromote;
52 };
53 
54 
55 // these defines makes adding new types much easier to understand
56 
57 //
58 // first, a define to promote identical types to themselves
59 #define NCBI_PROMOTE_TRAITS(type) \
60 template<> struct SPromoteTraits< type, type > { \
61 public: \
62  typedef type TPromote; \
63 }
64 
65 
66 //
67 // next, this type handles promotion of unlike types
68 #define NCBI_PROMOTE2_TRAITS(type1,type2,type3) \
69 template<> struct SPromoteTraits< type1, type2 > { \
70 public: \
71  typedef type3 TPromote; \
72 }; \
73 template<> struct SPromoteTraits< type2, type1 > { \
74 public: \
75  typedef type3 TPromote; \
76 }
77 
78 
79 //
80 // this macro makes the syntax a little easier to understand when declaring a
81 // promoted type
82 //
83 #if defined(NCBI_COMPILER_MSVC) && (_MSC_VER <= 1200)
84 # define NCBI_PROMOTE(a,b) SPromoteTraits< a, b >::TPromote
85 #else
86 # define NCBI_PROMOTE(a,b) typename SPromoteTraits< a, b >::TPromote
87 #endif
88 
89 //
90 // comparisons for built-in types
91 // this is needed because we can define the correct sorts of type promotion
92 // for various template classes and global operators
93 //
94 
95 
96 //
97 // promotion of identical types
99 NCBI_PROMOTE_TRAITS(unsigned char);
101 NCBI_PROMOTE_TRAITS(unsigned short);
103 NCBI_PROMOTE_TRAITS(unsigned int);
106 
107 NCBI_PROMOTE2_TRAITS(char, unsigned char, unsigned char);
108 NCBI_PROMOTE2_TRAITS(char, short, short);
109 NCBI_PROMOTE2_TRAITS(char, unsigned short, unsigned short);
110 NCBI_PROMOTE2_TRAITS(char, int, int);
111 NCBI_PROMOTE2_TRAITS(char, unsigned int, unsigned int);
112 NCBI_PROMOTE2_TRAITS(char, float, float);
113 NCBI_PROMOTE2_TRAITS(char, double, double);
114 NCBI_PROMOTE2_TRAITS(unsigned char, short, short);
115 NCBI_PROMOTE2_TRAITS(unsigned char, unsigned short, unsigned short);
116 NCBI_PROMOTE2_TRAITS(unsigned char, int, int);
117 NCBI_PROMOTE2_TRAITS(unsigned char, unsigned int, unsigned int);
118 NCBI_PROMOTE2_TRAITS(unsigned char, float, float);
119 NCBI_PROMOTE2_TRAITS(unsigned char, double, double);
120 NCBI_PROMOTE2_TRAITS(short, unsigned short, unsigned short);
121 NCBI_PROMOTE2_TRAITS(short, int, int);
122 NCBI_PROMOTE2_TRAITS(short, unsigned int, unsigned int);
123 NCBI_PROMOTE2_TRAITS(short, float, float);
124 NCBI_PROMOTE2_TRAITS(short, double, double);
125 NCBI_PROMOTE2_TRAITS(unsigned short, int, int);
126 NCBI_PROMOTE2_TRAITS(unsigned short, unsigned int, unsigned int);
127 NCBI_PROMOTE2_TRAITS(unsigned short, float, float);
128 NCBI_PROMOTE2_TRAITS(unsigned short, double, double);
129 NCBI_PROMOTE2_TRAITS(int, unsigned int, unsigned int);
130 NCBI_PROMOTE2_TRAITS(int, float, float);
131 NCBI_PROMOTE2_TRAITS(int, double, double);
132 NCBI_PROMOTE2_TRAITS(unsigned int, float, float);
133 NCBI_PROMOTE2_TRAITS(unsigned int, double, double);
134 NCBI_PROMOTE2_TRAITS(float, double, double);
135 
136 
138 
139 #endif // UTIL_MATH___PROMOTE___HPP
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define T(s)
Definition: common.h:230
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_PROMOTE2_TRAITS(type1, type2, type3)
Definition: promote.hpp:68
#define NCBI_PROMOTE_TRAITS(type)
Definition: promote.hpp:59
Modified on Fri Sep 20 14:58:10 2024 by modify_doxy.py rev. 669887