24 #ifndef PXR_USD_SDF_ALLOWED_H 25 #define PXR_USD_SDF_ALLOWED_H 30 #include "pxr/usd/sdf/api.h" 35 #include <boost/operators.hpp> 36 #include <boost/optional.hpp> 38 PXR_NAMESPACE_OPEN_SCOPE
47 class SdfAllowed :
private boost::equality_comparable<SdfAllowed> {
49 typedef boost::optional<std::string> _State;
52 typedef std::pair<bool, std::string> Pair;
59 SdfAllowed(
const char* whyNot) : _state(std::string(whyNot)) { }
61 SdfAllowed(
const std::string& whyNot) : _state(whyNot) { }
64 _state(!condition, std::string(whyNot)) { }
67 _state(!condition, whyNot) { }
69 SdfAllowed(
const Pair& x) : _state(!x.first, x.second) { }
73 typedef _State
SdfAllowed::*UnspecifiedBoolType;
77 operator UnspecifiedBoolType()
const 79 return _state ? NULL : &SdfAllowed::_state;
85 return static_cast<bool>(_state);
90 operator const std::string&()
const 97 SDF_API
const std::string&
GetWhyNot()
const;
103 if (whyNot && _state) {
113 return _state == other._state;
120 PXR_NAMESPACE_CLOSE_SCOPE
122 #endif // PXR_USD_SDF_ALLOWED_H SdfAllowed()
Construct true.
bool IsAllowed(std::string *whyNot) const
Returns true if allowed, otherwise fills whyNot if not NULL and returns false.
Low-level utilities for informing users of various internal and external diagnostic conditions.
SDF_API const std::string & GetWhyNot() const
Returns the reason why the operation is not allowed.
SdfAllowed(const Pair &x)
Construct from bool,string pair x.
bool operator==(const SdfAllowed &other) const
Compare to other.
Indicates if an operation is allowed and, if not, why not.
SdfAllowed(bool x)
Construct true.
SdfAllowed(bool condition, const char *whyNot)
Construct in condition with annotation whyNot if false.
SdfAllowed(const char *whyNot)
Construct false with annotation whyNot.
#define TF_AXIOM(cond)
Aborts if the condition cond is not met.
SdfAllowed(const std::string &whyNot)
Construct false with annotation whyNot.
SdfAllowed(bool condition, const std::string &whyNot)
Construct in condition with annotation whyNot if false.
bool operator!() const
Returns false in a boolean context if allowed, true otherwise.