1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "config_clang.h"
12 template <typename Type
> class OptValue
20 explicit OptValue(const Type
& rValue
)
26 bool has_value() const { return mbHasValue
; }
27 bool operator!() const { return !mbHasValue
; }
29 const Type
& value() const { return maValue
; }
30 const Type
& value_or(const Type
& rDefValue
) const { return mbHasValue
? maValue
: rDefValue
; }
32 Type
& operator*() { return maValue
; }
40 OptValue
& operator=(const Type
& rValue
)
46 bool operator==(const OptValue
& rValue
) const
48 return ((!mbHasValue
&& rValue
.mbHasValue
== false)
49 || (mbHasValue
== rValue
.mbHasValue
&& maValue
== rValue
.maValue
));
59 OptValue
<int> getInteger();
64 void foo(AttributeList
& rAttrs
)
66 // expected-error@+1 {{call to OptValue::value() [loplugin:optvalue]}}
67 rAttrs
.getInteger().value();
69 // no warning expected
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */