ACF $AcfVersion:0$
iprm - Parameter Management Library

Introduction

The iprm library provides a flexible and extensible framework for managing parameters in applications. It offers a comprehensive set of interfaces and implementations for handling different types of parameters, parameter sets, and dynamic parameter management with support for serialization, validation, and change notification.

Key Features

  • Type-Safe Parameter Management: Strongly typed parameter interfaces for text, IDs, names, and selections
  • Dynamic Parameter Sets: Support for creating, modifying, and managing collections of parameters
  • Selection Constraints: Flexible option lists with support for hierarchical selections
  • Serialization: Built-in support for parameter persistence through the ACF serialization framework
  • Change Notification: Observer pattern implementation for tracking parameter modifications
  • Validation: Extensible parameter set validation framework
  • State Management: Parameter state providers for managing edit/display states

Architecture

The iprm library is organized into several key components:

Parameter Types

Parameter Containers

Options and Constraints

Utilities

Usage Examples

Text Parameter Example

// Create a text parameter
iprm::CTextParam textParam;
// Set text value
textParam.SetText("Hello, World!");
// Get text value
QString text = textParam.GetText();
// Check if read-only
bool isReadOnly = textParam.IsReadOnly();
// Serialize to archive
iser::CMemoryWriteArchive archive(nullptr);
textParam.Serialize(archive);
Implementation of the text value over iprm::ITextParam interface.
Definition CTextParam.h:17
virtual void SetText(const QString &text) override
Set the text value.
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
virtual bool IsReadOnly() const override
Return true if the text is read-only.
virtual QString GetText() const override
Get the text value.
Implementation of archive using memory buffer to store the persistent objects.

Selection Parameter Example

// Create options manager
iprm::COptionsManager optionsManager;
// Add options
optionsManager.InsertOption("Option 1", "opt1", "First option");
optionsManager.InsertOption("Option 2", "opt2", "Second option");
optionsManager.InsertOption("Option 3", "opt3", "Third option");
// Create selection parameter
iprm::CSelectionParam selectionParam;
selectionParam.SetSelectionConstraints(&optionsManager);
// Set selection by index
selectionParam.SetSelectedOptionIndex(1);
// Get selected index
int selectedIndex = selectionParam.GetSelectedOptionIndex();
// Set selection by option ID
selectionParam.SetSelectedOptionById("opt3");
// Get constraints
const iprm::IOptionsList* constraints = selectionParam.GetSelectionConstraints();
int optionsCount = constraints->GetOptionsCount();
QString optionName = constraints->GetOptionName(0);
Implementation of a simple options manager.
virtual bool InsertOption(const QString &optionName, const QByteArray &optionId, const QString &optionDescription=QString(), int index=-1) override
Insert an option at some position.
Basic implementation of selection parameter.
virtual int GetSelectedOptionIndex() const override
Get selected index.
bool SetSelectedOptionById(const QByteArray &selectedOptionId)
Set selection index according to a given option ID.
virtual bool SetSelectedOptionIndex(int index) override
Set index of selected option.
void SetSelectionConstraints(const IOptionsList *constraintsPtr)
Set selection constraints for this selection object.
virtual const IOptionsList * GetSelectionConstraints() const override
Get constraints of this parameter.
Constraints of selection from set of possibilities.
virtual int GetOptionsCount() const =0
Get number of managed options.
virtual QString GetOptionName(int index) const =0
Get name of specified option.

Parameter Set Example

// Assuming you have a parameter set implementation
iprm::IParamsSet* paramsSet = /* ... obtained from somewhere ... */;
// Get list of parameter IDs
iprm::IParamsSet::Ids paramIds = paramsSet->GetParamIds();
// Iterate through parameters
for (const QByteArray& id : paramIds)
{
const iser::ISerializable* param = paramsSet->GetParameter(id);
// Process parameter...
}
// Get editable parameter
iser::ISerializable* editableParam = paramsSet->GetEditableParameter("myParamId");
if (editableParam)
{
// Cast to appropriate type and modify
iprm::ITextParam* textParam = dynamic_cast<iprm::ITextParam*>(editableParam);
if (textParam)
{
textParam->SetText("New Value");
}
}
Set of general parameters.
Definition IParamsSet.h:81
virtual const iser::ISerializable * GetParameter(const QByteArray &id) const =0
Get any parameter (read-only access).
virtual iser::ISerializable * GetEditableParameter(const QByteArray &id)=0
Get access to editable parameter (read-write access).
virtual Ids GetParamIds(bool editableOnly=false) const =0
Get list of used parameter IDs in the parameter set.
QSet< QByteArray > Ids
Definition IParamsSet.h:83
Interface for an object containing simple text.
Definition ITextParam.h:76
virtual void SetText(const QString &text)=0
Set the text value.
Common class for all classes which objects can be archived or restored from archive.

Parameter Manager Example

