C12Adapter Opensource C++ Interface
MRegistry Class Reference

Provides the access to Windows registry, system dependent class. More...

Inheritance diagram for MRegistry:

Public Types

enum  PredefinedKeyEnum {
  KeyClassesRoot = 0,
  KeyCurrentUser = 1,
  KeyLocalMachine = 2,
  KeyUsers = 3
}
 Key type within the registry, determines the location of the registry hive. More...
 

Public Member Functions

 MRegistry ()
 Creates an empty uninitialized registry access object. More...
 
 MRegistry (const MRegistry &parent, const MStdString &subLocation)
 Creates a sub-entry of the given opened registry object. More...
 
virtual ~MRegistry ()
 Object destructor, closes the registry access object and frees the resources.
 
MStdStringVector GetAllSubkeys () const
 Get the list of subkeys in the registry. More...
 
MStdStringVector GetAllValues () const
 Get the list of value names in the registry access object. More...
 
bool IsOpen () const
 Tells whether the registry is open. More...
 
bool IsReadOnly () const
 Tells whether the registry access object is read-only. More...
 
void Open (PredefinedKeyEnum parentKey, const MStdString &location, bool readonly)
 Open the registry folder for the desired access. More...
 
void OpenSubkey (const MRegistry &parent, const MStdString &subLocation)
 Open a sub-entry of the given opened registry object. More...
 
void Close ()
 Make sure the changes are flushed into persistent storage and close the registry. More...
 
bool IsPresent (const MStdString &keyOrValue) const
 Whether the key or value with such name is present in the open registry access object. More...
 
bool IsSubkeyPresent (const MStdString &key) const
 Whether the key with such name is present in the open registry access object. More...
 
bool IsValuePresent (const MStdString &valueName) const
 Whether the value with such name is present in the open registry access object. More...
 
MStdString GetString (const MStdString &valueName, const MStdString &defaultValue) const
 Get the string representation of the value name, or default if value with such name does not exist. More...
 
MStdString GetExistingString (const MStdString &valueName) const
 Get the string representation of the value associated with the value name given. More...
 
int GetInteger (const MStdString &valueName, int defaultValue) const
 Get the integer representation of the value name, or default if value with such name does not exist. More...
 
int GetExistingInteger (const MStdString &valueName) const
 Get the integer representation of the value associated with the value name given. More...
 
MByteString GetBinary (const MStdString &valueName, const MByteString &defaultValue) const
 Get the binary representation of the value name, or default if value with such name does not exist. More...
 
MByteString GetExistingBinary (const MStdString &valueName) const
 Get the binary representation of the value associated with the value name given. More...
 
void SetString (const MStdString &valueName, const MStdString &value)
 Associate the given string value with the name. More...
 
void SetInteger (const MStdString &valueName, int value)
 Associate the given integer value with the name. More...
 
void SetBinary (const MStdString &valueName, const MByteString &value)
 Associate the given binary value with the name. More...
 
void Remove (const MStdString &keyOrValue)
 Remove either the key or the value with such name from the registry access object. More...
 
void RemoveValue (const MStdString &valueName)
 Remove value with such name from the registry access object. More...
 
void RemoveSubkey (const MStdString &key)
 Remove key with such name from the registry. More...
 
void CheckIfOpen () const
 Check if the registry access object is open, throw an exception otherwise. More...
 
 MRegistry (PredefinedKeyEnum parentKey, const MStdString &location, bool readonly)
 
 MRegistry (PredefinedKeyEnum parentKey, const char *location, bool readonly)
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Provides the access to Windows registry, system dependent class.

Only string data types are supported for values, however MRegistry provides services that allow handling them as integers. There is no check provided, and for example, one can store 1.2 as string, and read it as a rounded integer, or vice versa.

It is possible to request read-only access to a registry.

Since
MeteringSDK Version 6.4.0.4870.

Member Enumeration Documentation

Key type within the registry, determines the location of the registry hive.

Enumerator
KeyClassesRoot 

Classes root, corresponds to HKEY_CLASSES_ROOT, if added mask 0x80000000.

KeyCurrentUser 

Current user, corresponds to HKEY_CURRENT_USER, if added mask 0x80000000.

KeyLocalMachine 

Local machine, corresponds to HKEY_LOCAL_MACHINE, if added mask 0x80000000.

KeyUsers 

All users, corresponds to HKEY_USERS, if added mask 0x80000000.

Constructor & Destructor Documentation

MRegistry::MRegistry ( )

Creates an empty uninitialized registry access object.

See also
Open - the next logical step after registry access object is created
MRegistry::MRegistry ( PredefinedKeyEnum  parentKey,
const MStdString location,
bool  readonly 
)
explicit

Initializes the registry from location.

