31 #include <unordered_map> 32 #include <boost/functional/hash.hpp> 46 bool isZero(std::complex<double> z);
68 int n = x % 16; x /= 16;
69 char d = (n < 10) ?
'0' + n :
'A' + n - 10;
84 inline auto find(
const std::vector<T>& v,
const T& val) -> decltype( v.cbegin() )
86 return std::find(v.cbegin(), v.cend(), val);
97 for (
auto p : v ) {
delete p; }
109 a.reserve(a.size() + b.size());
110 for (
auto e : b ) { a.insert(a.end(), e); }
123 v.erase((index < 0 ? v.end() - 1 : v.begin()) + index);
136 v.insert((index < 0 ? v.end() : v.begin()) + index, e);
147 auto AddAfter(std::vector<T>& v, decltype(v.begin()) it,
const T& elem)->decltype(v.begin())
154 return v.insert(v.begin(), elem);
157 return v.insert(it, elem);
166 template <
typename K,
typename V>
169 for (
auto& kv : kv_map ) {
170 if ( kv.second == value ) {
290 std::string s =
"width: " + std::to_string(
width()) +
", height: " + std::to_string(
height()) +
291 ", x0: " + std::to_string(
x0()) +
", y0: " + std::to_string(
y0());
308 return ( x >=
x0() && x < (
x0() +
width()) &&
327 bool noOverlap = (
x0() - r.
x0()) > r.
width() ||
338 T x0 = min(
x0(), r.
x0());
356 enum { WIDTH, HEIGHT, X0, Y0, SIZE };
363 using StringMap = std::unordered_map<std::string, std::string>;
371 std::size_t seed = 0;
373 boost::hash_combine<T>(seed, n);
386 void msg(
const std::string& m);
389 #define LOG_TRACE_MSG(m) Log::msg(string("") + __FILE__ + ": " + to_string(__LINE__) + ": " + (m)) 390 #define LOG_TRACE_FILE "/tmp/milo.log" 391 #define LOG_TRACE_CLEAR() remove(LOG_TRACE_FILE) 393 #define QUOTE(arg) #arg 394 #define STR(macro) QUOTE(macro) 397 #define INSTALL_PATH /usr/local/milo 400 #define INSTALL_PATH_STR STR(INSTALL_PATH) void eraseElement(std::vector< T > &v, int index)
Definition: util.h:121
void setSize(T x, T y)
Definition: util.h:228
int & x0()
Definition: util.h:237
T area()
Definition: util.h:299
void merge(const Rectangle &r)
Definition: util.h:337
const K searchMapValue(const std::unordered_map< K, V > &kv_map, V value)
Definition: util.h:167
void msg(const std::string &m)
int & y0()
Definition: util.h:243
int x0() const
Definition: util.h:261
bool intersect(const Rectangle &r) const
Definition: util.h:326
int y0() const
Definition: util.h:267
std::unordered_map< std::string, std::string > StringMap
hash map for string => string
Definition: util.h:363
bool inside(T x, T y) const
Definition: util.h:307
std::string toString()
Definition: util.h:288
Rectangle()
Definition: util.h:193
bool isZero(double x)
Definition: milo.cpp:86
int & height()
Definition: util.h:255
std::array< T, SIZE > m_rect
Storage of rectangle parameters.
Definition: util.h:357
void setOrigin(T x0, T y0)
Definition: util.h:221
std::size_t hash_calculate(std::initializer_list< T > l)
Definition: util.h:369
void freeVector(std::vector< T * > &v)
Definition: util.h:95
auto find(const std::vector< T > &v, const T &val) -> decltype(v.cbegin())
Definition: util.h:84
void mergeVectors(std::vector< T > &a, std::vector< T > &b)
Definition: util.h:107
int height() const
Definition: util.h:279
static Rectangle merge(const Rectangle &r1, const Rectangle &r2)
Definition: util.h:348
Rectangle(T x, T y, T x0, T y0)
Definition: util.h:202
bool isInteger(const std::string &n)
int & width()
Definition: util.h:249
std::string to_hexstring(unsigned long x)
Definition: util.h:64
auto AddAfter(std::vector< T > &v, decltype(v.begin()) it, const T &elem) -> decltype(v.begin())
Definition: util.h:147
int width() const
Definition: util.h:273
void insertElement(std::vector< T > &v, int index, const T &e)
Definition: util.h:134
bool inside(Rectangle r) const
Definition: util.h:317