ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
customcolor.h
Go to the documentation of this file.
1 //Author: Timur Pocheptsov, 14/1/2014.
2 
3 #ifndef CUSTOMCOLOR_INCLUDED
4 #define CUSTOMCOLOR_INCLUDED
5 
6 #include <algorithm>
7 
8 #ifndef ROOT_TError //'ROOT-style' inclusion guards.
9 #include "TError.h"
10 #endif
11 #ifndef ROOT_Rtypes
12 #include "Rtypes.h"
13 #endif
14 #ifndef ROOT_TROOT
15 #include "TROOT.h"
16 #endif
17 
18 namespace ROOT {
19 namespace CocoaTutorials {
20 
21 //___________________________________________________________
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  for (Color_t i = std::max(start, Color_t(1000)), e = 10000; i < e; ++i)
32  if (!gROOT->GetColor(i))
33  return i;
34 
35  ::Error("FindFreeCustomColorIndex", "no index found");
36 
37  return -1;
38 }
39 
40 //
41 //Ho-ho-ho! Say good-bye to CINT and hello CLING ... and good old templates!!!
42 //___________________________________________________________
43 template <unsigned N>
44 inline unsigned FindFreeCustomColorIndices(Color_t (&indices)[N])
45 {
46  //All or none.
47  Color_t tmp[N] = {};
48  tmp[0] = FindFreeCustomColorIndex();
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 }//CocoaTutorials
66 }//ROOT
67 
68 #endif
unsigned FindFreeCustomColorIndices(Color_t(&indices)[N])
Definition: customcolor.h:44
#define N
#define gROOT
Definition: TROOT.h:344
Color_t FindFreeCustomColorIndex(Color_t start=1000)
Definition: customcolor.h:22
short Color_t
Definition: RtypesCore.h:79
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.