OpenFPM_io  0.2.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Functions Variables Typedefs
util.hpp
1 /*
2  * util.hpp
3  *
4  * Created on: May 7, 2015
5  * Author: Pietro Incardona
6  */
7 
8 #include "config.h"
9 
10 #include "util/SimpleRNG.hpp"
11 
12 #ifndef UTIL_HPP_
13 #define UTIL_HPP_
14 
15 #include <boost/iostreams/device/mapped_file.hpp>
16 
17 
26 static inline bool compare(std::string file1, std::string file2)
27 {
28  boost::iostreams::mapped_file_source f1(file1);
29  boost::iostreams::mapped_file_source f2(file2);
30 
31  if( f1.size() == f2.size() && std::equal(f1.data(), f1.data() + f1.size(), f2.data()) )
32  return true;
33  else
34  return false;
35 }
36 
37 struct RGB
38 {
39  float R;
40  float G;
41  float B;
42 
43  std::string toString()
44  {
45  return std::to_string(R) + " " + std::to_string(G) + " " + std::to_string(B);
46  }
47 };
48 
70 static inline struct RGB getColor(int group, SimpleRNG & d)
71 {
72  struct RGB col;
73 
74  float s = (float)d.GetUniform();
75 
76  group = group % 12;
77 
78 #ifdef ON_IO_UNIT_TESTS
79  s = 0.5;
80 #endif
81 
82  if (group == 0)
83  {
84  col.R = s/2 + 0.5;
85  col.G = 0.0;
86  col.B = 0.0;
87  }
88  else if (group == 1)
89  {
90  col.R = 0.0;
91  col.G = s/2 + 0.5;
92  col.B = 0.0;
93  }
94  else if (group == 2)
95  {
96  col.R = 0.0;
97  col.G = 0.0;
98  col.B = s;
99  }
100  else if (group == 3)
101  {
102  col.R = s/2 + 0.5;
103  col.G = s/2 + 0.5;
104  col.B = 0.0;
105  }
106  else if (group == 4)
107  {
108  col.R = s/2 + 0.5;
109  col.G = 0.0;
110  col.B = s/2 + 0.5;
111  }
112  else if (group == 5)
113  {
114  col.R = 0.0;
115  col.G = s/2 + 0.5;
116  col.B = s/2 + 0.5;
117  }
118  else if (group == 6)
119  {
120  col.R = s/2 + 0.5;
121  col.G = s/4 + 0.5;
122  col.B = 0.0;
123  }
124  else if (group == 7)
125  {
126  col.R = s/4 + 0.5;
127  col.G = s/2 + 0.5;
128  col.B = 0.0;
129  }
130  else if (group == 8)
131  {
132  col.R = 0.0;
133  col.G = s/2 + 0.5;
134  col.B = s/4 + 0.5;
135  }
136  else if (group == 9)
137  {
138  col.R = 0.0;
139  col.G = s/4 + 0.5;
140  col.B = s/2 + 0.5;
141  }
142  else if (group == 10)
143  {
144  col.R = s/4 + 0.5;
145  col.G = 0.0;
146  col.B = s/2 + 0.5;
147  }
148  else if (group == 11)
149  {
150  col.R = s/2 + 0.5;
151  col.G = 0.0;
152  col.B = s/4 + 0.5;
153  }
154 
155  return col;
156 }
157 
164 static inline bool hasEnding (std::string const &fullString, std::string const &ending)
165 {
166  if (fullString.length() >= ending.length())
167  {return (0 == fullString.compare (fullString.length() - ending.length(), ending.length(), ending));}
168  else
169  {return false;}
170 }
171 
172 #endif /* UTIL_HPP_ */
Definition: util.hpp:37