summary refs log tree commit diff stats
path: root/lib/data.cpp
blob: db4248723fede16759fc52e6dc8098da32d0380b (plain) (blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "verbly.h"

namespace verbly {
  
  data::data(std::string datafile)
  {
    if (sqlite3_open_v2(datafile.c_str(), &ppdb, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK)
    {
      throw std::invalid_argument(sqlite3_errmsg(ppdb));
    }
  }

  data::data(data&& other)
  {
    ppdb = other.ppdb;
  }

  data& data::operator=(data&& other)
  {
    ppdb = other.ppdb;
  
    return *this;
  }

  data::~data()
  {
    sqlite3_close_v2(ppdb);
  }

  verb_query data::verbs() const
  {
    return verb_query(*this);
  }

  adjective_query data::adjectives() const
  {
    return adjective_query(*this);
  }

  adverb_query data::adverbs() const
  {
    return adverb_query(*this);
  }

  noun_query data::nouns() const
  {
    return noun_query(*this);
  }
  
  frame_query data::frames() const
  {
    return frame_query(*this);
  }
  
  preposition_query data::prepositions() const
  {
    return preposition_query(*this);
  }
  
  binding::type binding::get_type() const
  {
    return _type;
  }
  
  binding::binding(const binding& other)
  {
    _type = other._type;
    
    switch (_type)
    {
      case type::integer:
      {
        _integer = other._integer;
        
        break;
      }
      
      case type::string:
      {
        new(&_string) std::string(other._string);
        
        break;
      }
    }
  }
  
  binding::~binding()
  {
    switch (_type)
    {
      case type::string:
      {
        using string_type = std::string;
        _string.~string_type();
        
        break;
      }
    }
  }
  
  binding& binding::operator=(const binding& other)
  {
    this->~binding();
    
    _type = other._type;
    
    switch (_type)
    {
      case type::integer:
      {
        _integer = other._integer;
        
        break;
      }
      
      case type::string:
      {
        new(&_string) std::string(other._string);
        
        break;
      }
    }
    
    return *this;
  }
  
  binding::binding(int _arg)
  {
    _type = type::integer;
    _integer = _arg;
  }
  
  int binding::get_integer() const
  {
    assert(_type == type::integer);
    
    return _integer;
  }
  
  void binding::set_integer(int _arg)
  {
    *this = binding(_arg);
  }
  
  binding& binding::operator=(int _arg)
  {
    *this = binding(_arg);
    
    return *this;
  }
  
  binding::binding(std::string _arg)
  {
    _type = type::string;
    new(&_string) std::string(_arg);
  }
  
  std::string binding::get_string() const
  {
    assert(_type == type::string);
    
    return _string;
  }
  
  void binding::set_string(std::string _arg)
  {
    *this = binding(_arg);
  }
  
  binding& binding::operator=(std::string _arg)
  {
    *this = binding(_arg);
    
    return *this;
  }
  
};