cpp-msgpack-light 0.3.0
A light library to serialize MessagePack.
Loading...
Searching...
No Matches
object.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cstring>
23
24#include "msgpack_light/details/allocator_wrapper.h" // IWYU pragma: export
25#include "msgpack_light/details/array_iterator.h" // IWYU pragma: export
26#include "msgpack_light/details/array_iterator_impl.h" // IWYU pragma: export
27#include "msgpack_light/details/array_ref.h" // IWYU pragma: export
28#include "msgpack_light/details/array_ref_impl.h" // IWYU pragma: export
29#include "msgpack_light/details/extension_ref.h" // IWYU pragma: export
30#include "msgpack_light/details/map_iterator.h" // IWYU pragma: export
31#include "msgpack_light/details/map_iterator_impl.h" // IWYU pragma: export
32#include "msgpack_light/details/map_ref.h" // IWYU pragma: export
33#include "msgpack_light/details/map_ref_impl.h" // IWYU pragma: export
34#include "msgpack_light/details/object_base.h" // IWYU pragma: export
35#include "msgpack_light/details/object_data.h" // IWYU pragma: export
36#include "msgpack_light/details/object_helper.h" // IWYU pragma: export
37#include "msgpack_light/details/object_ref.h" // IWYU pragma: export
38#include "msgpack_light/details/object_ref_decl.h" // IWYU pragma: export
40
41namespace msgpack_light {
42
48template <typename Allocator = standard_allocator>
49class object
50 : public details::mutable_object_base<object<Allocator>, Allocator> {
51public:
53 using base_type =
55
56#ifndef MSGPACK_LIGHT_DOCUMENTATION
57 using base_type::clear;
58 using typename base_type::allocator_type;
59#endif
60
65
73
79 object(const object& other) : allocator_(other.allocator_) {
81 }
82
88 object(object&& other) noexcept
89 : data_(other.data_), allocator_(std::move(other.allocator_)) {
90 std::memset(&other.data_, 0, sizeof(other.data_));
91 }
92
99 object& operator=(const object& other) {
100 if (this == &other) {
101 return *this;
102 }
103 clear();
105 return *this;
106 }
107
114 object& operator=(object&& other) noexcept {
115 swap(other);
116 return *this;
117 }
118
124 void swap(object& other) noexcept {
125 std::swap(data_, other.data_);
126 std::swap(allocator_, other.allocator_);
127 }
128
132 ~object() { clear(); }
133
135
142
148 [[nodiscard]] details::object_data& data() noexcept { return data_; }
149
155 [[nodiscard]] const details::object_data& data() const noexcept {
156 return data_;
157 }
158
165 return allocator_;
166 }
167
169
170private:
173
176};
177
178} // namespace msgpack_light
Definition of allocator_wrapper class.
Definition of classes of iterators of arrays.
Implementation of classes of iterators of arrays.
Definition of classes of references to arrays.
Implementation of classes of references to arrays.
Base class of non-constant objects in MessagePack.
details::allocator_wrapper< Allocator > allocator_
Allocator.
Definition object.h:175
details::object_data & data() noexcept
Get the internal data.
Definition object.h:148
~object()
Destructor.
Definition object.h:132
object(allocator_type allocator=allocator_type())
Constructor.
Definition object.h:71
object & operator=(const object &other)
Copy assignment operator.
Definition object.h:99
const details::object_data & data() const noexcept
Get the internal data.
Definition object.h:155
details::mutable_object_base< object< Allocator >, Allocator > base_type
Type of the base class.
Definition object.h:53
object(const object &other)
Copy constructor.
Definition object.h:79
details::allocator_wrapper< Allocator > & allocator() noexcept
Get the allocator.
Definition object.h:164
object(object &&other) noexcept
Move constructor.
Definition object.h:88
details::object_data data_
Data.
Definition object.h:172
object & operator=(object &&other) noexcept
Move assignment operator.
Definition object.h:114
void swap(object &other) noexcept
Swap this instance with another instance.
Definition object.h:124
Definition of classes of references to extension values.
Definition of classes of iterators of maps.
Definition of classes of iterators of maps.
Definition of classes of references to maps.
Implementation of classes of references of maps.
void copy_object_data(object_data &to, const object_data &from, allocator_wrapper< Allocator > &allocator)
Copy data.
Namespace of this project.
Definition binary.h:33
STL namespace.
void swap(msgpack_light::details::basic_binary_buffer &instance1, msgpack_light::details::basic_binary_buffer &instance2) noexcept
Implementation of std::swap for msgpack_light::details::basic_binary_buffer.
Definition of base classes of objects.
Definition of object_data struct.
Definition of helper functions for implementation of object class.
Definition of classes of references to objects.
Declaration of classes of references to objects.
Definition of standard_allocator class.
Struct of data of objects in MessagePack.
Definition object_data.h:94