Logo ROOT   6.07/09
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 #ifndef ROOT_TError //'ROOT-style' inclusion guards.
9 #include "TError.h"
10 #endif
11 #ifndef ROOT_TROOT
12 #include "TROOT.h"
13 #endif
14 
15 namespace ROOT {
16 namespace GLTutorials {
17 
18 //Type T is some integer type - either Int_t or a Color_t as you wish.
19 
20 //___________________________________________________________
21 template <typename T>
22 inline T FindFreeCustomColorIndex(T start = 1000)
23 {
24  if (!gROOT) {
25  //AH??? WHAT??? Should never happen! :)
26  ::Error("FindFreeCustomColorIndex", "gROOT is null");
27  return -1;
28  }
29  //Some (probably stupid) assumption about the TColor -
30  //I'm trying to find some 'free' index in the range [1000, 10000).
31  //Int_t(1000) - well, to make some exotic platform happy (if Int_t != int).
32  for (Int_t i = std::max(start, T(1000)), e = 10000; i < e; ++i)
33  if (!gROOT->GetColor(i))
34  return i;
35 
36  ::Error("FindFreeCustomColorIndex", "no index found");
37 
38  return -1;
39 }
40 
41 //
42 //___________________________________________________________
43 template <typename T, unsigned N>
44 inline unsigned FindFreeCustomColorIndices(T (&indices)[N])
45 {
46  //All or none.
47  T tmp[N] = {};
48  tmp[0] = FindFreeCustomColorIndex<T>();
49  if (tmp[0] == -1)//Not found.
50  return 0;
51 
52  unsigned nFound = 1;
53  for (; nFound < N; ++nFound) {
54  tmp[nFound] = FindFreeCustomColorIndex(tmp[nFound - 1] + 1);//the next free color index.
55  if (tmp[nFound] == -1)
56  break;
57  }
58 
59  if (nFound == N)
60  std::copy(tmp, tmp + N, indices);
61 
62  return nFound;
63 }
64 
65 }//GLTutorials
66 }//ROOT
67 
68 #endif
unsigned FindFreeCustomColorIndices(T(&indices)[N])
Definition: customcolorgl.h:44
T FindFreeCustomColorIndex(T start=1000)
Definition: customcolorgl.h:22
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
double T(double x)
Definition: ChebyshevPol.h:34
#define N
#define gROOT
Definition: TROOT.h:364
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.