chemfiles::Property¶This class holds the data used in properties by the Atom and the Frame classes. A property can have various types: bool, double, string or Vector3D.
Public Types
Public Functions
Property(bool value)¶Create a property holding a boolean value.
auto property = Property(false);
assert(property.get_kind() == Property::BOOL);
assert(property.as_bool() == false);
Property(double value)¶Create a property holding a double value.
auto property = Property(45.2);
assert(property.get_kind() == Property::DOUBLE);
assert(property.as_double() == 45.2);
// Various overload convert integers to double
assert(Property(45).get_kind() == Property::DOUBLE); // int
assert(Property(45l).get_kind() == Property::DOUBLE); // long
assert(Property(45ll).get_kind() == Property::DOUBLE); // long long
assert(Property(45u).get_kind() == Property::DOUBLE); // unsigned
assert(Property(45ul).get_kind() == Property::DOUBLE); // unsigned long
assert(Property(45ull).get_kind() == Property::DOUBLE); // unsigned long long
Property(Vector3D value)¶Create a property holding a Vector3D value.
auto property = Property(Vector3D(11, 22, 33));
assert(property.get_kind() == Property::VECTOR3D);
assert(property.as_vector3d() == Vector3D(11, 22, 33));
Property(std::string value)¶Create a property holding a string value.
// from a std::string
auto property = Property(std::string("foo"));
assert(property.get_kind() == Property::STRING);
assert(property.as_string() == "foo");
// from a const char*
property = Property("bar");
assert(property.get_kind() == Property::STRING);
assert(property.as_string() == "bar");
Property(const char *value)¶Create a property holding a string value from a const char*.
// from a std::string
auto property = Property(std::string("foo"));
assert(property.get_kind() == Property::STRING);
assert(property.as_string() == "foo");
// from a const char*
property = Property("bar");
assert(property.get_kind() == Property::STRING);
assert(property.as_string() == "bar");
Property(int value)¶Create a property holding a double value from an int.
auto property = Property(45.2);
assert(property.get_kind() == Property::DOUBLE);
assert(property.as_double() == 45.2);
// Various overload convert integers to double
assert(Property(45).get_kind() == Property::DOUBLE); // int
assert(Property(45l).get_kind() == Property::DOUBLE); // long
assert(Property(45ll).get_kind() == Property::DOUBLE); // long long
assert(Property(45u).get_kind() == Property::DOUBLE); // unsigned
assert(Property(45ul).get_kind() == Property::DOUBLE); // unsigned long
assert(Property(45ull).get_kind() == Property::DOUBLE); // unsigned long long
Property(long value)¶Create a property holding a double value from a long.
auto property = Property(45.2);
assert(property.get_kind() == Property::DOUBLE);
assert(property.as_double() == 45.2);
// Various overload convert integers to double
assert(Property(45).get_kind() == Property::DOUBLE); // int
assert(Property(45l).get_kind() == Property::DOUBLE); // long
assert(Property(45ll).get_kind() == Property::DOUBLE); // long long
assert(Property(45u).get_kind() == Property::DOUBLE); // unsigned
assert(Property(45ul).get_kind() == Property::DOUBLE); // unsigned long
assert(Property(45ull).get_kind() == Property::DOUBLE); // unsigned long long
Property(long long value)¶Create a property holding a double value from a long long.
auto property = Property(45.2);
assert(property.get_kind() == Property::DOUBLE);
assert(property.as_double() == 45.2);
// Various overload convert integers to double
assert(Property(45).get_kind() == Property::DOUBLE); // int
assert(Property(45l).get_kind() == Property::DOUBLE); // long
assert(Property(45ll).get_kind() == Property::DOUBLE); // long long
assert(Property(45u).get_kind() == Property::DOUBLE); // unsigned
assert(Property(45ul).get_kind() == Property::DOUBLE); // unsigned long
assert(Property(45ull).get_kind() == Property::DOUBLE); // unsigned long long
Property(unsigned value)¶Create a property holding a double value from an unsigned.
auto property = Property(45.2);
assert(property.get_kind() == Property::DOUBLE);
assert(property.as_double() == 45.2);
// Various overload convert integers to double
assert(Property(45).get_kind() == Property::DOUBLE); // int
assert(Property(45l).get_kind() == Property::DOUBLE); // long
assert(Property(45ll).get_kind() == Property::DOUBLE); // long long
assert(Property(45u).get_kind() == Property::DOUBLE); // unsigned
assert(Property(45ul).get_kind() == Property::DOUBLE); // unsigned long
assert(Property(45ull).get_kind() == Property::DOUBLE); // unsigned long long
Property(unsigned long value)¶Create a property holding a double value from an unsigned long.
auto property = Property(45.2);
assert(property.get_kind() == Property::DOUBLE);
assert(property.as_double() == 45.2);
// Various overload convert integers to double
assert(Property(45).get_kind() == Property::DOUBLE); // int
assert(Property(45l).get_kind() == Property::DOUBLE); // long
assert(Property(45ll).get_kind() == Property::DOUBLE); // long long
assert(Property(45u).get_kind() == Property::DOUBLE); // unsigned
assert(Property(45ul).get_kind() == Property::DOUBLE); // unsigned long
assert(Property(45ull).get_kind() == Property::DOUBLE); // unsigned long long
Property(unsigned long long value)¶Create a property holding a double value from an unsigned long long.
auto property = Property(45.2);
assert(property.get_kind() == Property::DOUBLE);
assert(property.as_double() == 45.2);
// Various overload convert integers to double
assert(Property(45).get_kind() == Property::DOUBLE); // int
assert(Property(45l).get_kind() == Property::DOUBLE); // long
assert(Property(45ll).get_kind() == Property::DOUBLE); // long long
assert(Property(45u).get_kind() == Property::DOUBLE); // unsigned
assert(Property(45ul).get_kind() == Property::DOUBLE); // unsigned long
assert(Property(45ull).get_kind() == Property::DOUBLE); // unsigned long long
get_kind() const¶Get the kind of property, i.e. the type of the holded value
assert(Property(42).get_kind() == Property::DOUBLE);
assert(Property(false).get_kind() == Property::BOOL);
assert(Property("string").get_kind() == Property::STRING);
assert(Property(Vector3D(1, 2, 3)).get_kind() == Property::VECTOR3D);
as_bool() const¶Get the boolean value stored in this Property
auto property = Property(false);
assert(property.as_bool() == false);
PropertyError: if this property does not hold a boolean value as_double() const¶Get the double value stored in this Property
auto property = Property(45.2);
assert(property.as_double() == 45.2);
PropertyError: if this property does not hold a double value as_vector3d() const¶Get the Vector3D value stored in this Property
auto property = Property(Vector3D(11, 22, 33));
assert(property.as_vector3d() == Vector3D(11, 22, 33));
PropertyError: if this property does not hold a Vector3D value as_string() const¶Get the string value stored in this Property
// from a std::string
auto property = Property("foo");
assert(property.as_string() == "foo");
PropertyError: if this property does not hold a string value