派生自 development/c++

pansen
2019-03-07 d3b7bbe7102cd089680a828f5d8f6402c8cf6342
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// Created by ps on 8/9/18.
//
 
 
#include "ShareMemoryTool.hpp"
#include <jsoncpp/json/json.h>
#include <SemTool.h>
 
 
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<BISTL::bi_map_Feature_Info>("MyMap")(std::less<BISTL::char_string>(),alloc_inst);
//        BISTL::bi_map_Feature_Info *mymap =
//            segment.find_or_construct<BISTL::bi_map_Feature_Info>("aaa8")(std::less<BISTL::char_string>(), 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;
}