It allows opening global versus user registry access object, as read-only or read-write.

Parameters
parentKeyPredefined key to use as parent, any of these enumeration values:
locationA string that defines the location within the registry, as described in class header.
readonlyWhen true, the registry is opened in read-only mode. Otherwise, and this is the default, the registry is open for both reading and writing.
Precondition
The location is valid and the requested access is allowed, otherwise the exception is thrown.
MRegistry::MRegistry ( PredefinedKeyEnum  parentKey,
const char *  location,
bool  readonly 
)
explicit

Initializes the registry from location.

It allows opening global versus user registry access object, as read-only or read-write.

Parameters
parentKeyPredefined key to use as parent, any of these enumeration values:
locationA string that defines the location within the registry, as described in class header.
readonlyWhen true, the registry is opened in read-only mode. Otherwise, and this is the default, the registry is open for both reading and writing.
Precondition
The location is valid and the requested access is allowed, otherwise the exception is thrown.
MRegistry::MRegistry ( const MRegistry parent,
const MStdString subLocation 
)

Creates a sub-entry of the given opened registry object.

When there is already an open registry, and there is a need to access its "subdirectory", this method is both a convenience and performance improvement. The read-only flag is copied from the parent.

Parameters
parentAn open registry to use for creation of its child.
subLocationLocation relative to parent where to open the result registry access object
Precondition
The parent is open, the subLocation is a valid registry location, and the access is allowed, so the process of opening the registry access object succeeds. Otherwise the exception is thrown.

Member Function Documentation

void MRegistry::CheckIfOpen ( ) const

Check if the registry access object is open, throw an exception otherwise.

See also
Open - open registry access object
Close - close registry access object
IsOpen - return a boolean instead of throwing an exception
void MRegistry::Close ( )

Make sure the changes are flushed into persistent storage and close the registry.

If the registry access object was not open prior to this method, it will succeed by doing nothing.

See also
IsOpen - tell whether the registry access object is open
MStdStringVector MRegistry::GetAllSubkeys ( ) const

Get the list of subkeys in the registry.

Returns
the list of all subkeys in the currently open registry access object
Precondition
The registry should be open or an exception is raised. Also, storage-related exceptions can be thrown.
See also
GetAllValues - list all values
MStdStringVector MRegistry::GetAllValues ( ) const

Get the list of value names in the registry access object.

Returns
the list of all values in the currently open registry
Precondition
The registry object should be open or an exception is raised. Also, storage-related exceptions can be thrown.
See also
GetAllSubkeys - list all subkeys
MByteString MRegistry::GetBinary ( const MStdString valueName,
const MByteString defaultValue 
) const

Get the binary representation of the value name, or default if value with such name does not exist.

Parameters
valueNameName of the value in the open registry access object
defaultValueWhat to return if there is no such value in registry access object.
Precondition
Registry access object shall be open. Also, storage-related exceptions can be thrown.
See also
GetExistingBinary for variation that throws an exception in case the name does not exist.
MByteString MRegistry::GetExistingBinary ( const MStdString valueName) const

Get the binary representation of the value associated with the value name given.

Parameters
valueNameName of the value in the open registry access object.
Precondition
Registry access object shall be open. Also, storage-related exceptions can be thrown.
See also
GetBinary for variation that allows specifying the default value for the case when the string does not exist.
int MRegistry::GetExistingInteger ( const MStdString valueName) const

Get the integer representation of the value associated with the value name given.

Parameters
valueNameName of the value in the open registry access object.
Precondition
Registry access object shall be open. Also, storage-related exceptions can be thrown.
See also
GetInteger for variation that allows specifying the default value for the case when the string does not exist.
MStdString MRegistry::GetExistingString ( const MStdString valueName) const

Get the string representation of the value associated with the value name given.

Parameters
valueNameName of the value in the open registry access object.
Precondition
Registry access object shall be open. Also, storage-related exceptions can be thrown.
See also
GetString for variation that allows specifying the default value for the case when the string does not exist.
int MRegistry::GetInteger ( const MStdString valueName,
int  defaultValue 
) const

Get the integer representation of the value name, or default if value with such name does not exist.

Parameters
valueNameName of the value in the open registry access object.
defaultValueWhat to return if there is no such value in registry access object.
Precondition
Registry access object shall be open. Also, storage-related exceptions can be thrown.
See also
GetExistingInteger for variation that throws an exception in case the name does not exist.
MStdString MRegistry::GetString ( const MStdString valueName,
const MStdString defaultValue 
) const

Get the string representation of the value name, or default if value with such name does not exist.

Parameters
valueNameName of the value in the open registry access object.
defaultValueWhat to return if there is no such value in registry.
Precondition
Registry access object shall be open. Also, storage-related exceptions can be thrown.
See also
GetExistingString for variation that throws an exception in case the name does not exist.
bool MRegistry::IsOpen ( ) const
inline

