// // Created by ps on 8/9/18. // #include "ShareMemoryTool.hpp" #include #include using namespace std; static std::string getTimeSecString() { char buf[128] = {0}; time_t t = time(nullptr); timeval time{0}; gettimeofday(&time, nullptr); tm *local = localtime(&t); //转为本地时间 strftime(buf, 64, "%Y-%m-%d %H:%M:%S", local); return std::string(buf); } int main() { // string str_json = "{\"path\":\"/opt/erlang/sub1/\",\"nodeName\":\"sub1@192.168.1.186\",\"cookie\":\"abc\",\"tableName\":\"test\"}"; // int key = 1234; // SemTool semTool(key); // semTool.set_semvalue(); auto str = getTimeSecString(); cout << str.substr(0, 10) << endl; srand(time(0)); bool ret = true; if (rand() % 2) { for (int i = 0; i < 10; ++i) { int loop = 3; cout << loop << " " << loop % 2 << endl; ret &= loop % 2; } } else { ret = false; } if (ret) { cout << "true" << endl; } else { cout << "false" << endl; } return 0; Json::Value t_json; Json::FastWriter writer; t_json["\"path\""] = "\"/opt/erlang/sub1/\""; t_json["\"nodeName\""] = "\"sub1@192.168.1.186\""; t_json["\"cookie\""] = "\"abc\""; t_json["\"tableName\""] = "\"test\""; // t_json["\"key\""] = "\""+to_string(key)+"\""; string tet = "./syncDBClient "; string str_json = writer.write(t_json); tet.append("\"" + str_json.substr(0, str_json.length() - 1) + "\" "); cout << tet << endl; system(tet.c_str()); // return 0; // sleep(2); // semTool.semaphore_p(); try { // BISTL::shared_memory_object // init // BISTL::managed_shared_memory segment(BISTL::open_only, "aaa8" ); BISTL::BiMapFeaData biMapFeaData("test"); // const BISTL::void_allocator alloc_inst (segment.get_segment_manager()); // BISTL::bi_map_Feature_Info * mymap = // segment.construct("MyMap")(std::less(),alloc_inst); // BISTL::bi_map_Feature_Info *mymap = // segment.find_or_construct("aaa8")(std::less(), alloc_inst); auto mymap = biMapFeaData.getMap(); auto size = mymap->size(); for (auto it = mymap->begin(); it != mymap->end(); it++) { // printf("%s \n", it->second.id.c_str()); // printf("%d \n", it->second.id); string a = string(it->second.m_id.data()); string b = string(it->second.m_feature.data()); std::cout << "id " << a << std::endl; std::cout << "feature " << b << std::endl; // it->second.id; } printf("\n"); // BISTL::shared_memory_object::remove("SharedMemory"); } catch (const std::exception &e) { printf("Exception:%s\n", e.what()); BISTL::shared_memory_object::remove("test"); } getchar(); BISTL::shared_memory_object::remove("test"); return 0; }