Electroneum
Loading...
Searching...
No Matches
epee::misc_utils Namespace Reference

Namespaces

namespace  parse

Classes

struct  less_as_pod
struct  call_befor_die_base
struct  call_befor_die
struct  struct_init
struct  rolling_median_t

Typedefs

typedef boost::shared_ptr< call_befor_die_baseauto_scope_leave_caller

Functions

template<typename t_type>
t_type get_max_t_val (t_type t)
template<typename t_iterator>
t_iterator move_it_forward (t_iterator it, size_t count)
template<typename t_iterator>
t_iterator move_it_backward (t_iterator it, size_t count)
template<class _Ty>
bool is_less_as_pod (const _Ty &_Left, const _Ty &_Right)
bool sleep_no_w (long ms)
template<class type_vec_type>
type_vec_type median (std::vector< type_vec_type > &v)
template<class t_scope_leave_handler>
auto_scope_leave_caller create_scope_leave_handler (t_scope_leave_handler f)
uint64_t get_ns_count ()
uint64_t get_tick_count ()
int call_sys_cmd (const std::string &cmd)
std::string get_thread_string_id ()
bool get_gmt_time (time_t t, struct tm &tm)
std::string get_time_str (const time_t &time_)
std::string get_time_str_v2 (const time_t &time_)
std::string get_time_str_v3 (const boost::posix_time::ptime &time_)
std::string get_internet_time_str (const time_t &time_)
std::string get_time_interval_string (const time_t &time_)

Typedef Documentation

◆ auto_scope_leave_caller

Definition at line 139 of file misc_language.h.

Function Documentation

◆ call_sys_cmd()

int epee::misc_utils::call_sys_cmd ( const std::string & cmd)
inline

Definition at line 94 of file misc_os_dependent.h.

95 {
96 std::cout << "# " << cmd << std::endl;
97
98 FILE * fp ;
99 //char tstCommand[] ="ls *";
100 char path[1000] = {0};
101#if !defined(__GNUC__)
102 fp = _popen(cmd.c_str(), "r");
103#else
104 fp = popen(cmd.c_str(), "r");
105#endif
106 while ( fgets( path, 1000, fp ) != NULL )
107 std::cout << path;
108
109#if !defined(__GNUC__)
110 _pclose(fp);
111#else
112 pclose(fp);
113#endif
114 return 0;
115
116 }

◆ create_scope_leave_handler()

template<class t_scope_leave_handler>
auto_scope_leave_caller epee::misc_utils::create_scope_leave_handler ( t_scope_leave_handler f)

Definition at line 156 of file misc_language.h.

157 {
159 return slc;
160 }
boost::shared_ptr< call_befor_die_base > auto_scope_leave_caller
Here is the caller graph for this function:

◆ get_gmt_time()

bool epee::misc_utils::get_gmt_time ( time_t t,
struct tm & tm )
inline

Definition at line 128 of file misc_os_dependent.h.

129 {
130#ifdef _WIN32
131 return gmtime_s(&tm, &t);
132#else
133 return gmtime_r(&t, &tm);
134#endif
135 }
Here is the caller graph for this function:

◆ get_internet_time_str()

std::string epee::misc_utils::get_internet_time_str ( const time_t & time_)
inline

Definition at line 108 of file time_helper.h.

109 {
110 char tmpbuf[200] = {0};
111 tm* pt = NULL;
112PRAGMA_WARNING_PUSH
113PRAGMA_WARNING_DISABLE_VS(4996)
114 pt = gmtime(&time_);
115PRAGMA_WARNING_POP
116 strftime( tmpbuf, 199, "%a, %d %b %Y %H:%M:%S GMT", pt );
117 return tmpbuf;
118 }

◆ get_max_t_val()

template<typename t_type>
t_type epee::misc_utils::get_max_t_val ( t_type t)

Definition at line 58 of file misc_language.h.

59 {
60 return (std::numeric_limits<t_type>::max)();
61 }

◆ get_ns_count()

uint64_t epee::misc_utils::get_ns_count ( )
inline

Definition at line 58 of file misc_os_dependent.h.

59 {
60#if defined(_MSC_VER)
61 return ::GetTickCount64() * 1000000;
62#elif defined(WIN32)
63 static LARGE_INTEGER pcfreq = {0};
64 LARGE_INTEGER ticks;
65 if (!pcfreq.QuadPart)
66 QueryPerformanceFrequency(&pcfreq);
67 QueryPerformanceCounter(&ticks);
68 ticks.QuadPart *= 1000000000; /* we want nsec */
69 return ticks.QuadPart / pcfreq.QuadPart;
70#elif defined(__MACH__)
71 clock_serv_t cclock;
72 mach_timespec_t mts;
73
74 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
75 clock_get_time(cclock, &mts);
76 mach_port_deallocate(mach_task_self(), cclock);
77
78 return ((uint64_t)mts.tv_sec * 1000000000) + (mts.tv_nsec);
79#else
80 struct timespec ts;
81 if(clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
82 return 0;
83 }
84 return ((uint64_t)ts.tv_sec * 1000000000) + (ts.tv_nsec);
85#endif
86 }
unsigned __int64 uint64_t
Definition stdint.h:136
Here is the caller graph for this function:

◆ get_thread_string_id()

