Open Chinese Convert: Optional.hpp Source File

Open Chinese Convert 1.0.2 A project for conversion between Traditional and Simplified Chinese

- Main Page
- Modules
- Classes
- Examples

All Classes Functions Typedefs Modules
Optional.hpp
1 /*
2 * Open Chinese Convert
3 *
4 * Copyright 2010-2014 BYVoid <byvoid@byvoid.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #pragma once
20
21 namespace opencc {
26 template<typename T>
27 class Optional {
28 public:
32 Optional(T actual) : isNull(false), data(actual) {
33 }
34
38 bool IsNull() const {
39 return isNull;
40 }
41
45 const T& Get() const {
46 return data;
47 }
48
52 static Optional<T> Null() {
53 return Optional();
54 }
55
56 private:
57 Optional() : isNull(true) {
58 }
59
60 bool isNull;
61 T data;
62 };
63
69 template<typename T>
70 class Optional<T*> {
71 private:
72 Optional() : data(nullptr) {
73 }
74
75 typedef T* TPtr;
76 TPtr data;
77
78 public:
79 Optional(TPtr actual) : data(actual) {
80 }
81
82 bool IsNull() const {
83 return data == nullptr;
84 }
85
86 const TPtr& Get() const {
87 return data;
88 }
89
90 static Optional<TPtr> Null() {
91 return Optional();
92 }
93 };
94
95 }
opencc::Optional::Get
const T & Get() const
Returns the containing data of the instance.
Definition: Optional.hpp:45
opencc::Optional::Null
static Optional< T > Null()
Constructs a null instance.
Definition: Optional.hpp:52
opencc
Definition: BinaryDict.hpp:24
opencc::Optional::Optional
Optional(T actual)
The constructor of Optional.
Definition: Optional.hpp:32
opencc::Optional
A class that wraps type T into a nullable type.
Definition: Optional.hpp:27
opencc::Optional::IsNull
bool IsNull() const
Returns true if the instance is null.
Definition: Optional.hpp:38