blob: 9ce0ce27248a135c333b06a55fa0d4509f627d7f [file] [log] [blame]
Alex Vakulenkob6513a12014-05-05 17:23:40 -07001// Copyright 2014 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "buffet/any.h"
6
7#include <algorithm>
8
9namespace buffet {
10
11Any::Any(const Any& rhs) : data_buffer_(rhs.data_buffer_) {
12}
13
14Any::~Any() {
15}
16
17Any& Any::operator=(const Any& rhs) {
18 data_buffer_ = rhs.data_buffer_;
19 return *this;
20}
21
22const std::type_info& Any::GetType() const {
23 if (!IsEmpty())
24 return data_buffer_.GetDataPtr()->GetType();
25
26 struct NullType {}; // Special helper type representing an empty variant.
27 return typeid(NullType);
28}
29
30void Any::Swap(Any& other) {
31 std::swap(data_buffer_, other.data_buffer_);
32}
33
34bool Any::IsEmpty() const {
35 return data_buffer_.IsEmpty();
36}
37
38void Any::Clear() {
39 data_buffer_.Clear();
40}
41
42bool Any::IsConvertibleToInteger() const {
43 return !IsEmpty() && data_buffer_.GetDataPtr()->IsConvertibleToInteger();
44}
45
46intmax_t Any::GetAsInteger() const {
47 CHECK(!IsEmpty()) << "Must not be called on an empty Any";
48 return data_buffer_.GetDataPtr()->GetAsInteger();
49}
50
51} // namespace buffet