Argo  1.0
A C++ library for handling JSON.
token.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Andrew Haisley
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 
24 
25 #include "common.hpp"
26 #include "token.hpp"
27 
28 using namespace std;
29 using namespace NAMESPACE;
30 
31 token::token() noexcept : m_type(null_e)
32 {
33 }
34 
35 token::token(const token &other)
36 {
37  *this = other;
38 }
39 
40 token::token(token &&other)
41 {
42  *this = other;
43 }
44 
45 token &token::operator=(const token &other)
46 {
47  if (this != &other)
48  {
49  m_type = other.m_type;
50  m_raw_value = other.m_raw_value;
51  }
52  return *this;
53 }
54 
55 token &token::operator=(token &&other)
56 {
57  if (this != &other)
58  {
59  m_type = other.m_type;
60  other.m_type = null_e;
61  m_raw_value = move(other.m_raw_value);
62  }
63  return *this;
64 }
65 
66 token::token(token_type t) : m_type(t)
67 {
68 }
69 
70 token::token(token_type t, const char *raw_value, size_t len) : m_raw_value(raw_value, len), m_type(t)
71 {
72 }
73 
75 {
76 }
77 
78 const string &token::get_raw_value() const
79 {
80  return m_raw_value;
81 }
82 
84 {
85  return m_type;
86 }
const std::string & get_raw_value() const
Get the raw untranslated JSON value.
Definition: token.cpp:78
#define NAMESPACE
You can change the namespace of the whole library by changing this value.
Definition: common.hpp:29
The token class.
STL namespace.
Common defs needed everywhere and, as far as is possible, platform specific changes.
Lexical tokens read from a JSON message.
Definition: token.hpp:41
token() noexcept
Constructor. null token.
Definition: token.cpp:31
token_type
Type of the token. Matches the RFC except that ints and floats are separated out. ...
Definition: token.hpp:46
token_type get_type() const
Get the token type.
Definition: token.cpp:83
virtual ~token()
Definition: token.cpp:74