std::string epee::misc_utils::get_thread_string_id ( )
inline

Definition at line 119 of file misc_os_dependent.h.

120 {
121#if defined(_WIN32)
122 return boost::lexical_cast<std::string>(GetCurrentThreadId());
123#elif defined(__GNUC__)
124 return boost::lexical_cast<std::string>(pthread_self());
125#endif
126 }
Here is the caller graph for this function:

◆ get_tick_count()

uint64_t epee::misc_utils::get_tick_count ( )
inline

Definition at line 88 of file misc_os_dependent.h.

89 {
90 return get_ns_count() / 1000000;
91 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_time_interval_string()

std::string epee::misc_utils::get_time_interval_string ( const time_t & time_)
inline

Definition at line 120 of file time_helper.h.

121 {
122 std::string res;
123 time_t tail = time_;
124PRAGMA_WARNING_PUSH
125PRAGMA_WARNING_DISABLE_VS(4244)
126 int days = tail/(60*60*24);
127 tail = tail%(60*60*24);
128 int hours = tail/(60*60);
129 tail = tail%(60*60);
130 int minutes = tail/(60);
131 tail = tail%(60);
132 int seconds = tail;
133PRAGMA_WARNING_POP
134 res = std::string() + "d" + boost::lexical_cast<std::string>(days) + ".h" + boost::lexical_cast<std::string>(hours) + ".m" + boost::lexical_cast<std::string>(minutes) + ".s" + boost::lexical_cast<std::string>(seconds);
135 return res;
136 }
const char * res
STL namespace.
Here is the caller graph for this function:

◆ get_time_str()

std::string epee::misc_utils::get_time_str ( const time_t & time_)
inline

Definition at line 56 of file time_helper.h.

57 {
58
59
60 char tmpbuf[200] = {0};
61 tm* pt = NULL;
62PRAGMA_WARNING_PUSH
63PRAGMA_WARNING_DISABLE_VS(4996)
64 pt = localtime(&time_);
65PRAGMA_WARNING_POP
66
67 if(pt)
68 strftime( tmpbuf, 199, "%d.%m.%Y %H:%M:%S", pt );
69 else
70 {
71 std::stringstream strs;
72 strs << "[wrong_time: " << std::hex << time_ << "]";
73 return strs.str();
74 }
75 return tmpbuf;
76 }
else if(0==res)

◆ get_time_str_v2()

std::string epee::misc_utils::get_time_str_v2 ( const time_t & time_)
inline

Definition at line 79 of file time_helper.h.

80 {
81
82 char tmpbuf[200] = {0};
83 tm* pt = NULL;
84PRAGMA_WARNING_PUSH
85PRAGMA_WARNING_DISABLE_VS(4996)
86 pt = localtime(&time_);
87PRAGMA_WARNING_POP
88
89 if(pt)
90 strftime( tmpbuf, 199, "%Y_%m_%d %H_%M_%S", pt );
91 else
92 {
93 std::stringstream strs;
94 strs << "[wrong_time: " << std::hex << time_ << "]";
95 return strs.str();
96 }
97 return tmpbuf;
98 }

◆ get_time_str_v3()

std::string epee::misc_utils::get_time_str_v3 ( const boost::posix_time::ptime & time_)
inline

Definition at line 101 of file time_helper.h.

102 {
103 return boost::posix_time::to_simple_string(time_);
104 }

◆ is_less_as_pod()

template<class _Ty>
bool epee::misc_utils::is_less_as_pod ( const _Ty & _Left,
const _Ty & _Right )

Definition at line 93 of file misc_language.h.

94 { // apply operator< to operands
95 return memcmp(&_Left, &_Right, sizeof(_Left)) < 0;
96 }

◆ median()

template<class type_vec_type>
type_vec_type epee::misc_utils::median ( std::vector< type_vec_type > & v)

Definition at line 110 of file misc_language.h.

111 {
112 if(v.empty())
113 return boost::value_initialized<type_vec_type>();
114 if(v.size() == 1)
115 return v[0];
116
117 size_t n = (v.size()) / 2;
118 std::sort(v.begin(), v.end());
119 //nth_element(v.begin(), v.begin()+n-1, v.end());
120 if(v.size()%2)
121 {//1, 3, 5...
122 return v[n];
123 }else
124 {//2, 4, 6...
125 return (v[n-1] + v[n])/2;
126 }
127
128 }
Here is the caller graph for this function:

◆ move_it_backward()

template<typename t_iterator>
t_iterator epee::misc_utils::move_it_backward ( t_iterator it,
size_t count )

Definition at line 73 of file misc_language.h.

74 {
75 while(count--)
76 it--;
77 return it;
78 }
Here is the caller graph for this function:

◆ move_it_forward()

template<typename t_iterator>
t_iterator epee::misc_utils::move_it_forward ( t_iterator it,
size_t count )

Definition at line 65 of file misc_language.h.

66 {
67 while(count--)
68 it++;
69 return it;
70 }

◆ sleep_no_w()

bool epee::misc_utils::sleep_no_w ( long ms)
inline

Definition at line 100 of file misc_language.h.

101 {
102 boost::this_thread::sleep(
103 boost::get_system_time() +
104 boost::posix_time::milliseconds( std::max<long>(ms,0) ) );
105
106 return true;
107 }
Here is the caller graph for this function: