PProperties Class Reference

Detailed Description

The PProperties class represents a container of properties; each property has a name (PString) and a value which can be any Papillon object (PObject).

How to iterate over a PProperties container?

PProperties properties;
for (PStringMapIterator it = properties.Iterator(); it.HasNext(); it.Next())
{
PString key = it.GetKey();
PObject value = it.GetValue();
}

This container is thread-safe.

Definition at line 38 of file PProperties.h.

#include <PProperties.h>

Constructor & Destructor Documentation

◆ PProperties() [1/2]

PProperties::PProperties ( )

Constructs an empty container of properties.

◆ PProperties() [2/2]

PProperties::PProperties ( const PProperties other)

Constructs a shared copy of other.

Member Function Documentation

◆ Clone()

PProperties PProperties::Clone ( ) const

Returns a shallow copy of this object (only the container is cloned, not contained objects).

◆ CreateFromKeyValueString()

static PProperties PProperties::CreateFromKeyValueString ( const PString s)
static

Constructs a container of properties from a key/value string.

Example: "object;type=color;r=128;g=32;b=64" => returns a container containing 5 properties: ("object" -> "" ; "type" -> "color" ; "r" -> "128" ; "g" -> "32" ; "b" -> "64").

Notes:

  • Types of properties are always string.
  • Properties with no value (jut a key) are associated with an empty string.

◆ Destringify()

static PResult PProperties::Destringify ( const PString propertyType,
const PString propertyValue,
PObject object 
)
static

Converts a pair (string, string) = (type, stringValue) to a papillon PObject.

This function expects one of the following type: PString, PDateTime, PGuid, PInt32, PInt64, PFloat, PDouble, PBool, or "base64" to indicate a base64 representation of a serialised papillon object.

Returns PResult::C_OK if success, another result otherwise.

◆ Empty()

static const PProperties& PProperties::Empty ( )
inlinestatic

Returns the constant holding an empty PProperties container.

Definition at line 44 of file PProperties.h.

◆ GetAsString()

PString PProperties::GetAsString ( const PString name) const

Gets a string representation of the specified property or an empty string if the property does not exist.

◆ GetBool()

bool PProperties::GetBool ( const PString key,
bool *  ok = NULL 
) const

Returns the specified bool value.

If the value does not exist or the specified key is not associated with a PBool, returns false.

◆ GetDouble()

double PProperties::GetDouble ( const PString key,
bool *  ok = NULL 
) const

Returns the specified double value.

If the value does not exist or the specified key is not associated with a PDouble, returns PMath::NaNd().

◆ GetFloat()

float PProperties::GetFloat ( const PString key,
bool *  ok = NULL 
) const

Returns the specified float value.

If the value does not exist or the specified key is not associated with a PFloat, returns PMath::NaNf().

◆ GetInt32()

papillon::int32 PProperties::GetInt32 ( const PString key,
bool *  ok = NULL 
) const

Returns the specified int32 value.

If the value does not exist or the specified key is not associated with a PInt32, returns -1.

◆ GetInt64()

papillon::int64 PProperties::GetInt64 ( const PString key,
bool *  ok = NULL 
) const

Returns the specified int64 value.

If the value does not exist or the specified key is not associated with a PInt64, returns -1.

◆ operator=()

PProperties& PProperties::operator= ( const PProperties other)

Performs a shared copy of other to this object.

◆ RemoveByRegexp()

int32 PProperties::RemoveByRegexp ( const PString pattern)

Removes all the properties with a name matching the specified "Perl" regular expression.

Returns the number of removed properties.

◆ Set() [1/7]

PProperties& PProperties::Set ( const PString key,
const PObject value 
)

DEPRECATED, use SetObject() instead.

Sets the specified property. If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ Set() [2/7]

PProperties& PProperties::Set ( const PString key,
const char *  value 
)

DEPRECATED, use SetString() instead.

An helper to set a PString property (auto-boxing, same as Set(key, PString(value)). If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ Set() [3/7]

PProperties& PProperties::Set ( const PString key,
bool  value 
)

DEPRECATED, use SetBool() instead.

An helper to set a bool property (auto-boxing, same as Set(key, PBool(value)). If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ Set() [4/7]

PProperties& PProperties::Set ( const PString key,
papillon::int32  value 
)

DEPRECATED, use SetInt32() instead.

An helper to set a int32 property (auto-boxing, same as Set(key, PIn32(value)). If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ Set() [5/7]

PProperties& PProperties::Set ( const PString key,
papillon::int64  value 
)

DEPRECATED, use SetInt32() instead.

An helper to set a int64 property (auto-boxing, same as Set(key, PIn64(value)). If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ Set() [6/7]

PProperties& PProperties::Set ( const PString key,
float  value 
)

DEPRECATED, use SetFloat() instead.

An helper to set a float property (auto-boxing, same as Set(key, PFloat(value)). If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ Set() [7/7]

PProperties& PProperties::Set ( const PString key,
double  value 
)

DEPRECATED, use SetDouble() instead.

An helper to set a double property (auto-boxing, same as Set(key, PDouble(value)). If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ SetBool()

PProperties& PProperties::SetBool ( const PString key,
bool  value 
)

An helper to set a bool property (auto-boxing, same as Set(key, PBool(value)).

If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ SetDouble()

PProperties& PProperties::SetDouble ( const PString key,
double  value 
)

An helper to set a double property (auto-boxing, same as Set(key, PDouble(value)).

If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ SetFloat()

PProperties& PProperties::SetFloat ( const PString key,
float  value 
)

An helper to set a float property (auto-boxing, same as Set(key, PFloat(value)).

If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ SetInt32()

PProperties& PProperties::SetInt32 ( const PString key,
papillon::int32  value 
)

An helper to set a int32 property (auto-boxing, same as Set(key, PIn32(value)).

If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ SetInt64()

PProperties& PProperties::SetInt64 ( const PString key,
papillon::int64  value 
)

An helper to set a int64 property (auto-boxing, same as Set(key, PIn64(value)).

If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ SetObject()

PProperties& PProperties::SetObject ( const PString key,
const PObject value 
)

Sets the specified property.

If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ SetString()

PProperties& PProperties::SetString ( const PString key,
const char *  value 
)

An helper to set a PString property (auto-boxing, same as Set(key, PString(value)).

If a property with the specified name already exists, the value is replaced. Call to Set() can be chained.

◆ Stringify()

static PResult PProperties::Stringify ( const PObject object,
PString propertyType,
PString propertyValue 
)
static

Converts any PObject to a pair (string, string) = (type, stringValue).

The following rules applies:

Input object type Output type Output value
PString "PString" the string itself
PDateTime "PDateTime" ISO representation with milliseconds
PGuid "PGuid" standard string representation
PVersion "PVersion" "X.Y.Z.W"
PInt32 "PInt32" int value to string
PInt64 "PInt64" int value to string
PFloat "PFloat" float value to string
PDouble "PDouble" double value to string
PBool "PBool" "true" or "false"
all others "base64" base64 representation of the serialised object

Returns PResult::C_OK if success, another result otherwise.

◆ ToStringLog()

PString PProperties::ToStringLog ( ) const

Returns a string representation of this object (human readable).