A writeable "handle" to an MSElement. More...
#include <ElementHandle.h>
Public Member Functions | |
EditElementHandle () | |
construct a blank, invalid, EditElementHandle More... | |
EditElementHandle (MSElementDescrP descr, bool owned, bool isUnmodified, DgnModelRefP modelRef=0) | |
Construct an ElementHandle from an MSElementDescr. More... | |
EditElementHandle (ElementRefP elRef, DgnModelRefP modelRef=0) | |
Construct an ElementHandle from an ElementRefP and a DgnModelRefP. More... | |
EditElementHandle (MSElementCP el, DgnModelRefP modelRef) | |
Construct an ElementHandle from an MSElement and a DgnModelRef. More... | |
EditElementHandle (ElementId id, DgnModelRefP modelRef) | |
Construct an ElementHandle from an ElementId and a DgnModelRefP. More... | |
EditElementHandle (ElementHandleCR from, bool duplicateDescr) | |
Construct an ElementHandle from another element handle. More... | |
void | Duplicate (ElementHandleCR) |
Duplicate the element descriptor and its scheduled XAttribute changes. More... | |
void | SetModelRef (DgnModelRefP modelRef) |
Change the DgnModelRef for this EditElementHandle. More... | |
void | SetNonPersistent () |
Turn off the "IsUnmodified" flag for this EditElementHandle. More... | |
void | Invalidate () |
Mark this EditElementHandle as invalid. If there is an MSElementDescr associated with this EditElementHandle, it is freed. More... | |
void | SetIElementState (IElementStateP state) |
IElementStateP | GetIElementState () |
Element Data | |
MSElementDescrP | GetElementDescrP () |
Get a writable MSElementDescr from this EditElementHandle. More... | |
MSElementP | GetElementP () |
Get a pointer to a writeable MSElement from this EditElementHandle. More... | |
StatusInt | ReplaceElement (MSElementCP el) |
Replace the element associated with this EditElementHandle with a new element. More... | |
StatusInt | ReplaceElementDescr (MSElementDescrP elDscr) |
Replace the MSElementDescr associated with the EditElementHandle with a new MSElementDescr. More... | |
MSElementDescrP | ExtractElementDescr () |
Extract and take ownership of the MSElementDescr associated with this EditElementHandle. More... | |
void | SetElementDescr (MSElementDescrP elDscr, bool owned, bool isUnmodified, DgnModelRefP modelRef=0) |
Assign a new MSElementDescr to this EditElementHandle. More... | |
void | SetElementRef (ElementRefP elRef, DgnModelRefP modelRef) |
Change the ElementRefP and DgnModelRef for this EditElementHandle. More... | |
XAttribute Changes | |
StatusInt | ScheduleWriteXAttribute (XAttributeHandlerIdCR h, UInt32 xAttrId, size_t dataSize, void const *data) |
Schedule the specified XAttribute to be written to the MSElementDescr. More... | |
StatusInt | CancelWriteXAttribute (XAttributeHandlerIdCR h, UInt32 xAttrId) |
Cancel out the effects of a prior call to ScheduleWriteXAttribute. More... | |
StatusInt | ScheduleDeleteXAttribute (XAttributeHandlerIdCR h, UInt32 xAttrId) |
Schedule removal of the specified XAttribute from the MSElementDescr. More... | |
StatusInt | CancelDeleteXAttribute (XAttributeHandlerIdCR h, UInt32 xAttrId) |
Cancel out the effects of a prior call to ScheduleDeleteXAttribute. More... | |
Read from model | |
StatusInt | FindByID (ElementId elemID, DgnModelP dgnCache, bool allowDeleted=false) |
StatusInt | FindByID (ElementId elemID, DgnModelRefP modelRef, bool allowDeleted=false) |
Write changes to a Model | |
StatusInt | AddToModel () |
Add this EditElementHandle to the associated model. More... | |
StatusInt | DeleteFromModel () |
Delete this EditElementHandle from its model. More... | |
StatusInt | ReplaceInModel (ElementRefP oldRef) |
Replace the element referred to by the supplied ElementRefP with the modified MSElementDescr held by this EditElementHandle. More... | |
Element Linkages | |
ElementLinkageIterator | BeginElementLinkages (UInt16 rl=0) |
Get an iterator over the element's user data linkages. More... | |
ElementLinkageIterator | EndElementLinkages () |
Get an iterator that marks the end of the element's user data linkages. More... | |
StatusInt | ReplaceElementLinkage (ElementLinkageIteratorR it, LinkageHeader const &newLinkageHeader, void const *newLinkageData) |
Replace an element data linkage on this element. More... | |
StatusInt | RemoveElementLinkage (ElementLinkageIteratorR it) |
Remove an element data linkage from this element. More... | |
StatusInt | InsertElementLinkage (ElementLinkageIterator *newLinkageIt, LinkageHeaderCR newLinkageHeader, void const *newLinkageData, ElementLinkageIterator &wh, UInt16 rl=0) |
Add a new element data linkage to this element. More... | |
StatusInt | AppendElementLinkage (ElementLinkageIterator *newLinkageIt, LinkageHeaderCR newLinkageHeader, void const *newLinkageData) |
Appends a new element data linkage to the end of this element. More... | |
![]() | |
ElementHandle () | |
construct a blank, invalid, ElementHandle More... | |
~ElementHandle () | |
ElementHandle (ElementRefP elRef, DgnModelRefP modelRef=0) | |
Construct an ElementHandle from an ElementRefP and a DgnModelRefP. More... | |
ElementHandle (ElementId id, DgnModelRefP modelRef) | |
Construct an ElementHandle from an ElementId and a DgnModelRefP. More... | |
ElementHandle (MSElementDescrCP elDscr, bool owned, bool isUnmodified=false, DgnModelRefP modelRef=0) | |
Construct an ElementHandle from an MSElementDescr. More... | |
ElementHandle (MSElementCP el, DgnModelRefP modelRef) | |
Construct an ElementHandle from an MSElement and a DgnModelRef. More... | |
ElementHandle (ElementHandleCR from) | |
Copy an ElementHandle. More... | |
ElementId | GetElementId () const |
Get the element ID of the element contained in the ElementHandle. More... | |
void | ResetHandler () const |
Handler & | GetHandler (MissingHandlerPermissions perm=MISSING_HANDLER_PERMISSION_None) const |
Get the Handler for this ElementHandle. More... | |
DisplayHandlerP | GetDisplayHandler () const |
A shortcut method to get a DisplayHandler pointer for the Handler of this ElementHandle, or NULL if the element's Handler does not derive from DisplayHandler. More... | |
IDependencyHandlerP | GetIDependencyHandler () const |
A shortcut method to get the IDependencyHandler interface on the Handler for this ElementHandle, or NULL if the element's Handler does not implement that interface. More... | |
ITransactionHandlerP | GetITransactionHandler () const |
A shortcut method to get the ITransactionHandler interface on the Handler for this ElementHandle, or NULL if the element's Handler does not implement that interface. More... | |
ITextQueryCP | GetITextQuery () const |
A shortcut method to get the ITextQuery interface on the Handler for this ElementHandle, or NULL if the element's Handler does not implement that interface. More... | |
ITextEditP | GetITextEdit () const |
A shortcut method to get the ITextEdit interface on the Handler for this ElementHandle, or NULL if the element's Handler does not implement that interface. More... | |
ElementRefP | GetElementRef () const |
Get the ElementRefP for this ElementHandle. More... | |
DgnModelP | GetDgnModelP () const |
Get a DgnModelP for this ElementHandle. More... | |
DgnFileP | GetDgnFileP () const |
Get the DgnFile of the DgnModel for this ElementHandle. More... | |
DgnModelRefP | GetModelRef () const |
Get the DgnModelRef for this ElementHandle. More... | |
MSElementCP | GetElementCP () const |
Get a const pointer to the MSElement associated with this ElementHandle. More... | |
bool | IsValid () const |
Determine whether this ElementHandle is currently valid. More... | |
bool | IsPersistent () const |
Determine whether this ElementHandle references an unmodified element in the cache. More... | |
int | GetElementType () const |
Get the element type of the element referenced by this ElementHandle. More... | |
void | GetElementHeader (Elm_hdr &hdr) const |
Get a copy of the Elm_hdr of the element referenced by this ElementHandle. More... | |
MSElementDescrCP | PeekElementDescrCP () const |
Peek to see whether this ElementHandle currently has an MSElementDescr. More... | |
MSElementDescrCP | GetElementDescrCP () const |
Get an MSElementDescrCP from this ElementHandle. More... | |
ConstElementLinkageIterator | BeginElementLinkages (UInt16 rl=0) const |
Get an iterator over the element's user data linkages. More... | |
ConstElementLinkageIterator | EndElementLinkages () const |
Get an iterator that marks the end of the element's user data linkages. More... | |
A writeable "handle" to an MSElement.
EditElementHandle is the ideal means of passing an element to functions, when the functions might modify the element. EditElementHandle is also useful for creating and adding new elements and for deleting existing elements.
Like an ElementHandle, an EditElementHandle can hold either an ElementRefP or an MSElementDescrP in order to represent an element. Unlike ElementHandle, an EditElementHandle can be used to change the modified and persistent state of its element and will will change its internal representation accordingly.
EditElementHandle is often set up to take ownership of an underlying MSElementDescrP. This feature allows EditElementHandle, like ElementHandle, to serve as a smart pointer. As a read/write handle, EditElementHandle is also well suited for cases where the underlying MSElementDescrP pointer must be reallocated. Use of EditElementHandle makes for cleaner, simpler, more reliable code and is preferable to MSElementDescrH.
Some common workflows involving an EditElementHandle are:
Creating a new element involves setting up an element descriptor in memory and then writing it to a cache. The handle ends up holding the new ElementRefP that represents the newly created element.
The modification scenario starts with an existing, unmodified element. The modification logic will normally work on an element descriptor. The handle then shifts to holding the modified descriptor. After writing the modified descriptor back to its cache, then handle switches back to representing an existing, unmodified element.
Legacy code often works with element descriptors. This shows how to use the ExtractElementDescr method in order to hand off a descriptor and manage its lifecycle.
Applications that work with legacy code may have to understand and even manage a handle's internal state. When following the common use scenarios above, an application can use an EditElementHandle without worrying too much about whether the handle contains an ElementRefP or an MSElementDescrP or whether the descriptor's elementRef field is valid or not. The EditElementHandle's state logic can manage this data in most cases. If the application follows a different workflow, however, it might have to control this information in the handle.
An EditElementHandle can represent an element in three possible states:
Applications can control an EditElementHandle's persistent status by means of the isUnmodified argument to the element descriptor constructor and the SetElementDescr method. Normally, isUnmodified is set to false. That is, if you are setting up an EditElementHandle from a descriptor, you are probably creating a new element or have modified its data. If you want to represent a persistent, unmodified element, the preferred method is to specify an ElementRefP. When using legacy code, however, an application might possibly start by reading a persistent element into an element descriptor. If the application then wants to switch over to using an EditElementHandle, it can pass isUnmodified = true. That will cause the EditElementHandle to adopt the descriptor's ElementRefP and also to hold the descriptor pointer. The following example shows how to create a persistent and unmodified handle that also acts as a smart pointer.
EditElementHandle eh (elementDescriptor, true, true); ... ... eh.GetElementDescrP (); // already has a descriptor, so no need to read it ... eh.GetElementRef (); // also has an ElementRefP // eh will free elementDescriptor
You can use EditElementHandle to add, replace, or delete an element's XAttributes. Unlike XAttrIO, EditElementHandle schedules XAttribute changes. Scheduled changes are written to the cache when you rewrite the handle's underlying MSElementDescr (e.g., by using the AddToModel or ReplaceInModel methods).
The XAttributeChangeIter class can be used to inspect scheduled changes.
The ElementHandle::XAttributeIter class can be used to iterate XAtttributes on an element, taking scheduled changes into account.
construct a blank, invalid, EditElementHandle
EditElementHandle | ( | MSElementDescrP | descr, |
bool | owned, | ||
bool | isUnmodified, | ||
DgnModelRefP | modelRef = 0 |
||
) |
Construct an ElementHandle from an MSElementDescr.
EditElementHandle | ( | ElementRefP | elRef, |
DgnModelRefP | modelRef = 0 |
||
) |
Construct an ElementHandle from an ElementRefP and a DgnModelRefP.
EditElementHandle | ( | MSElementCP | el, |
DgnModelRefP | modelRef | ||
) |
Construct an ElementHandle from an MSElement and a DgnModelRef.
EditElementHandle | ( | ElementId | id, |
DgnModelRefP | modelRef | ||
) |
Construct an ElementHandle from an ElementId and a DgnModelRefP.
[in] | id | The ElementId of the element for this ElementHandle. |
[in] | modelRef | The DgnModelRefP used to access the element. |
EditElementHandle | ( | ElementHandleCR | from, |
bool | duplicateDescr | ||
) |
Construct an ElementHandle from another element handle.
[in] | from | The other ElementHandle. |
[in] | duplicateDescr | True if the new ElementHandle should duplicate the internal descriptor. If the element handles are to be modified seperately then this should be set. |
StatusInt AddToModel | ( | ) |
Add this EditElementHandle to the associated model.
The addition is via the current transaction (see ITxn::AddElement) and is always undoable.
StatusInt AppendElementLinkage | ( | ElementLinkageIterator * | newLinkageIt, |
LinkageHeaderCR | newLinkageHeader, | ||
void const * | newLinkageData | ||
) |
Appends a new element data linkage to the end of this element.
[out] | newLinkageIt | Points to new linkage on the element |
newLinkageHeader | new linkdage header (copied). | |
newLinkageData | new linkdage data (copied). |
ElementLinkageIterator BeginElementLinkages | ( | UInt16 | rl = 0 | ) |
Get an iterator over the element's user data linkages.
rl | Linkage ID filter value identifies the linkages of interest. Defaults to all linkages. |
StatusInt CancelDeleteXAttribute | ( | XAttributeHandlerIdCR | h, |
UInt32 | xAttrId | ||
) |
Cancel out the effects of a prior call to ScheduleDeleteXAttribute.
[in] | h | XAttributeHandler ID |
[in] | xAttrId | XAttribute ID |
StatusInt CancelWriteXAttribute | ( | XAttributeHandlerIdCR | h, |
UInt32 | xAttrId | ||
) |
Cancel out the effects of a prior call to ScheduleWriteXAttribute.
[in] | h | XAttributeHandler ID |
[in] | xAttrId | XAttribute ID |
StatusInt DeleteFromModel | ( | ) |
Delete this EditElementHandle from its model.
The delete is via the current transaction (see ITxn::DeleteElement) and is always undoable. The deletion is via the current transaction (see ITxn::DeleteElement) and is always undoable.
void Duplicate | ( | ElementHandleCR | ) |
Duplicate the element descriptor and its scheduled XAttribute changes.
ElementLinkageIterator EndElementLinkages | ( | ) |
Get an iterator that marks the end of the element's user data linkages.
MSElementDescrP ExtractElementDescr | ( | ) |
Extract and take ownership of the MSElementDescr associated with this EditElementHandle.
StatusInt FindByID | ( | ElementId | elemID, |
DgnModelRefP | modelRef, | ||
bool | allowDeleted = false |
||
) |
MSElementDescrP GetElementDescrP | ( | ) |
Get a writable MSElementDescr from this EditElementHandle.
If this EditElementHandle does not already have an MSElementDescr, allocate one using the ElementRefP/DgnModelRef.
MSElementP GetElementP | ( | ) |
Get a pointer to a writeable MSElement from this EditElementHandle.
References NULL.
IElementStateP GetIElementState | ( | ) |
StatusInt InsertElementLinkage | ( | ElementLinkageIterator * | newLinkageIt, |
LinkageHeaderCR | newLinkageHeader, | ||
void const * | newLinkageData, | ||
ElementLinkageIterator & | wh, | ||
UInt16 | rl = 0 |
||
) |
Add a new element data linkage to this element.
[out] | newLinkageIt | Points to new linkage on the element |
newLinkageHeader | new linkdage header (copied). | |
newLinkageData | new linkdage data (copied). | |
wh | where the new linkage should be inserted into the element's linkage data area. Pass EndElementLinkages() to append. Pass BeginElementLinkages() to insert before all existing linkages. Otherwise, pass an iterator that identifies an existing linkage, and this function will insert the new linkage before it. | |
rl | Linkage ID filter value to assign to newLinkageIt. Defaults to all linkages. |
void Invalidate | ( | ) |
Mark this EditElementHandle as invalid. If there is an MSElementDescr associated with this EditElementHandle, it is freed.
StatusInt RemoveElementLinkage | ( | ElementLinkageIteratorR | it | ) |
Remove an element data linkage from this element.
When this function is called during the iterator, the resulting iterator will point to the next element, and should not be incremented. For example:
it | The linkage that is to be removed |
StatusInt ReplaceElement | ( | MSElementCP | el | ) |
Replace the element associated with this EditElementHandle with a new element.
[in] | el | The new element. The element is copied from this buffer and allocated in a new MSElementDescr. |
StatusInt ReplaceElementDescr | ( | MSElementDescrP | elDscr | ) |
Replace the MSElementDescr associated with the EditElementHandle with a new MSElementDescr.
[in] | elDscr | The new MSElementDescr to be associated with the EditElementHandle. After this call, elDscr becomes owned by this EditElementHandle. |
StatusInt ReplaceElementLinkage | ( | ElementLinkageIteratorR | it, |
LinkageHeader const & | newLinkageHeader, | ||
void const * | newLinkageData | ||
) |
Replace an element data linkage on this element.
it | The linkage that is to be replaced |
newLinkageHeader | new linkdage header (copied). |
newLinkageData | new linkdage data (copied). |
StatusInt ReplaceInModel | ( | ElementRefP | oldRef | ) |
Replace the element referred to by the supplied ElementRefP with the modified MSElementDescr held by this EditElementHandle.
The replacement is via the current transaction (see ITxn::ReplaceElement) and is always undoable.
[in] | oldRef | Element to replace. |
StatusInt ScheduleDeleteXAttribute | ( | XAttributeHandlerIdCR | h, |
UInt32 | xAttrId | ||
) |
Schedule removal of the specified XAttribute from the MSElementDescr.
[in] | h | XAttributeHandler ID |
[in] | xAttrId | XAttribute ID |
StatusInt ScheduleWriteXAttribute | ( | XAttributeHandlerIdCR | h, |
UInt32 | xAttrId, | ||
size_t | dataSize, | ||
void const * | data | ||
) |
Schedule the specified XAttribute to be written to the MSElementDescr.
[in] | h | XAttributeHandler ID |
[in] | xAttrId | XAttribute ID |
[in] | dataSize | Number of bytes of data in XAttribute data |
[in] | data | XAttribute data |
void SetElementDescr | ( | MSElementDescrP | elDscr, |
bool | owned, | ||
bool | isUnmodified, | ||
DgnModelRefP | modelRef = 0 |
||
) |
Assign a new MSElementDescr to this EditElementHandle.
The existing MSElementDescr (if present) is freed.
[in] | elDscr | MSElementDescr to be referenced by this ElementHandle. |
[in] | owned | If true, destructor will free elDscr. Otherwise, caller maintains ownership of elDscr. |
[in] | isUnmodified | If true, elDscr is an exact image of the element in the cache. |
[in] | modelRef | Will be used if elDscr.h.dgnModelRef is NULL. |
void SetElementRef | ( | ElementRefP | elRef, |
DgnModelRefP | modelRef | ||
) |
Change the ElementRefP and DgnModelRef for this EditElementHandle.
If there is currently an MSElementDescr associated with this EditElementHandle, it is freed.
[in] | elRef | New ElementRefP. |
[in] | modelRef | New DgnModelRef |
void SetIElementState | ( | IElementStateP | state | ) |
References IRefCounted::AddRef().
void SetModelRef | ( | DgnModelRefP | modelRef | ) |
Change the DgnModelRef for this EditElementHandle.
modelRef | IN new DgnModelRef |
void SetNonPersistent | ( | ) |
Turn off the "IsUnmodified" flag for this EditElementHandle.
This EditElementHandle will no longer be treated as an exact image of the element in the cache.
References NULL.