Class item_value
Defined in File item.hpp
Class Documentation
-
class item_value
The data is stored in this item_value type. It contains one of the five types from cif::item_value_type. Data is stored internally in the structure, except for strings larger than 7 characters. 99% of the character strings in a typical mmCIF file are 7 bytes or less, so this saves a lot of memory allocations.
Public Functions
-
inline item_value() noexcept
Construct an item_value containing the INAPPLICABLE value.
-
inline item_value(std::nullptr_t)
Construct an item_value containing the MISSING value.
-
inline item_value(item_value_type type) noexcept
Create an item_value containing the type specified by type and a default value for this type.
-
inline item_value(const item_value &rhs)
Copy constructor.
-
inline item_value(std::string_view s)
Construct an item_value containing the string s.
- template<size_t N> inline item_value (const char(s)[N])
Construct an item_value containing the string s.
-
inline item_value(const char *s)
Construct an item_value containing the string s.
-
inline item_value(const std::string &s)
Construct an item_value containing the string s.
-
template<IntegralType T>
inline item_value(T v) Construct an item_value containing the integer v.
-
template<FloatType T>
inline item_value(T v) Construct an item_value containing the double v No precission is recorded, so output will be as long as required to contain value.
-
template<FloatType T>
inline item_value(T v, int precision) Construct an item_value containing the double v If precision is not zero, output of this value to a file will use this precision. When parsing files, this precision is taken from the parsed string which will guarantee that the output of the data is the same as the input.
-
template<typename T>
inline item_value(std::optional<T> v) Construct an item_value containing either the value v or a MISSING type.
-
template<FloatType T>
inline item_value(std::optional<T> v, int precision) Construct an item_value containing the double v If precision is not zero, output of this value to a file will use this precision. When parsing files, this precision is taken from the parsed string which will guarantee that the output of the data is the same as the input. If v is emtpy, the proper MISSING value type will be used.
-
inline item_value(item_value &&rhs) noexcept
Move constructor.
-
inline item_value &operator=(item_value rhs) noexcept
We’re using modern move semantics.
-
inline bool is_inapplicable() const noexcept
Test if contained value is of type cif::item_value_type::INAPPLICABLE.
-
inline bool is_missing() const noexcept
Test if contained value is of type cif::item_value_type::MISSING.
-
inline bool is_null() const noexcept
Test if contained value is null, i.e. of type cif::item_value_type::INAPPLICABLE or cif::item_value_type::MISSING.
-
inline bool is_string() const noexcept
Test if contained value is a string, i.e. of type cif::item_value_type::TEXT.
-
inline bool is_number_int() const noexcept
Test if contained value is of type cif::item_value_type::INT.
-
inline bool is_number_float() const noexcept
Test if contained value is of type cif::item_value_type::FLOAT.
-
inline bool is_number() const noexcept
Test if contained value is a number, i.e. of type cif::item_value_type::INT or cif::item_value_type::FLOAT.
-
inline item_value_type type() const
Return the type of the contained value.
-
inline bool empty() const noexcept
Return true if the contained value is considered to be ‘empty’.
-
template<StringType T>
inline std::string get() const Return the string representation of the contained value.
-
template<IntegralType T>
inline std::remove_cvref_t<T> get() const Return the integer representation of the contained value. Will throw if the value cannot be cast to an integer
-
template<FloatType T>
inline std::remove_cvref_t<T> get() const Return the floating point representation of the contained value. Will throw if the value cannot be cast to the requested type
-
template<typename T>
inline auto get() const Return the std::optional<> wrapped value. The return value will not have a value if the contained value is missing or inapplicable. Will throw if the value cannot be cast to the requested type
-
std::string str() const
Return the string representation of the contained value.
-
inline const std::string_view sv() const
Return a std::string_view to the contained value. This will of course throw when the type is not cif::item_value_type::TEXT
-
inline auto operator<=>(const item_value &rhs) const noexcept
Three way comparison operator.
-
inline bool operator==(const item_value &rhs) const
Three way comparison operator is not always found TODO: find out why.
-
int compare(const item_value &b, bool ignore_case = false) const noexcept
Compare the value of this item_value with b, optionally ignoring case.
-
void cast_to_int()
Cast the value to an integer, will throw if not possible.
-
void cast_to_float()
Cast the value to a float, will throw if not possible.
-
void cast_to_string()
Cast the value to a string, may throw (when value is null).
Friends
-
inline friend void swap(item_value &a, item_value &b) noexcept
Swap two item_values.
-
friend std::ostream &operator<<(std::ostream &os, const item_value &v)
For debugging, print out a value.
-
inline item_value() noexcept