Logo ROOT   6.14/05
Reference Guide
customcolorgl.h
Go to the documentation of this file.
1 //Author: Timur Pocheptsov, 02/03/2014.
2 
3 #ifndef CUSTOMCOLORGL_INCLUDED
4 #define CUSTOMCOLORGL_INCLUDED
5 
6 #include <algorithm>
7 
8 #include "TError.h"
9 #include "TROOT.h"
10 
11 namespace ROOT {
12 namespace GLTutorials {
13 
14 //Type T is some integer type - either Int_t or a Color_t as you wish.
15 
16 //___________________________________________________________
17 template <typename T>
18 inline T FindFreeCustomColorIndex(T start = 1000)
19 {
20  if (!gROOT) {
21  //AH??? WHAT??? Should never happen! :)
22  ::Error("FindFreeCustomColorIndex", "gROOT is null");
23  return -1;
24  }
25  //Some (probably stupid) assumption about the TColor -
26  //I'm trying to find some 'free' index in the range [1000, 10000).
27  //Int_t(1000) - well, to make some exotic platform happy (if Int_t != int).
28  for (Int_t i = std::max(start, T(1000)), e = 10000; i < e; ++i)
29  if (!gROOT->GetColor(i))
30  return i;
31 
32  ::Error("FindFreeCustomColorIndex", "no index found");
33 
34  return -1;
35 }
36 
37 //
38 //___________________________________________________________
39 template <typename T, unsigned N>
40 inline unsigned FindFreeCustomColorIndices(T (&indices)[N])
41 {
42  //All or none.
43  T tmp[N] = {};
44  tmp[0] = FindFreeCustomColorIndex<T>();
45  if (tmp[0] == -1)//Not found.
46  return 0;
47 
48  unsigned nFound = 1;
49  for (; nFound < N; ++nFound) {
50  tmp[nFound] = FindFreeCustomColorIndex(tmp[nFound - 1] + 1);//the next free color index.
51  if (tmp[nFound] == -1)
52  break;
53  }
54 
55  if (nFound == N)
56  std::copy(tmp, tmp + N, indices);
57 
58  return nFound;
59 }
60 
61 }//GLTutorials
62 }//ROOT
63 
64 #endif
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:40
T FindFreeCustomColorIndex(T start=1000)
Definition: customcolorgl.h:18
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
#define N
#define gROOT
Definition: TROOT.h:410
int Int_t
Definition: RtypesCore.h:41
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.