Public Member Functions | List of all members
ElementIdMap< _ForeignId, _Compare, _ForeignIdIO > Class Template Reference

ElementIDMap is a template for classes which store a mapping from some "foreign" object ID to DGN Element Ids (64 bit unsigned integers). More...

#include <ElementIdMap.h>

Inheritance diagram for ElementIdMap< _ForeignId, _Compare, _ForeignIdIO >:
StringToElementIdMap

Public Member Functions

 ElementIdMap (_ForeignIdIO const &io)
 
T_AUInt64 GetId (_ForeignId const &foreignId)
 Return elementId for supplied foreignId. More...
 
StatusInt Store (DataExternalizer &sink) const
 Store map. More...
 
StatusInt Load (DataInternalizer &source)
 Load map. More...
 
BeFileName GetMapFileName (WStringCR baseName)
 
StatusInt Load (WStringCR baseFileName)
 Load map. More...
 
StatusInt Store (WStringCR baseFileName)
 Store map. More...
 

Detailed Description

template<class _ForeignId, class _Compare = std::less<_ForeignId>, class _ForeignIdIO = FixedSizeForeignIdIO <_ForeignId>>
class Bentley::DgnPlatform::ElementIdMap< _ForeignId, _Compare, _ForeignIdIO >

ElementIDMap is a template for classes which store a mapping from some "foreign" object ID to DGN Element Ids (64 bit unsigned integers).

By utilizing this mapping an application which generates DGN elements from its objects with its own ID system can insure that the elements always recieve consistent ElementIDs. This is important as element IDs are used by MicrStation to store named groups, item sets, clash detection sets, associative dimension targets etc.

In order for the element map to be useful, it must be persistent. The default implementation stores and reads the map to a file with the same name but with the extension ".dgnIdMap".... a Rhino file "test.3dm" would use a mapping file, "test.3dm.dgnIdMap".

Example file creation code:

   StatusInt LoadFile (...)
         {
         m_fileObj->SetHighestID (0x80000000);       // Insure that all non-mapped IDs are above mapped/.
         m_idMap.Load (GetFileName());               // Load ID Map.


         for (...)
             {
             ObjectID                foreignObjectId.         // From current object.
             EditElemHandle          editElemHandle;
             ElementId               elementId = m_idMap->GetId (foreignObjectId);

             ... GenerateElement (editElemHandle, object, elementId);        

             TxnElementAddOptions    txnOptions (false       // Do not call Asynchs.
                                                 false,      // Do not save in ID
                                                 true);      // Override IDs (with those from map).

             ITxnManager::GetCurrentTxn().AddElement (editElemHandle, txnOptions);
             }

         m_idMap->Store (GetFileName());             // Save ID map.
         }

Note: that in the example we set the initially set the highest element ID to reserve low IDs for those in the map. All elements generated without the explicitly mapped IDs will be sequentially numbered beginning with this value (0x80000000).

Example ElementIdMap definition.   The code below demonstrates the creation of a class
     for a map from a foreign ID: "ON_UUID" with a compare function, "ON_UuidCompare".
     as this is a fixed size key, the default IO class, "FixedSizeForeignIdIO" is used.

 struct ON_UuidLess
    {
    bool operator () (ON_UUID const& id1, ON_UUID const& id2) { return ON_UuidCompare (&id1, &id2) < 0; }
    };

    typedef  ElementIdMap <ON_UUID, ON_UuidLess> T_UuidToElementIdMap;



 struct ON_UuidToElementIdMap : T_UuidToElementIdMap
    {
    FixedSizeForeignIdIO<ON_UUID>    idIo;

    ON_UuidToElementIdMap () : T_UuidToElementIdMap (idIo) { }
    };

+===============+===============+===============+===============+===============+======*/

Constructor & Destructor Documentation

ElementIdMap ( _ForeignIdIO const &  io)

Member Function Documentation

T_AUInt64 GetId ( _ForeignId const &  foreignId)

Return elementId for supplied foreignId.

If the foreignId is not currently mapped then one is generated by incrementing m_highestId.

Parameters
[in]foreignIdForeign object Id (templated).
Returns
element ID
BeFileName GetMapFileName ( WStringCR  baseName)
StatusInt Load ( DataInternalizer &  source)

Load map.

Parameters
[in]sourceData internalizer.

References Bentley::SUCCESS.

StatusInt Load ( WStringCR  baseFileName)

Load map.

Parameters
[in]baseFileNamefile name

References BeAssert, count(), Bentley::ERROR, NULL, SEEK_END, and SEEK_SET.

StatusInt Store ( DataExternalizer &  sink) const

Store map.

Parameters
[in]sinkData externalizer.

References Bentley::SUCCESS.

StatusInt Store ( WStringCR  baseFileName)

Store map.

Parameters
[in]baseFileNamefile name

References BeAssert, Bentley::ERROR, fwrite, NULL, and Bentley::SUCCESS.


The documentation for this class was generated from the following file:

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.