|
@@ -25,324 +25,325 @@
|
|
|
|
|
|
class tool_other
|
|
|
{
|
|
|
-public:
|
|
|
- static double round(double dVal, int iPlaces)
|
|
|
- {
|
|
|
- double dRetval;
|
|
|
- double dMod = 0.0000001;
|
|
|
- if (dVal<0.0) dMod=-0.0000001;
|
|
|
- dRetval=dVal;
|
|
|
- dRetval+=(5.0/pow(10.0,iPlaces+1.0));
|
|
|
- dRetval*=pow(10.0,iPlaces);
|
|
|
- dRetval=floor(dRetval+dMod);
|
|
|
- dRetval/=pow(10.0,iPlaces);
|
|
|
- return(dRetval);
|
|
|
- }
|
|
|
- static std::string to13str(std::string& str)
|
|
|
- {
|
|
|
- uint64_t tmp = std::stoull(str);
|
|
|
- return to13str(tmp);
|
|
|
- }
|
|
|
-
|
|
|
- static std::string to13str(uint64_t data)
|
|
|
- {
|
|
|
- char ss[20]={0};
|
|
|
- sprintf(ss, "%013ld", data);
|
|
|
-
|
|
|
- return std::string(ss);
|
|
|
- }
|
|
|
-
|
|
|
- static uint32_t id64_to_id(std::string& str)
|
|
|
- {
|
|
|
- return static_cast<uint32_t>(std::stoul(to13str(str).substr(3)));
|
|
|
- }
|
|
|
-
|
|
|
- static int id64_to_type(std::string& str)
|
|
|
- {
|
|
|
- return std::stoi(to13str(str).substr(0, 3));
|
|
|
- }
|
|
|
- static int card_id_to_type(const std::string &cardid)
|
|
|
- {
|
|
|
- return std::stoi(cardid.substr(0,3));
|
|
|
- }
|
|
|
- static int card_id_to_id(const std::string &cardid)
|
|
|
- {
|
|
|
- return atoi(cardid.substr(3).c_str());
|
|
|
- }
|
|
|
- static std::string type_id_to_str(int32_t type,uint32_t id)
|
|
|
- {
|
|
|
- char sql[15] = {0};
|
|
|
- snprintf(sql, 15,"%03d%010d", type, id);
|
|
|
- return std::string(sql);
|
|
|
- }
|
|
|
- static uint64_t type_id_to_u64(uint64_t type,uint32_t id)
|
|
|
- {
|
|
|
- return type<<32|id;
|
|
|
- }
|
|
|
- static bool is_person(int32_t type)
|
|
|
- {
|
|
|
- return CT_PERSON == type;
|
|
|
- }
|
|
|
-
|
|
|
- static bool is_vehicle(int32_t type)
|
|
|
- {
|
|
|
- return CT_VEHICLE == type || CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
|
|
|
- }
|
|
|
- static std::string get_string_cardid(uint64_t id)
|
|
|
- {
|
|
|
- uint64_t type = id>>32;
|
|
|
- uint32_t cid = id & (~(type<<32));
|
|
|
- return type_id_to_str(type,cid);
|
|
|
- }
|
|
|
-
|
|
|
- static uint64_t card_id_to_u64(const std::string & cardid)
|
|
|
- {
|
|
|
- return type_id_to_u64(card_id_to_type(cardid),card_id_to_id(cardid));
|
|
|
- }
|
|
|
-
|
|
|
- ///采煤机
|
|
|
- static bool is_coal(int32_t type)
|
|
|
- {
|
|
|
- return CT_COAL_CUTTER == type;
|
|
|
- }
|
|
|
-
|
|
|
- /// 掘进机
|
|
|
- static bool is_driving(int32_t type)
|
|
|
- {
|
|
|
- return CT_HEADING_MACHINE == type;
|
|
|
- }
|
|
|
-
|
|
|
- static bool is_coal_or_driving(int32_t type)
|
|
|
- {
|
|
|
- return CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-class tool_map
|
|
|
-{
|
|
|
-public:
|
|
|
- static bool try_get_value(sio::message::ptr& out_data,
|
|
|
- const char* key, sio::message::ptr const& data)
|
|
|
- {
|
|
|
- auto map=data->get_map()[key];
|
|
|
- if(map && sio::message::flag_object == map->get_flag())
|
|
|
+ public:
|
|
|
+ static double round(double dVal, int iPlaces)
|
|
|
{
|
|
|
- out_data = map;
|
|
|
- return true;
|
|
|
+ double dRetval;
|
|
|
+ double dMod = 0.0000001;
|
|
|
+ if (dVal<0.0) dMod=-0.0000001;
|
|
|
+ dRetval=dVal;
|
|
|
+ dRetval+=(5.0/pow(10.0,iPlaces+1.0));
|
|
|
+ dRetval*=pow(10.0,iPlaces);
|
|
|
+ dRetval=floor(dRetval+dMod);
|
|
|
+ dRetval/=pow(10.0,iPlaces);
|
|
|
+ return(dRetval);
|
|
|
}
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- static bool try_get_value(int64_t& out_data, const char* key, sio::message::ptr const& data)
|
|
|
- {
|
|
|
- auto map=data->get_map()[key];
|
|
|
- if(map && sio::message::flag_integer == map->get_flag())
|
|
|
+ static std::string to13str(std::string& str)
|
|
|
{
|
|
|
- out_data = map->get_int();
|
|
|
- return true;
|
|
|
+ if(str.size()<13)
|
|
|
+ str.insert(0,13-str.size(),'0');
|
|
|
+ return str;
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- static bool try_get_value(uint32_t& out_data, const char* key, sio::message::ptr const& data)
|
|
|
- {
|
|
|
- auto map=data->get_map()[key];
|
|
|
- if(map && sio::message::flag_integer == map->get_flag())
|
|
|
+ static std::string to13str(uint64_t data)
|
|
|
{
|
|
|
- out_data = static_cast<uint32_t>(map->get_int());
|
|
|
- return true;
|
|
|
- }
|
|
|
+ char ss[20]={0};
|
|
|
+ sprintf(ss, "%013ld", data);
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ return std::string(ss);
|
|
|
+ }
|
|
|
|
|
|
- static bool try_get_value(int& out_data, const char* key, sio::message::ptr const& data)
|
|
|
- {
|
|
|
- auto map=data->get_map()[key];
|
|
|
- if(map && sio::message::flag_integer == map->get_flag())
|
|
|
+ static uint32_t id64_to_id(std::string& str)
|
|
|
{
|
|
|
- out_data = static_cast<int>(map->get_int());
|
|
|
- return true;
|
|
|
+ return static_cast<uint32_t>(std::stoul(to13str(str).substr(3)));
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- static bool try_get_value(std::string& out_data, const char* key, sio::message::ptr const& data)
|
|
|
- {
|
|
|
- auto map=data->get_map()[key];
|
|
|
- if(map && sio::message::flag_string == map->get_flag())
|
|
|
+ static int id64_to_type(std::string& str)
|
|
|
+ {
|
|
|
+ return std::stoi(to13str(str).substr(0, 3));
|
|
|
+ }
|
|
|
+ static int card_id_to_type(const std::string &cardid)
|
|
|
{
|
|
|
- out_data = map->get_string();
|
|
|
- return true;
|
|
|
+ return std::stoi(cardid.substr(0,3));
|
|
|
+ }
|
|
|
+ static int card_id_to_id(const std::string &cardid)
|
|
|
+ {
|
|
|
+ return atoi(cardid.substr(3).c_str());
|
|
|
+ }
|
|
|
+ static std::string type_id_to_str(int32_t type,uint32_t id)
|
|
|
+ {
|
|
|
+ char sql[15] = {0};
|
|
|
+ snprintf(sql, 15,"%03d%010d", type, id);
|
|
|
+ return std::string(sql);
|
|
|
+ }
|
|
|
+ static uint64_t type_id_to_u64(uint64_t type,uint32_t id)
|
|
|
+ {
|
|
|
+ return type<<32|id;
|
|
|
+ }
|
|
|
+ static bool is_person(int32_t type)
|
|
|
+ {
|
|
|
+ return CT_PERSON == type;
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ static bool is_vehicle(int32_t type)
|
|
|
+ {
|
|
|
+ return CT_VEHICLE == type || CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
|
|
|
+ }
|
|
|
+ static std::string get_string_cardid(uint64_t id)
|
|
|
+ {
|
|
|
+ uint64_t type = id>>32;
|
|
|
+ uint32_t cid = id & (~(type<<32));
|
|
|
+ return type_id_to_str(type,cid);
|
|
|
+ }
|
|
|
|
|
|
- static bool try_get_value(double& out_data, const char* key, sio::message::ptr const& data)
|
|
|
- {
|
|
|
- auto map=data->get_map()[key];
|
|
|
- if(map && sio::message::flag_double == map->get_flag())
|
|
|
+ static uint64_t card_id_to_u64(const std::string & cardid)
|
|
|
{
|
|
|
- out_data = map->get_double();
|
|
|
- return true;
|
|
|
+ return type_id_to_u64(card_id_to_type(cardid),card_id_to_id(cardid));
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ ///采煤机
|
|
|
+ static bool is_coal(int32_t type)
|
|
|
+ {
|
|
|
+ return CT_COAL_CUTTER == type;
|
|
|
+ }
|
|
|
|
|
|
- static bool try_get_value(std::vector<sio::message::ptr>& out_data,
|
|
|
- const char* key, sio::message::ptr const& data)
|
|
|
- {
|
|
|
- auto map=data->get_map()[key];
|
|
|
- if(map && sio::message::flag_array == map->get_flag())
|
|
|
+ /// 掘进机
|
|
|
+ static bool is_driving(int32_t type)
|
|
|
{
|
|
|
- out_data = map->get_vector();
|
|
|
- return true;
|
|
|
+ return CT_HEADING_MACHINE == type;
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ static bool is_coal_or_driving(int32_t type)
|
|
|
+ {
|
|
|
+ return CT_COAL_CUTTER == type || CT_HEADING_MACHINE == type;
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
-class tool_json
|
|
|
+class tool_map
|
|
|
{
|
|
|
-public:
|
|
|
- static void add_member(rapidjson::Value& out_data, const char* key, std::string value,
|
|
|
- rapidjson::Document::AllocatorType& allocator)
|
|
|
- {
|
|
|
- rapidjson::Value name;
|
|
|
- name.SetString(key, allocator);
|
|
|
-
|
|
|
- rapidjson::Value data;
|
|
|
- data.SetString(value.c_str(), allocator);
|
|
|
-
|
|
|
- out_data.AddMember(name, data, allocator);
|
|
|
- }
|
|
|
-
|
|
|
- static void push_back(rapidjson::Value& out_data, std::string value,
|
|
|
- rapidjson::Document::AllocatorType& allocator)
|
|
|
- {
|
|
|
- rapidjson::Value data;
|
|
|
- data.SetString(value.c_str(), allocator);
|
|
|
-
|
|
|
- out_data.PushBack(data, allocator);
|
|
|
- }
|
|
|
-
|
|
|
- static bool try_get_iter(const char* key, const rapidjson::Value& node,
|
|
|
- rapidjson::Value::ConstMemberIterator& out_iter)
|
|
|
- {
|
|
|
- if(node.IsObject())
|
|
|
- {
|
|
|
- out_iter = node.FindMember(key);
|
|
|
- if(node.MemberEnd() == out_iter)
|
|
|
+ public:
|
|
|
+ static bool try_get_value(sio::message::ptr& out_data,
|
|
|
+ const char* key, sio::message::ptr const& data)
|
|
|
+ {
|
|
|
+ auto map=data->get_map()[key];
|
|
|
+ if(map && sio::message::flag_object == map->get_flag())
|
|
|
{
|
|
|
- return false;
|
|
|
+ out_data = map;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
- return true;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ static bool try_get_value(int64_t& out_data, const char* key, sio::message::ptr const& data)
|
|
|
+ {
|
|
|
+ auto map=data->get_map()[key];
|
|
|
+ if(map && sio::message::flag_integer == map->get_flag())
|
|
|
+ {
|
|
|
+ out_data = map->get_int();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- static bool try_get_value(int& d, const char* key, const rapidjson::Value& node)
|
|
|
- {
|
|
|
- rapidjson::Value::ConstMemberIterator iter;
|
|
|
- if(try_get_iter(key, node, iter))
|
|
|
+ static bool try_get_value(uint32_t& out_data, const char* key, sio::message::ptr const& data)
|
|
|
{
|
|
|
- if(iter->value.IsInt())
|
|
|
+ auto map=data->get_map()[key];
|
|
|
+ if(map && sio::message::flag_integer == map->get_flag())
|
|
|
{
|
|
|
- d = iter->value.GetInt();
|
|
|
+ out_data = static_cast<uint32_t>(map->get_int());
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ static bool try_get_value(int& out_data, const char* key, sio::message::ptr const& data)
|
|
|
+ {
|
|
|
+ auto map=data->get_map()[key];
|
|
|
+ if(map && sio::message::flag_integer == map->get_flag())
|
|
|
+ {
|
|
|
+ out_data = static_cast<int>(map->get_int());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- static bool try_get_value(uint64_t& d, const char* key, const rapidjson::Value& node)
|
|
|
- {
|
|
|
- rapidjson::Value::ConstMemberIterator iter;
|
|
|
- if(try_get_iter(key, node, iter))
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ static bool try_get_value(std::string& out_data, const char* key, sio::message::ptr const& data)
|
|
|
{
|
|
|
- if(iter->value.IsUint64())
|
|
|
+ auto map=data->get_map()[key];
|
|
|
+ if(map && sio::message::flag_string == map->get_flag())
|
|
|
{
|
|
|
- d = iter->value.GetUint64();
|
|
|
+ out_data = map->get_string();
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
- static bool try_get_value(double& d, const char* key, const rapidjson::Value& node)
|
|
|
- {
|
|
|
- rapidjson::Value::ConstMemberIterator iter;
|
|
|
- if(try_get_iter(key, node, iter))
|
|
|
+ static bool try_get_value(double& out_data, const char* key, sio::message::ptr const& data)
|
|
|
{
|
|
|
- if(iter->value.IsDouble())
|
|
|
+ auto map=data->get_map()[key];
|
|
|
+ if(map && sio::message::flag_double == map->get_flag())
|
|
|
{
|
|
|
- d = iter->value.GetDouble();
|
|
|
+ out_data = map->get_double();
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
- return false;
|
|
|
- }
|
|
|
|
|
|
- static bool try_get_value(std::string& d, const char* key, const rapidjson::Value& node)
|
|
|
- {
|
|
|
- rapidjson::Value::ConstMemberIterator iter;
|
|
|
- if(try_get_iter(key, node, iter))
|
|
|
+ static bool try_get_value(std::vector<sio::message::ptr>& out_data,
|
|
|
+ const char* key, sio::message::ptr const& data)
|
|
|
{
|
|
|
- if(iter->value.IsString())
|
|
|
+ auto map=data->get_map()[key];
|
|
|
+ if(map && sio::message::flag_array == map->get_flag())
|
|
|
{
|
|
|
- d = iter->value.GetString();
|
|
|
+ out_data = map->get_vector();
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
+};
|
|
|
+
|
|
|
+class tool_json
|
|
|
+{
|
|
|
+ public:
|
|
|
+ static void add_member(rapidjson::Value& out_data, const char* key, std::string value,
|
|
|
+ rapidjson::Document::AllocatorType& allocator)
|
|
|
+ {
|
|
|
+ rapidjson::Value name;
|
|
|
+ name.SetString(key, allocator);
|
|
|
+
|
|
|
+ rapidjson::Value data;
|
|
|
+ data.SetString(value.c_str(), allocator);
|
|
|
|
|
|
- return false;
|
|
|
- }
|
|
|
+ out_data.AddMember(name, data, allocator);
|
|
|
+ }
|
|
|
|
|
|
- static int get_value(const char* key, const int& default_data, const rapidjson::Value& node)
|
|
|
- {
|
|
|
- rapidjson::Value::ConstMemberIterator iter;
|
|
|
- if(try_get_iter(key, node, iter))
|
|
|
+ static void push_back(rapidjson::Value& out_data, std::string value,
|
|
|
+ rapidjson::Document::AllocatorType& allocator)
|
|
|
{
|
|
|
- if(iter->value.IsInt())
|
|
|
+ rapidjson::Value data;
|
|
|
+ data.SetString(value.c_str(), allocator);
|
|
|
+
|
|
|
+ out_data.PushBack(data, allocator);
|
|
|
+ }
|
|
|
+
|
|
|
+ static bool try_get_iter(const char* key, const rapidjson::Value& node,
|
|
|
+ rapidjson::Value::ConstMemberIterator& out_iter)
|
|
|
+ {
|
|
|
+ if(node.IsObject())
|
|
|
{
|
|
|
- return iter->value.GetInt();
|
|
|
+ out_iter = node.FindMember(key);
|
|
|
+ if(node.MemberEnd() == out_iter)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- return default_data;
|
|
|
- }
|
|
|
+ static bool try_get_value(int& d, const char* key, const rapidjson::Value& node)
|
|
|
+ {
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
+ {
|
|
|
+ if(iter->value.IsInt())
|
|
|
+ {
|
|
|
+ d = iter->value.GetInt();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- static std::string get_value(const char* key, const std::string& default_data, const rapidjson::Value& node)
|
|
|
- {
|
|
|
- rapidjson::Value::ConstMemberIterator iter;
|
|
|
- if(try_get_iter(key, node, iter))
|
|
|
+ static bool try_get_value(uint64_t& d, const char* key, const rapidjson::Value& node)
|
|
|
{
|
|
|
- if(iter->value.IsString())
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
{
|
|
|
- return iter->value.GetString();
|
|
|
+ if(iter->value.IsUint64())
|
|
|
+ {
|
|
|
+ d = iter->value.GetUint64();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- return default_data;
|
|
|
- }
|
|
|
+ static bool try_get_value(double& d, const char* key, const rapidjson::Value& node)
|
|
|
+ {
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
+ {
|
|
|
+ if(iter->value.IsDouble())
|
|
|
+ {
|
|
|
+ d = iter->value.GetDouble();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ static bool try_get_value(std::string& d, const char* key, const rapidjson::Value& node)
|
|
|
+ {
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
+ {
|
|
|
+ if(iter->value.IsString())
|
|
|
+ {
|
|
|
+ d = iter->value.GetString();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ static int get_value(const char* key, const int& default_data, const rapidjson::Value& node)
|
|
|
+ {
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
+ {
|
|
|
+ if(iter->value.IsInt())
|
|
|
+ {
|
|
|
+ return iter->value.GetInt();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return default_data;
|
|
|
+ }
|
|
|
|
|
|
- static std::string doc_to_json(rapidjson::Document& doc)
|
|
|
- {
|
|
|
- rapidjson::StringBuffer sb;
|
|
|
- rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
|
|
|
- doc.Accept(writer);
|
|
|
+ static std::string get_value(const char* key, const std::string& default_data, const rapidjson::Value& node)
|
|
|
+ {
|
|
|
+ rapidjson::Value::ConstMemberIterator iter;
|
|
|
+ if(try_get_iter(key, node, iter))
|
|
|
+ {
|
|
|
+ if(iter->value.IsString())
|
|
|
+ {
|
|
|
+ return iter->value.GetString();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- return sb.GetString();
|
|
|
- }
|
|
|
+ return default_data;
|
|
|
+ }
|
|
|
+
|
|
|
+ static std::string doc_to_json(rapidjson::Document& doc)
|
|
|
+ {
|
|
|
+ rapidjson::StringBuffer sb;
|
|
|
+ rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(sb);
|
|
|
+ doc.Accept(writer);
|
|
|
+
|
|
|
+ return sb.GetString();
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
#endif // COMMON_TOOL_H
|