]>
Commit | Line | Data |
---|---|---|
5a5a1232 | 1 | // $Header$ |
2 | ||
3 | #ifndef REVE_Reve_H | |
4 | #define REVE_Reve_H | |
5 | ||
a8600b56 | 6 | // #include <string> |
7 | #include <exception> | |
51a6ecc6 | 8 | #include <TObject.h> |
5a5a1232 | 9 | #include <TString.h> |
3cc71cfc | 10 | #include <TError.h> |
915dabe1 | 11 | #include <Gtypes.h> |
5a5a1232 | 12 | |
5a5a1232 | 13 | class TVirtualPad; |
14 | class TGeoManager; | |
15 | ||
16 | namespace Reve { | |
17 | ||
51a6ecc6 | 18 | |
19 | /**************************************************************************/ | |
20 | // Exceptions, string functions | |
21 | /**************************************************************************/ | |
22 | ||
a8600b56 | 23 | bool operator==(const TString& t, const std::string& s); |
24 | bool operator==(const std::string& s, const TString& t); | |
25 | ||
26 | class Exc_t : public std::exception, public TString | |
5a5a1232 | 27 | { |
28 | public: | |
29 | Exc_t() {} | |
a8600b56 | 30 | Exc_t(const TString& s) : TString(s) {} |
31 | Exc_t(const char* s) : TString(s) {} | |
32 | Exc_t(const std::string& s); | |
5a5a1232 | 33 | |
a8600b56 | 34 | virtual ~Exc_t() throw () {} |
5a5a1232 | 35 | |
a8600b56 | 36 | virtual const char* what() const throw () { return Data(); } |
5a5a1232 | 37 | |
a8600b56 | 38 | ClassDef(Exc_t, 1); |
5a5a1232 | 39 | }; |
40 | ||
41 | Exc_t operator+(const Exc_t &s1, const std::string &s2); | |
42 | Exc_t operator+(const Exc_t &s1, const TString &s2); | |
43 | Exc_t operator+(const Exc_t &s1, const char *s2); | |
44 | ||
51a6ecc6 | 45 | void WarnCaller(const TString& warning); |
5a5a1232 | 46 | |
915dabe1 | 47 | |
5a5a1232 | 48 | /**************************************************************************/ |
51a6ecc6 | 49 | // Environment, Macro functions |
5a5a1232 | 50 | /**************************************************************************/ |
51 | ||
51a6ecc6 | 52 | void SetupEnvironment(); |
5a5a1232 | 53 | |
f8fae956 | 54 | Bool_t CheckMacro(const Text_t* mac); |
55 | void AssertMacro(const Text_t* mac); | |
56 | void Macro(const Text_t* mac); | |
57 | void LoadMacro(const Text_t* mac); | |
5a5a1232 | 58 | |
51a6ecc6 | 59 | |
5a5a1232 | 60 | /**************************************************************************/ |
51a6ecc6 | 61 | // Local cache for global Pad, GeoManager |
5a5a1232 | 62 | /**************************************************************************/ |
63 | ||
64 | TVirtualPad* PushPad(TVirtualPad* new_gpad=0, Int_t subpad=0); | |
65 | TVirtualPad* PopPad(Bool_t modify_update_p=false); | |
66 | ||
67 | class PadHolder | |
68 | { | |
69 | private: | |
70 | Bool_t fModifyUpdateP; | |
71 | public: | |
72 | PadHolder(Bool_t modify_update_p, TVirtualPad* new_gpad=0, Int_t subpad=0) : | |
73 | fModifyUpdateP(modify_update_p) | |
74 | { PushPad(new_gpad, subpad); } | |
75 | ||
76 | virtual ~PadHolder() { PopPad(fModifyUpdateP); } | |
77 | ||
78 | ClassDef(PadHolder, 0); | |
79 | }; | |
80 | ||
81 | class GeoManagerHolder | |
82 | { | |
83 | private: | |
84 | TGeoManager* fManager; | |
265ecb21 | 85 | |
86 | GeoManagerHolder(const GeoManagerHolder&); // Not implemented | |
87 | GeoManagerHolder& operator=(const GeoManagerHolder&); // Not implemented | |
88 | ||
5a5a1232 | 89 | public: |
90 | GeoManagerHolder(TGeoManager* new_gmgr=0); | |
91 | virtual ~GeoManagerHolder(); | |
92 | ||
93 | ClassDef(GeoManagerHolder, 0); | |
94 | }; | |
95 | ||
51a6ecc6 | 96 | |
97 | /**************************************************************************/ | |
98 | // ReferenceCount base-class (interface) | |
915dabe1 | 99 | /**************************************************************************/ |
100 | ||
101 | class ReferenceCount | |
102 | { | |
103 | protected: | |
104 | Int_t fRefCount; | |
105 | ||
106 | public: | |
107 | ReferenceCount() : fRefCount(0) {} | |
108 | virtual ~ReferenceCount() {} | |
109 | ||
110 | void IncRefCount() { ++fRefCount; } | |
111 | void DecRefCount() { if(--fRefCount <= 0) OnZeroRefCount(); } | |
112 | ||
113 | virtual void OnZeroRefCount() { delete this; } | |
114 | ||
115 | ClassDef(ReferenceCount, 0); | |
116 | }; | |
117 | ||
51a6ecc6 | 118 | |
119 | /**************************************************************************/ | |
120 | // Color, palette management | |
121 | /**************************************************************************/ | |
122 | ||
123 | void ColorFromIdx(Color_t ci, UChar_t* col, Bool_t alpha=kTRUE); | |
124 | void ColorFromIdx(Float_t f1, Color_t c1, Float_t f2, Color_t c2, | |
125 | UChar_t* col, Bool_t alpha=kTRUE); | |
126 | Color_t* FindColorVar(TObject* obj, const Text_t* varname); | |
127 | ||
128 | class RGBAPalette : public TObject, public ReferenceCount | |
129 | { | |
69990b35 | 130 | RGBAPalette(const RGBAPalette&); // Not implemented |
131 | RGBAPalette& operator=(const RGBAPalette&); // Not implemented | |
132 | ||
51a6ecc6 | 133 | protected: |
134 | Int_t fMinVal; | |
135 | Int_t fMaxVal; | |
136 | Int_t fNBins; | |
137 | Bool_t fInterpolate; | |
138 | Bool_t fWrap; | |
139 | ||
69990b35 | 140 | mutable UChar_t* fColorArray; //! |
51a6ecc6 | 141 | |
142 | void SetupColor(Int_t val, UChar_t* pix) const; | |
143 | ||
144 | public: | |
145 | RGBAPalette(); | |
146 | RGBAPalette(Int_t min, Int_t max); | |
147 | RGBAPalette(Int_t min, Int_t max, Bool_t interp, Bool_t wrap); | |
148 | virtual ~RGBAPalette(); | |
149 | ||
150 | void SetupColorArray() const; | |
151 | void ClearColorArray(); | |
152 | ||
153 | UChar_t* ColorFromArray(Int_t val) const; | |
154 | void ColorFromArray(Int_t val, UChar_t* pix, Bool_t alpha=kTRUE) const; | |
155 | ||
156 | Int_t GetMinVal() const { return fMinVal; } | |
157 | Int_t GetMaxVal() const { return fMaxVal; } | |
158 | Bool_t GetInterpolate() const { return fInterpolate; } | |
159 | Bool_t GetWrap() const { return fWrap; } | |
160 | ||
161 | void SetMinMax(Int_t min, Int_t max); | |
162 | void SetInterpolate(Bool_t b); | |
163 | void SetWrap(Bool_t b); | |
164 | ||
165 | ClassDef(RGBAPalette, 1) | |
166 | }; | |
167 | ||
168 | ||
169 | inline UChar_t* RGBAPalette::ColorFromArray(Int_t val) const | |
170 | { | |
171 | if(!fColorArray) SetupColorArray(); | |
172 | if(val < fMinVal) val = fWrap ? ((val+1-fMinVal)%fNBins + fMaxVal) : fMinVal; | |
173 | if(val > fMaxVal) val = fWrap ? ((val-1-fMaxVal)%fNBins + fMinVal) : fMaxVal; | |
174 | return fColorArray + 4 * (val - fMinVal); | |
175 | } | |
176 | ||
177 | inline void RGBAPalette::ColorFromArray(Int_t val, UChar_t* pix, Bool_t alpha) const | |
178 | { | |
179 | UChar_t* c = ColorFromArray(val); | |
180 | pix[0] = c[0]; pix[1] = c[1]; pix[2] = c[2]; | |
181 | if (alpha) pix[3] = c[3]; | |
182 | } | |
183 | ||
184 | /**************************************************************************/ | |
185 | ||
5a5a1232 | 186 | } |
187 | ||
188 | #endif |