-
Notifications
You must be signed in to change notification settings - Fork 1
/
value.h
58 lines (40 loc) · 1.13 KB
/
value.h
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
#ifndef TORRENTPP_value_H
#define TORRENTPP_value_H
#include "encode.h"
#include <cstdint>
#include <map>
#include <ostream>
#include <stdexcept>
#include <string>
#include <vector>
namespace bencode {
class value {
public:
enum class type { null, integer, string, list, dict };
typedef std::int64_t int_type;
typedef std::string string_type;
typedef std::vector<value> list_type;
typedef std::map<value, value> dict_type;
value();
explicit value(std::int64_t v);
explicit value(const std::string& str);
explicit value(const list_type& list);
explicit value(const dict_type& dict);
type value_type() const { return type_; }
std::int64_t int_value() const { return int_; }
std::string string_value() const { return string_; }
list_type list_value() const { return list_; }
dict_type dict_value() const { return dict_; }
std::string encode() const;
bool operator<(const value& other) const;
bool operator==(const value& other);
std::string to_string() const;
private:
type type_;
int_type int_;
string_type string_;
list_type list_;
dict_type dict_;
};
}
#endif