// Assuming you have a parameter manager implementation
iprm::IParamsManager* paramsManager = /* ... obtained from component ... */;
// Get number of parameter sets
int count = paramsManager->GetParamsSetsCount();
// Get operation flags
int flags = paramsManager->GetIndexOperationFlags(-1);
bool canInsert = (flags & iprm::IParamsManager::MF_SUPPORT_INSERT) != 0;
bool canDelete = (flags & iprm::IParamsManager::MF_SUPPORT_DELETE) != 0;
// Insert new parameter set
if (canInsert)
{
int newIndex = paramsManager->InsertParamsSet();
if (newIndex >= 0)
{
// Set name for new parameter set
paramsManager->SetParamsSetName(newIndex, "My Parameter Set");
// Get the parameter set
iprm::IParamsSet* paramsSet = paramsManager->GetParamsSet(newIndex);
// Work with the parameter set...
}
}
// Iterate through all parameter sets
for (int i = 0; i < count; ++i)
{
QString name = paramsManager->GetParamsSetName(i);
QString description = paramsManager->GetParamsSetDescription(i);
iprm::IParamsSet* paramsSet = paramsManager->GetParamsSet(i);
// Process parameter set...
}
// Remove a parameter set
if (canDelete)
{
paramsManager->RemoveParamsSet(2);
}
// Swap two parameter sets
bool canSwap = (flags & iprm::IParamsManager::MF_SUPPORT_SWAP) != 0;
if (canSwap)
{
paramsManager->SwapParamsSet(0, 1);
}
Manager of parameter sets.
virtual bool SetParamsSetName(int index, const QString &name)=0
Set name of specified parameter set.
virtual int GetIndexOperationFlags(int index=-1) const =0
Get operation control flags of some parameter set or whole manager.
virtual bool SwapParamsSet(int index1, int index2)=0
Swap two parameter sets.
virtual int InsertParamsSet(int typeIndex=-1, int index=-1)=0
Insert new parameter set at selected position.
virtual int GetParamsSetsCount() const =0
Get number of managed parameter sets.
virtual QString GetParamsSetDescription(int index) const =0
Get the description of the specified parameter set.
virtual IParamsSet * GetParamsSet(int index) const =0
Get selected parameter set.
virtual bool RemoveParamsSet(int index)=0
Remove parameter set at selected position.
virtual QString GetParamsSetName(int index) const =0
Get name of specified parameter set.
@ MF_SUPPORT_DELETE
Active if delete of parameters is possible.
@ MF_SUPPORT_INSERT
Active if insert of parameters is possible.
@ MF_SUPPORT_SWAP
Active if swap of parameters with the other one is possible.

Options Manager Example

// Create options manager
iprm::COptionsManager optionsManager;
// Check operation flags
int flags = optionsManager.GetOptionOperationFlags(-1);
bool canAddOptions = (flags & iprm::IOptionsManager::OOF_SUPPORT_INSERT) != 0;
// Insert options
if (canAddOptions)
{
optionsManager.InsertOption("Red", "color_red", "Red color", -1);
optionsManager.InsertOption("Green", "color_green", "Green color", -1);
optionsManager.InsertOption("Blue", "color_blue", "Blue color", -1);
}
// Get options count
int optionsCount = optionsManager.GetOptionsCount();
// Iterate through options
for (int i = 0; i < optionsCount; ++i)
{
QString name = optionsManager.GetOptionName(i);
QByteArray id = optionsManager.GetOptionId(i);
QString description = optionsManager.GetOptionDescription(i);
bool isEnabled = optionsManager.IsOptionEnabled(i);
qDebug() << "Option" << i << ":" << name << "(" << id << ")";
}
// Modify option
optionsManager.SetOptionName(0, "Dark Red");
optionsManager.SetOptionDescription(0, "Dark red color");
// Enable/disable option
optionsManager.SetOptionEnabled(1, false);
// Remove option
bool canRemove = (flags & iprm::IOptionsManager::OOF_SUPPORT_DELETE) != 0;
if (canRemove)
{
optionsManager.RemoveOption(2);
}
// Select an option
optionsManager.SetSelectedOptionIndex(0);
int selectedIndex = optionsManager.GetSelectedOptionIndex();
virtual bool SetOptionDescription(int index, const QString &optionDescription) override
Set a new description for the option at the given index.
virtual bool RemoveOption(int index) override
Remove an option at the given index.
virtual int GetOptionOperationFlags(int index=-1) const override
Get operation control flags of some option or whole manager.
virtual bool SetOptionName(int index, const QString &optionName) override
Set a new name for the option at the given index.
virtual bool IsOptionEnabled(int index) const override
Return true if the option is enabled and can be selected.
virtual QString GetOptionDescription(int index) const override
Get human-readable description for an option.
virtual QString GetOptionName(int index) const override
Get name of specified option.
virtual QByteArray GetOptionId(int index) const override
Get option ID.
virtual int GetOptionsCount() const override
Get number of managed options.
virtual bool SetOptionEnabled(int index, bool isEnabled=true) override
Enables or disables a given option.
@ OOF_SUPPORT_DELETE
Active if delete of options is possible.
@ OOF_SUPPORT_INSERT
Active if insert of options is possible.

