Loading...
Searching...
No Matches
Optional.hpp
/*
* Open Chinese Convert
*
* Copyright 2010-2014 Carbo Kuo <byvoid@byvoid.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
namespace opencc {
template <typename T> class Optional {
public:
Optional(T actual) : isNull(false), data(actual) {}
bool IsNull() const { return isNull; }
const T& Get() const { return data; }
static Optional<T> Null() { return Optional(); }
private:
Optional() : isNull(true) {}
bool isNull;
T data;
};
template <typename T> class Optional<T*> {
private:
Optional() : data(nullptr) {}
typedef T* TPtr;
TPtr data;
public:
Optional(TPtr actual) : data(actual) {}
bool IsNull() const { return data == nullptr; }
const TPtr& Get() const { return data; }
static Optional<TPtr> Null() { return Optional(); }
};
} // namespace opencc
opencc::Optional::Get
const T & Get() const
Returns the containing data of the instance.
Definition Optional.hpp:41
opencc::Optional::IsNull
bool IsNull() const
Returns true if the instance is null.
Definition Optional.hpp:36
opencc::Optional::Null
static Optional< T > Null()
Constructs a null instance.
Definition Optional.hpp:46
opencc::Optional::Optional
Optional(T actual)
The constructor of Optional.
Definition Optional.hpp:31