#include <stlsoft/properties/field_properties.hpp>
class ClassWithReadOnlyProp { public: // Member Types typedef std::string string_type; typedef int index_type; public: // Construction ClassWithReadOnlyProp(char const* instanceName, index_type instanceIndex) : name(instanceName) // Property value can be initialised inside enclosing class , index(1) // Property value can be initialised inside enclosing class {} public: // Operations void ReBadge(char const* newInstanceName, index_type newInstanceIndex) { name = newInstanceName; // Property value can be assigned inside enclosing class index = newInstanceIndex; // Property value can be assigned inside enclosing class } public: // Properties stlsoft::field_property_get<index_type, index_type, ClassWithReadOnlyProp> index; stlsoft::field_property_get<string_type, string_type const&, ClassWithReadOnlyProp> name; }; . . . ClassWithReadOnlyProp c("Object-#1", 1); int index = c.index; // Ok: access the value of the read-only property std::string const &name = c.name; // Ok: access the value of the read-only property c.index = 2; // Compile error: cannnot write to the read-only property c.name = "new name"; // Compile error: cannnot write to the read-only property
by_library/properties/field_property_get/field_property_get.cpp, by_library/properties/field_property_set/field_property_set.cpp, and by_library/properties/properties/properties.cpp.
Public Types | |
typedef V | value_type |
typedef R | reference_type |
typedef C | container_type |
typedef field_property_get< V, R, C > | class_type |
Public Member Functions | |
operator reference_type () const | |
Provides read-only access to the property. |
operator reference_type | ( | ) | const [inline] |
Provides read-only access to the property.