FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
common.h
1 #ifndef __MY_COMMON_H__
2 #define __MY_COMMON_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of SAFSlib.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include <string>
24 #include <vector>
25 #include <iostream>
26 
27 #include "log.h"
28 #include "common_c.h"
29 
30 #define ASSERT_EQ(x, y) \
31  if ((x) != (y)) { \
32  std::cerr << "x: " << x << ", y: " << y << std::endl;\
33  PRINT_BACKTRACE(); \
34  assert(x == y); \
35  }
36 
37 #define ASSERT_LT(x, y) \
38  if ((x) <= (y)) { \
39  std::cerr << "x: " << x << ", y: " << y << std::endl;\
40  PRINT_BACKTRACE(); \
41  assert(x > y); \
42  }
43 
44 #define ASSERT_LTEQ(x, y) \
45  if ((x) < (y)) { \
46  std::cerr << "x: " << x << ", y: " << y << std::endl;\
47  PRINT_BACKTRACE(); \
48  assert(x >= y); \
49  }
50 
51 #define ASSERT_ST(x, y) \
52  if ((x) >= (y)) { \
53  std::cerr << "x: " << x << ", y: " << y << std::endl;\
54  PRINT_BACKTRACE(); \
55  assert(x < y); \
56  }
57 
58 #define ASSERT_STEQ(x, y) \
59  if ((x) > (y)) { \
60  std::cerr << "x: " << x << ", y: " << y << std::endl;\
61  PRINT_BACKTRACE(); \
62  assert(x <= y); \
63  }
64 
65 #define ABORT_MSG(msg) \
66  do { \
67  BOOST_LOG_TRIVIAL(fatal) << (msg); \
68  PRINT_BACKTRACE(); \
69  abort(); \
70  } while (0)
71 
72 #define TEST(x) \
73  do { \
74  if (!(x)) { \
75  PRINT_BACKTRACE(); \
76  abort(); \
77  } \
78  } while (0)
79 
80 enum {
81  READ,
82  WRITE
83 };
84 
85 template<class T>
86 inline static T min(T v1, T v2)
87 {
88  return v1 > v2 ? v2 : v1;
89 }
90 
91 template<class T>
92 inline static T max(T v1, T v2)
93 {
94  return v1 < v2 ? v2 : v1;
95 }
96 
97 /*
98  * Check if the integer is a power of two.
99  */
100 bool align_check(size_t alignment);
101 
102 static inline std::string itoa(int n)
103 {
104  char buf[32];
105  snprintf(buf, sizeof(buf), "%d", n);
106  return buf;
107 }
108 
109 static inline std::string ltoa(long n)
110 {
111  char buf[32];
112  snprintf(buf, sizeof(buf), "%ld", n);
113  return buf;
114 }
115 
116 long str2size(std::string str);
117 
118 int split_string(const std::string &str, char delim,
119  std::vector<std::string> &strs);
120 
121 bool check_read_content(char *buf, int size, off_t off, int file_id);
122 void create_write_data(char *buf, int size, off_t off, int file_id);
123 int get_num_omp_threads();
124 int get_omp_thread_num();
125 
126 std::string gen_rand_name(size_t len);
127 
128 #endif