template <typename T> class UniqueHandle final {...};
Handle to a ReadAccessor or ReadWriteAccessor. A UniqueHandle is returned by the functions OpenFileReadOnly(), OpenFileWriteOnly(), and OpenFileReadWrite().
Manages exclusive, movable access to file accessor objects with RAII semantics.
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 7be811cdf7d8ProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
Manages exclusive, movable access to file accessor objects with RAII semantics.
The class template ara::per::UniqueHandle manages exclusive ownership of file accessor objects of AUTOSAR Persistency within the scope of strict move-only semantics. After receipt via file access functions, the instance must mandatorily be checked for validity by means of operator bool() prior to any usage [SWS_PER_00371]. Calling other operators on an empty or transferred handle leads to undefined behavior [SWS_PER_00399]. All operations are declared as noexcept, where read accesses are thread-safe, whereas modifying operations are not.
Context
The class template ara::per::UniqueHandle serves as a type-safe access handle to resource objects of AUTOSAR Adaptive Persistency, namely ReadAccessor or ReadWriteAccessor. It is provided as the return value of the functions OpenFileReadOnly(), OpenFileWriteOnly(), and OpenFileReadWrite(), encapsulating exclusive ownership of the opened file access interface.
Lifecycle
The class implements strict move-only semantics (unique ownership). To prevent accidental duplication of access or shared ownership, both the copy constructor [SWS_PER_00373] and the copy assignment operator [SWS_PER_00374] are defined as deleted (delete). Ownership rights can exclusively be transferred by moving: when calling the move constructor [SWS_PER_00371] or the move assignment [SWS_PER_00372], the passed source object is invalidated and may not be used thereafter.
A UniqueHandle is at any time either in a valid state (representing a valid object of the parameterized class) or in an empty or invalidated state, as present after a move transfer [SWS_PER_00399]. Upon termination of the scope, the destructor [SWS_PER_00569] is executed. Presumably, destruction of a valid handle automatically closes or cleans up the encapsulated access resource. Question Q-e7f12aa0d7c5548d (open)
Typical usage of UniqueHandle follows a defined sequence of steps:
Acquiring the handle: The application receives the handle as the result of a file access call such as OpenFileReadOnly(), OpenFileWriteOnly(), or OpenFileReadWrite().
State check: Prior to any further operation, the status of the instance must mandatorily be verified by means of operator bool()[SWS_PER_00371], [SWS_PER_00372]. The operator returns true if a valid object is present, and false if the handle is empty [SWS_PER_00399].
Accessing the encapsulated object: If the status is valid, methods and data of the target are accessed via the arrow operators operator-> (non-constant [SWS_PER_00360] or constant [SWS_PER_00361]) or via dereferencing by means of operator* (non-constant [SWS_PER_00400] or constant [SWS_PER_00401]).
Ownership transfer or destruction: If needed, the handle can be transferred to another component via std::move[SWS_PER_00371] or is automatically destroyed at the end of its lifetime [SWS_PER_00569].
Error Scenarios
A central error scenario is access to an empty or transferred handle: using operators other than operator bool() on an empty handle leads to undefined behavior according to the specification [SWS_PER_00399]. Prior to any dereferencing, a check is therefore mandatory [SWS_PER_00371], [SWS_PER_00372].
Regarding exception safety and concurrency, the following specification details apply:
Move constructor for UniqueHandle. The source handle object is invalidated and cannot be used anymore. The operator bool() shall be used to check the state of a handle object before using any other operators of the handle object.
Move assignment operator for UniqueHandle. The source handle object is invalidated and cannot be used anymore. The operator bool() shall be used to check the state of a handle object before using any other operators of the handle object.
Handle state. True if the handle represents a valid object of the templated class, False if the handle is empty (e.g. after a move operation). Using other operators than bool() of an empty handle will result in undefined behavior.
Move constructor for UniqueHandle. The source handle object is invalidated and cannot be used anymore. The operator bool() shall be used to check the state of a handle object before using any other operators of the handle object.
Move assignment operator for UniqueHandle. The source handle object is invalidated and cannot be used anymore. The operator bool() shall be used to check the state of a handle object before using any other operators of the handle object.
Handle state. True if the handle represents a valid object of the templated class, False if the handle is empty (e.g. after a move operation). Using other operators than bool() of an empty handle will result in undefined behavior.
gemini-3.8-flash-low· 2026-10-13 · German original