Tells whether the registry is open.

See also
Open - open registry access object
Close - close registry access object
CheckIfOpen - throw an exception if registry access object is not open
bool MRegistry::IsPresent ( const MStdString keyOrValue) const

Whether the key or value with such name is present in the open registry access object.

Parameters
keyOrValueA subkey or value to find in the registry.
Precondition
The registry access object is open, or an exception is thrown.
See also
IsSubkeyPresent - tell if such subkey is present
IsValuePresent - tell if such value is present
bool MRegistry::IsReadOnly ( ) const

Tells whether the registry access object is read-only.

This property is not about the rights of the particular registry entry, but rather in which way the registry access object was opened. The same registry access object can be opened in either read-write or read-only mode, should the user have the appropriate rights.

Returns
Whether the open registry access object is one of these types:
  • True means the registry access object is read-only, and no value changes can be done through it.
  • False means the registry access object object can be used for both reading and writing.
Precondition
The registry access object shall be open or an exception is raised.
bool MRegistry::IsSubkeyPresent ( const MStdString key) const

Whether the key with such name is present in the open registry access object.

Parameters
keyA subkey to find in the registry.
Precondition
The registry access object is open, or an exception is thrown.
See also
IsPresent - tell if such subkey or value is present
IsValuePresent - tell if such value is present
bool MRegistry::IsValuePresent ( const MStdString valueName) const

Whether the value with such name is present in the open registry access object.

The value shall not be prefixed by key, or it will not be found.

Parameters
valueNameA value to find in the registry.
Precondition
The registry access object is open, or an exception is thrown.
See also
IsPresent - tell if such subkey or value is present
IsSubkeyPresent - tell if such subkey is present
void MRegistry::Open ( PredefinedKeyEnum  parentKey,
const MStdString location,
bool  readonly 
)

Open the registry folder for the desired access.

Parameters
parentKeyPredefined key to use as parent, any of these enumeration values:
locationA string that defines the location within the registry, as described in class header.
readonlyWhen true, the registry access object is opened in read-only mode. Otherwise, and this is the default, the registry access object is open for both reading and writing.
Precondition
The location is valid and the requested access is allowed, otherwise the exception is thrown.
See also
IsOpen - tell whether the registry access object is open
Close - explicitly close registry access object
void MRegistry::OpenSubkey ( const MRegistry parent,
const MStdString subLocation 
)

Open a sub-entry of the given opened registry object.

When there is already an open registry, and there is a need to access its "subdirectory", this method is both a convenience and performance improvement. The read-only flag is copied from the parent.

Parameters
parentAn open registry to use for creation of its child.
subLocationLocation relative to parent where to open the result registry access object
Precondition
The parent is open, the subLocation is a valid registry location, and the access is allowed, so the process of opening the registry access object succeeds. Otherwise the exception is thrown.
void MRegistry::Remove ( const MStdString keyOrValue)

Remove either the key or the value with such name from the registry access object.

Parameters
keyOrValueName of the value or subkey to remove.
Precondition
The value name or key name should exist, and the user should have rights to remove it from registry.
void MRegistry::RemoveSubkey ( const MStdString key)

Remove key with such name from the registry.

Parameters
keyName of the key to remove.
Precondition
The key name should exist, and the user should have rights to remove it from registry.
void MRegistry::RemoveValue ( const MStdString valueName)

Remove value with such name from the registry access object.

Parameters
valueNameName of the value to remove.
Precondition
The value name should exist, and the user should have rights to remove it from registry.
void MRegistry::SetBinary ( const MStdString valueName,
const MByteString value 
)

Associate the given binary value with the name.

In case the registry access object item with such name does not exist, it is created, and the value is initialized to one given.

Parameters
valueNameName of the value in the registry.
valueNew value for the given name.
Precondition
Storage-related exceptions can be thrown, like if the attempt to set a read-only value is made.
void MRegistry::SetInteger ( const MStdString valueName,
int  value 
)

Associate the given integer value with the name.

In case the registry access object item with such name does not exist, it is created, and the value is initialized to one given.

Parameters
valueNameName of the value in the registry.
valueNew value for the given name.
Precondition
Storage-related exceptions can be thrown, like if the attempt to set a read-only value is made.
void MRegistry::SetString ( const MStdString valueName,
const MStdString value 
)

Associate the given string value with the name.

In case the registry access object item with such name does not exist, it is created, and the value is initialized to one given.

Parameters
valueNameName of the value in the registry.
valueNew value for the given name.
Precondition
Storage-related exceptions can be thrown, like if the attempt to set a read-only value is made.