Property

class 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

enum chemfiles::Propertykind

Possible types holded by a property.

Values:

chemfiles::PropertyBOOL = 0
chemfiles::PropertyDOUBLE = 1
chemfiles::PropertySTRING = 2
chemfiles::PropertyVECTOR3D = 3

Public Functions

chemfiles::PropertyProperty(bool value)

Create a property holding a boolean value.

auto property = Property(false);

assert(property.get_kind() == Property::BOOL);
assert(property.as_bool() == false);

chemfiles::PropertyProperty(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

chemfiles::PropertyProperty(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));

chemfiles::PropertyProperty(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");

chemfiles::PropertyProperty(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");

chemfiles::PropertyProperty(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

chemfiles::PropertyProperty(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

chemfiles::PropertyProperty(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

chemfiles::PropertyProperty(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

chemfiles::PropertyProperty(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

chemfiles::PropertyProperty(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

kind chemfiles::Propertyget_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);

bool chemfiles::Propertyas_bool() const

Get the boolean value stored in this Property

auto property = Property(false);
assert(property.as_bool() == false);

Exceptions

double chemfiles::Propertyas_double() const

Get the double value stored in this Property

auto property = Property(45.2);
assert(property.as_double() == 45.2);

Exceptions

Vector3D chemfiles::Propertyas_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));

Exceptions

const std::string &chemfiles::Propertyas_string() const

Get the string value stored in this Property

// from a std::string
auto property = Property("foo");
assert(property.as_string() == "foo");

Exceptions