Sample Code for dxfInFields() with Order Independence

The following is sample code for AsdkPoly::dxfInFields():

Acad::ErrorStatus
AsdkPoly::dxfInFields(AcDbDxfFiler* filer)
{
    assertWriteEnabled();
    Acad::ErrorStatus es = Acad::eOk;
    resbuf rb;
    if ((AcDbCurve::dxfInFields(filer) != Acad::eOk)
        || !filer->atSubclassData("AsdkPoly"))
    {
        return filer->filerStatus();
    }
    // Object Version
    Adesk::Int16 version;
    filer->readItem(&rb);
    if (rb.restype != AcDb::kDxfInt16) 
    {
        filer->pushBackItem();
        filer->setError(Acad::eInvalidDxfCode,
            "\nError: expected group code %d (version)",
            AcDb::kDxfInt16);
        return filer->filerStatus();
    }
    version = rb.resval.rint;
    if (version > VERSION)
        return Acad::eMakeMeProxy;
    AcGePoint3d cen3d,sp3d;
    AcGePoint2d cen2d,sp2d;
    long numSides;
    AcDbObjectId textStyle;
    double elevation;
    Adesk::UInt32 fieldsFlags = 0;
    char * pName = NULL;
    AcGeVector3d planeNormal;
    while ((es == Acad::eOk)
        && ((es = filer->readResBuf(&rb)) == Acad::eOk))
    {
        switch (rb.restype) {
        case AcDb::kDxfXCoord:
            if (version == 1)
                cen3d = asPnt3d(rb.resval.rpoint);
            else 
                cen2d = asPnt2d(rb.resval.rpoint);
            fieldsFlags |= 0x1;
            break;
        case AcDb::kDxfXCoord + 1:
            if (version == 1)
                sp3d = asPnt3d(rb.resval.rpoint);
            else
                sp2d = asPnt2d(rb.resval.rpoint);
            fieldsFlags |= 0x2;
            break;
        case AcDb::kDxfInt32:
            numSides = rb.resval.rlong;
            fieldsFlags |= 0x4;
            break;
        case AcDb::kDxfNormalX:
            planeNormal = asVec3d(rb.resval.rpoint);
            fieldsFlags |= 0x8;
            break;
        case AcDb::kDxfText:
            acutUpdString(rb.resval.rstring,pName);
            fieldsFlags |= 0x11;
            break;
        case AcDb::kDxfHardPointerId:
            acdbGetObjectId(textStyle, rb.resval.rlname);
            fieldsFlags |= 0x12;
            break;
        case AcDb::kDxfReal:
            if (version == 2)
            {
                fieldsFlags |= 0x10;
                elevation = rb.resval.rreal;
                break;    
            }
            //fall through intentional
        default:
            // An unrecognized group. Push it back so that
            // the subclass can read it again.
            filer->pushBackItem();
            es = Acad::eEndOfFile;
            break;
        }
    }
    // At this point, the es variable must contain eEndOfFile,
    // either from readResBuf() or from pushbackBackItem(). If 
    // not, it indicates that an error happened and we should
    // return immediately.
    //
    if (es != Acad::eEndOfFile)
        return Acad::eInvalidResBuf;
    // Now check to be sure all necessary group codes were 
    // present.
    //
    // Mandatory fields:
    // - center
    // - start point
    // - normal
    // - number of sides
    // - elevation (if version > 1)
    short required[]  = 
        {AcDb::kDxfXCoord, AcDb::kDxfXCoord+1, AcDb::kDxfInt32,
        AcDb::kDxfNormalX, AcDb::kDxfReal};
    for (short i = 0; i < (version>1?4:3); i++) {
        if (!fieldsFlags & 0x1) {
            filer->setError(Acad::eMissingDxfField,
                "\nMissing DXF group code: %d", 2, required[i]);
            return Acad::eMissingDxfField;
        } else
            fieldsFlags >>= 1;
    }
    mPlaneNormal = planeNormal;
    mNumSides = numSides;
    mTextStyle = textStyle;
    setName(pName);
    acutDelString(pName);
    if (version==1)
    {
        //convert data from old format
        acdbWcs2Ecs(asDblArray(cen3d),asDblArray(cen3d),
            asDblArray(planeNormal),Adesk::kFalse);
        mCenter.set(cen3d.x,cen3d.y);
        mElevation = cen3d.z;
        acdbWcs2Ecs(asDblArray(sp3d),asDblArray(sp3d),
            asDblArray(planeNormal),Adesk::kFalse);
        mStartPoint.set(sp3d.x,sp3d.y);
        assert(mElevation == sp3d.z);
    } else {
        mCenter = cen2d;
        mStartPoint = sp2d;
        mElevation = elevation;
    }
    return es;
}

The complete code for the AsdkPoly application-defined class can be found in the samples directory.