Enableable Parameter Example

// Create enableable parameter
// Check if enabled
bool isEnabled = param.IsEnabled();
// Check if enabling is allowed
bool canEnable = param.IsEnablingAllowed();
// Enable/disable
if (canEnable)
{
bool success = param.SetEnabled(true);
if (success)
{
// Parameter was enabled
}
}
// Disable
param.SetEnabled(false);
Basic implementation of IEnableableParam interface.
virtual bool IsEnabled() const override
Return true if something is enabled.
virtual bool IsEnablingAllowed() const override
Return true if enabling/disabling is allowed.
virtual bool SetEnabled(bool isEnabled=true) override
Set the enabled state.

Parameter Set Validation Example

#include <ilog/CMessageConsumer.h>
// Assuming you have a validator implementation
iprm::IParamsSetValidator* validator = /* ... obtained from somewhere ... */;
// Get supported type IDs
// Create message consumer for validation messages
ilog::CMessageConsumer messageConsumer;
// Validate parameter set
iprm::IParamsSet* paramsSet = /* ... obtained from somewhere ... */;
QByteArray validationContext = "myContext";
bool isValid = validator->IsParamsSetConsistent(
validationContext,
*paramsSet,
&messageConsumer);
if (!isValid)
{
// Handle validation errors
// Check messageConsumer for detailed error messages
}
Interface for consistency checking of a parameter set.
virtual bool IsParamsSetConsistent(const QByteArray &validationContextId, const IParamsSet &paramsSet, ilog::IMessageConsumer *validationMessagesConsumerPtr=NULL) const =0
Return true if the parameter set is consistent, false otherwise.
virtual Ids GetSupportedTypeIds() const =0
Get list of parameter type IDs which can be checked by the validator.

Serialization Example

// Create and configure parameters
iprm::CTextParam textParam;
textParam.SetText("Important Data");
iprm::CSelectionParam selectionParam;
selectionParam.SetSelectedOptionIndex(2);
// Serialize to archive
iser::CMemoryWriteArchive writeArchive(nullptr);
textParam.Serialize(writeArchive);
selectionParam.Serialize(writeArchive);
// Later, deserialize from archive
iprm::CTextParam loadedTextParam;
iprm::CSelectionParam loadedSelectionParam;
iser::CMemoryReadArchive readArchive(writeArchive);
loadedTextParam.Serialize(readArchive);
loadedSelectionParam.Serialize(readArchive);
// Verify data was restored
QString text = loadedTextParam.GetText(); // "Important Data"
int index = loadedSelectionParam.GetSelectedOptionIndex(); // 2
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
Implementation of archive using memory buffer to read the persistent objects.

Change Notification Example

#include <imod/IModelObserver.h>
// Create observer for selection changes
class MySelectionObserver : public imod::IModelObserver
{
public:
virtual void OnModelChanged(const istd::IChangeable* modelPtr,
const istd::IChangeable::ChangeSet& changeSet) override
{
{
// Selection has changed
const iprm::ISelectionParam* selection =
dynamic_cast<const iprm::ISelectionParam*>(modelPtr);
if (selection)
{
int newIndex = selection->GetSelectedOptionIndex();
// Handle the change...
}
}
}
};
// Use the observer
MySelectionObserver observer;
iprm::CSelectionParam selectionParam;
// Attach observer (implementation specific)
// selectionParam.AttachObserver(&observer);
// When selection changes, observer will be notified
selectionParam.SetSelectedOptionIndex(3);
Interface allowing to select single option from list of options.
@ CF_SELECTION_CHANGED
Selection index has changed.
virtual int GetSelectedOptionIndex() const =0
Get selected index.
Set of change flags (its IDs).
Definition IChangeable.h:36
bool Contains(int changeId) const
Check if there is specific change flag in the set.
Common interface for data model objects, which can be changed.
Definition IChangeable.h:28

Thread Safety

The iprm library components are generally not thread-safe by default. When using parameters across multiple threads, appropriate synchronization mechanisms should be employed by the application.

Dependencies

The iprm library depends on the following ACF components:

  • istd: Standard utilities, change notification interfaces
  • iser: Serialization framework
  • imod: Model-observer pattern implementation
  • icomp: Component framework
  • Qt Core: QString, QByteArray, QSet, and other core classes

Best Practices

  1. Use Smart Pointers: Prefer istd::TUniqueInterfacePtr and istd::TSharedInterfacePtr for memory management
  2. Check Operation Flags: Always verify operation flags before attempting insert/delete/swap operations
  3. Handle Validation: Use parameter set validators to ensure data consistency
  4. Leverage Serialization: Utilize built-in serialization for persistence and undo/redo functionality
  5. Observe Changes: Implement observers to react to parameter changes in a decoupled manner
  6. Clone Parameters: Use CloneMe() for creating copies of parameters rather than manual copying
  7. Check Constraints: Verify selection constraints before setting option indices

See Also