Share
 
 

Class Data or Xdata Version Numbers

The version number can be stored as a data member of the class, and can be filed in and out as the first data member for each object. Because this data is persistent, and is the first item read, it can be checked to determine the version of the object before any other data is read.

When a number is used to differentiate versions of an object, the parent ObjectARX application must be able to handle these two cases of incompatible versions of objects:

  • When the application encounters an outdated version of an object in a file, it should be able to update the object to the current version. Updating an old object involves adding any new data members and member functions, as well as changing the version number.
  • When an older version of the application encounters a newer version of an object (that is, when the revision number of an object is greater than the revision number of the application), the custom class's dxfInFields() and dwgInFields() functions should immediately return the error code eMakeMeProxy to AutoCAD. AutoCAD will then create a proxy object for the drawing session, and write the original object to file when the drawing is saved.

Object versioning with a data-member version number is illustrated in the following code fragments from \samples\entity\polysamp\poly.cpp in the ObjectARX SDK.

// Object Version
#define VERSION 1
...
Acad::ErrorStatus
AsdkPoly::dwgInFields(AcDbDwgFiler* filer)
{
...
    // Object Version - must always be the first item
    Adesk::Int16 version;
    filer->readItem(&version);
    if (version > VERSION)
        return Acad::eMakeMeProxy;
...
}
Acad::ErrorStatus
AsdkPoly::dwgOutFields(AcDbDwgFiler* filer) const
{
...
    // Object Version - must always be the first item
    Adesk::Int16 version = VERSION;
    filer->writeItem(version);
...
}
Acad::ErrorStatus
AsdkPoly::dxfInFields(AcDbDxfFiler* filer)
{
...
    // Object Version
        case AcDb::kDxfInt16:
            Adesk::Int16 version;
            version = rb.resval.rint;
            if (version > VERSION)
                return Acad::eMakeMeProxy;
            break;
...
}
Acad::ErrorStatus
AsdkPoly::dxfOutFields(AcDbDxfFiler* filer) const
{
...
    // Object Version
    Adesk::Int16 version = VERSION;
    filer->writeItem(AcDb::kDxfInt16, version);
...
}

Was this information helpful?