optional_impl.h revision fe38dd8c9780b599cf2eff09ff6fbf60fbe9ab76
1/*
2 * Copyright (C) 2016 The Android Open Source Project
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 */
16
17#ifndef UTIL_CHRE_OPTIONAL_IMPL_H_
18#define UTIL_CHRE_OPTIONAL_IMPL_H_
19
20#include "chre/util/optional.h"
21
22namespace chre {
23
24template<typename ObjectType>
25bool Optional<ObjectType>::has_value() const {
26  return mHasValue;
27}
28
29template<typename ObjectType>
30void Optional<ObjectType>::reset() {
31  mObject.~ObjectType();
32  mHasValue = false;
33}
34
35template<typename ObjectType>
36Optional<ObjectType>& Optional<ObjectType>::operator=(ObjectType&& other) {
37  mObject = std::move(other);
38  mHasValue = true;
39  return *this;
40}
41
42template<typename ObjectType>
43Optional<ObjectType>& Optional<ObjectType>::operator=(const ObjectType& other) {
44  mObject = other;
45  mHasValue = true;
46  return *this;
47}
48
49template<typename ObjectType>
50ObjectType& Optional<ObjectType>::operator*() {
51  return mObject;
52}
53
54template<typename ObjectType>
55ObjectType *Optional<ObjectType>::operator->() {
56  return &mObject;
57}
58
59}  // namespace chre
60
61#endif  // UTIL_CHRE_OPTIONAL_IMPL_H_
62