Skip to content

Commit 58b1adc

Browse files
committed
add noexcept
1 parent 1e4e945 commit 58b1adc

File tree

4 files changed

+131
-118
lines changed

4 files changed

+131
-118
lines changed

include/json/object.h

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class object {
2323

2424
json::TYPE type;
2525

26-
void clearVariant();
26+
void clearVariant() noexcept(true);
2727

28-
void clearArray();
29-
void setArrayIfUndefined();
30-
void assertIsArray();
28+
void clearArray() noexcept(true);
29+
void setArrayIfUndefined() noexcept(true);
30+
void assertIsArray() noexcept(false);
3131

32-
void clearMap();
33-
void setMapIfUndefined();
34-
void assertIsMap();
32+
void clearMap() noexcept(true);
33+
void setMapIfUndefined() noexcept(true);
34+
void assertIsMap() noexcept(false);
3535

3636
protected:
3737
json::object::Value value;
@@ -40,57 +40,62 @@ class object {
4040

4141
public:
4242
// Constructors
43-
object();
44-
object(json::object::AllValues data);
45-
object(const char *data);
46-
~object();
43+
object() noexcept(true);
44+
object(json::object::AllValues data) noexcept(false);
45+
object(const char *data) noexcept(false);
46+
~object() noexcept(true);
4747

4848
// Assignment operators
49-
json::object &operator=(std::nullptr_t data);
50-
json::object &operator=(bool data);
51-
json::object &operator=(int data);
52-
json::object &operator=(long long int data);
53-
json::object &operator=(double data);
54-
json::object &operator=(const char *data);
55-
json::object &operator=(const std::string &data);
56-
json::object &operator=(std::vector<json::object> data);
57-
json::object &operator=(std::map<std::string, json::object> data);
49+
json::object &operator=(std::nullptr_t data) noexcept(true);
50+
json::object &operator=(bool data) noexcept(true);
51+
json::object &operator=(int data) noexcept(true);
52+
json::object &operator=(long long int data) noexcept(true);
53+
json::object &operator=(double data) noexcept(true);
54+
json::object &operator=(const char *data) noexcept(true);
55+
json::object &operator=(const std::string &data) noexcept(true);
56+
json::object &operator=(std::vector<json::object> data) noexcept(true);
57+
json::object &
58+
operator=(std::map<std::string, json::object> data) noexcept(true);
5859

5960
// Array operations
60-
json::object &operator[](const size_t index);
61-
json::object &operator[](const int index);
62-
void push_back(const json::object &data);
63-
void pop_back();
64-
void reserve(const size_t size);
65-
void resize(const size_t size);
66-
void shrink_to_fit();
61+
json::object &operator[](const size_t index) noexcept(false);
62+
json::object &operator[](const int index) noexcept(false);
63+
void push_back(const json::object &data) noexcept(false);
64+
void pop_back() noexcept(false);
65+
void reserve(const size_t size) noexcept(false);
66+
void resize(const size_t size) noexcept(false);
67+
void shrink_to_fit() noexcept(false);
6768

6869
// Map operations
69-
json::object &operator[](const char *key);
70-
json::object &operator[](const std::string &key);
71-
std::map<std::string, json::object>::iterator find(const std::string key);
72-
std::map<std::string, json::object>::iterator begin();
73-
std::map<std::string, json::object>::iterator end();
74-
void insert(const std::string key, json::object::AllValues value);
70+
json::object &operator[](const char *key) noexcept(false);
71+
json::object &operator[](const std::string &key) noexcept(false);
72+
std::map<std::string, json::object>::iterator
73+
find(const std::string key) noexcept(false);
74+
std::map<std::string, json::object>::iterator begin() noexcept(false);
75+
std::map<std::string, json::object>::iterator end() noexcept(false);
76+
void insert(const std::string key,
77+
json::object::AllValues value) noexcept(false);
7578

7679
// Array and Map operators
77-
void clear();
78-
size_t size() const;
80+
void clear() noexcept(false);
81+
size_t size() const noexcept(false);
7982

8083
// Object operators
81-
void reset();
82-
void dump(std::string filename, size_t indent = 0) const;
83-
std::string dumps(size_t indent = 0, size_t baseIndent = 0) const;
84+
void reset() noexcept(true);
85+
void dump(std::string filename, size_t indent = 0) const noexcept(false);
86+
std::string dumps(size_t indent = 0, size_t baseIndent = 0) const
87+
noexcept(false);
8488

8589
// Conversion Operators
86-
operator std::string() const;
87-
operator int() const;
88-
operator long long int() const;
89-
operator double() const;
90-
operator bool() const;
90+
operator std::string() const noexcept(false);
91+
operator int() const noexcept(false);
92+
operator long long int() const noexcept(false);
93+
operator double() const noexcept(false);
94+
operator bool() const noexcept(false);
9195

9296
// Output functions
93-
friend std::ostream &operator<<(std::ostream &os, const json::object &obj);
97+
friend std::ostream &operator<<(std::ostream &os,
98+
const json::object &obj) noexcept(true);
9499
};
95100

96101
} // namespace json

include/json/parse.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ class parser {
1616

1717
size_t index;
1818

19-
object parseValue();
20-
object parseBooleanNullOrUndefined();
21-
object parseNumber();
22-
object parseString();
23-
object parseArray();
24-
object parseMap();
25-
26-
void skipWhitespace();
27-
bool shouldStringBeEscaped();
28-
char getPrevChar();
29-
char getCurrChar();
19+
object parseValue() noexcept(false);
20+
object parseBooleanNullOrUndefined() noexcept(false);
21+
object parseNumber() noexcept(true);
22+
object parseString() noexcept(true);
23+
object parseArray() noexcept(false);
24+
object parseMap() noexcept(false);
25+
26+
void skipWhitespace() noexcept(true);
27+
bool shouldStringBeEscaped() noexcept(true);
28+
char getPrevChar() noexcept(true);
29+
char getCurrChar() noexcept(true);
3030

3131
public:
32-
parser();
33-
parser(std::string data);
34-
~parser();
32+
parser() noexcept(true);
33+
parser(std::string data) noexcept(false);
34+
~parser() noexcept(true);
3535

36-
object load(std::string path);
37-
object loads(std::string data);
36+
object load(std::string path) noexcept(false);
37+
object loads(std::string data) noexcept(false);
3838
};
3939

4040
} // namespace json

0 commit comments

Comments
 (0)