|
@@ -26,7 +26,18 @@
|
|
|
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);
|
|
@@ -50,24 +61,24 @@ public:
|
|
|
{
|
|
|
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)
|
|
|
- {
|
|
|
+ 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 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;
|
|
@@ -77,17 +88,17 @@ public:
|
|
|
{
|
|
|
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 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 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)
|
|
@@ -111,7 +122,7 @@ class tool_map
|
|
|
{
|
|
|
public:
|
|
|
static bool try_get_value(sio::message::ptr& out_data,
|
|
|
- const char* key, sio::message::ptr const& data)
|
|
|
+ const char* key, sio::message::ptr const& data)
|
|
|
{
|
|
|
auto map=data->get_map()[key];
|
|
|
if(map && sio::message::flag_object == map->get_flag())
|
|
@@ -184,7 +195,7 @@ public:
|
|
|
}
|
|
|
|
|
|
static bool try_get_value(std::vector<sio::message::ptr>& out_data,
|
|
|
- const char* key, sio::message::ptr const& data)
|
|
|
+ const char* key, sio::message::ptr const& data)
|
|
|
{
|
|
|
auto map=data->get_map()[key];
|
|
|
if(map && sio::message::flag_array == map->get_flag())
|
|
@@ -201,7 +212,7 @@ class tool_json
|
|
|
{
|
|
|
public:
|
|
|
static void add_member(rapidjson::Value& out_data, const char* key, std::string value,
|
|
|
- rapidjson::Document::AllocatorType& allocator)
|
|
|
+ rapidjson::Document::AllocatorType& allocator)
|
|
|
{
|
|
|
rapidjson::Value name;
|
|
|
name.SetString(key, allocator);
|
|
@@ -213,7 +224,7 @@ public:
|
|
|
}
|
|
|
|
|
|
static void push_back(rapidjson::Value& out_data, std::string value,
|
|
|
- rapidjson::Document::AllocatorType& allocator)
|
|
|
+ rapidjson::Document::AllocatorType& allocator)
|
|
|
{
|
|
|
rapidjson::Value data;
|
|
|
data.SetString(value.c_str(), allocator);
|
|
@@ -222,7 +233,7 @@ public:
|
|
|
}
|
|
|
|
|
|
static bool try_get_iter(const char* key, const rapidjson::Value& node,
|
|
|
- rapidjson::Value::ConstMemberIterator& out_iter)
|
|
|
+ rapidjson::Value::ConstMemberIterator& out_iter)
|
|
|
{
|
|
|
if(node.IsObject())
|
|
|
{
|