diff --git a/a8/mutable_xobject.cc b/a8/mutable_xobject.cc index db2f3ef..7e48f5b 100644 --- a/a8/mutable_xobject.cc +++ b/a8/mutable_xobject.cc @@ -53,6 +53,17 @@ namespace a8 return *this; } + a8::MutableXObject& MutableXObject::SetVal(const std::string& key, a8::XObject& val) + { + if (type_ != XOT_OBJECT) { + abort(); + } + std::shared_ptr p = std::make_shared(); + val.Move(*p.get()); + (*value_.object_value)[key] = p; + return *this; + } + a8::MutableXObject& MutableXObject::SetVal(const std::string& key, a8::MutableXObject& val) { if (type_ != XOT_OBJECT) { diff --git a/a8/mutable_xobject.h b/a8/mutable_xobject.h index f7baa58..3f542bd 100644 --- a/a8/mutable_xobject.h +++ b/a8/mutable_xobject.h @@ -17,6 +17,7 @@ namespace a8 a8::MutableXObject& SetVal(int i, a8::XValue val); a8::MutableXObject& SetVal(int i, a8::MutableXObject&& val); a8::MutableXObject& SetVal(const std::string& key, a8::XValue val); + a8::MutableXObject& SetVal(const std::string& key, a8::XObject& val); a8::MutableXObject& SetVal(const std::string& key, a8::MutableXObject& val); }; diff --git a/a8/sysutils.cc b/a8/sysutils.cc index 3935880..4076ac6 100644 --- a/a8/sysutils.cc +++ b/a8/sysutils.cc @@ -1,6 +1,9 @@ #include #include #include +#include +#include +#include #include #include @@ -117,10 +120,37 @@ namespace a8 bool MkDir(const std::string& path) { if (access(path.c_str(), W_OK) == 0) { - return 0; + return true; } int status = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); return status == 0; } + void ForceCreateDir(const std::string& path) + { + if (access(path.c_str(), W_OK) == 0) { + return; + } + std::vector strings; + a8::Split(path, strings, '/'); + std::string cur_dir = "/"; + for (auto& tmp_str : strings) { + cur_dir += tmp_str + "/"; + if (access(cur_dir.c_str(), W_OK) != 0) { + a8::MkDir(cur_dir); + } + } + } + + std::string GetIpAddress(unsigned long ip_saddr) + { + in_addr addr; + memset(&addr, 0, sizeof(addr)); + addr.s_addr = ip_saddr; + char buf[255]; + buf[0] = '\0'; + inet_ntop(AF_INET, &addr, buf, 255); + return std::string(buf); + } + } diff --git a/a8/sysutils.h b/a8/sysutils.h index 8f1adef..c4bcdc5 100644 --- a/a8/sysutils.h +++ b/a8/sysutils.h @@ -61,6 +61,8 @@ namespace a8 bool HasBitFlag(const long long& flag_bits, int bit); void XPrintf(const char* fmt, std::initializer_list args); bool MkDir(const std::string& path); + void ForceCreateDir(const std::string& path); + std::string GetIpAddress(unsigned long ip_saddr); }