⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stafdatatypes.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2001                                              *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/#include "STAF.h"#include "STAFUtil.h"#include "STAFRefPtr.h"#include <deque>#include <map>typedef std::deque<STAFObject_t> STAFObjectList;typedef std::map<STAFString, STAFObject_t> STAFObjectMap;enum STAFObjectIteratorType_t{    kSTAFObjectListIterator     = 0,    kSTAFObjectMapKeyIterator   = 1,    kSTAFObjectMapValueIterator = 2};struct STAFObjectListIterator{    STAFObjectList::iterator iter;    STAFObjectList *listObject;};struct STAFObjectMapIterator{    STAFObjectMap::iterator iter;    STAFObjectMap *mapObject;};struct STAFObjectIteratorImpl{    STAFObjectIteratorType_t type;    union    {        STAFObjectListIterator *listIterator;        STAFObjectMapIterator *mapIterator;    };};struct STAFObjectMarshallingContext{    STAFObject_t mapClassMap;    STAFObject_t rootObject;};struct STAFObjectImpl{    STAFObjectType_t type;    bool isRef;    union    {        STAFObjectList               *listValue;        STAFObjectMap                *mapValue;        STAFObjectMarshallingContext *contextValue;        STAFString                   *scalarStringValue;    };};static STAFObjectImpl sNoneObj = { kSTAFNoneObject, true };static STAFObject_t sNoneObjT = &sNoneObj;static STAFString sColon(kUTF8_COLON);inline unsigned int incrementNChars(STAFString &theString,                                    unsigned int beginIndex,                                    unsigned int incrementLength){    // This is the only viable way to increment characters as we have a length    // in  "chars", but we really want to be working in bytes.    unsigned int endOfString = beginIndex;    for (unsigned int i = 0; i < incrementLength; ++i)        endOfString += theString.sizeOfChar(endOfString);    return endOfString;}inline STAFString getCLCString(STAFString &theString, unsigned int &index){    unsigned int colonIndex1 = theString.find(sColon, index);    unsigned int colonIndex2 = theString.find(sColon, colonIndex1 + 1);    unsigned int stringLength = theString.subString(        colonIndex1 + 1, colonIndex2 - colonIndex1 - 1).asUInt();    index = incrementNChars(theString, colonIndex2 + 1, stringLength);    return theString.subString(colonIndex2 + 1, index - colonIndex2 - 1);}inline STAFObject_t adoptPrimaryObject(STAFObject_t &context){    // Initialize the output object to be the context itself.  If the context    // doesn't have any map classes, then we set the output object to be the    // adopted root object and then destruct the context itself.    STAFObject_t obj = context;    if (context->contextValue->mapClassMap->mapValue->size() == 0)    {        STAFObjectMarshallingContextAdoptRootObject(context, &obj);        STAFObjectDestruct(&context);    }    return obj;}inline STAFObject_t unmarshallToPrimaryObject(STAFString &theString,                                              STAFObject_t context,                                              unsigned int beginIndex,                                              unsigned int endIndex,                                              unsigned int flags){                                       STAFObject_t newContext = 0;    STAFObjectUnmarshallFromString(        &newContext,        theString.subString(beginIndex, endIndex - beginIndex).getImpl(),        context,        flags);    return adoptPrimaryObject(newContext);}inline STAFObject_t unmarshallObject(STAFString &theString, STAFObject_t context,                                     unsigned int &index, unsigned int flags){    unsigned int beginIndex = index;    unsigned int colonIndex1 = theString.find(sColon, beginIndex);    unsigned int colonIndex2 = theString.find(sColon, colonIndex1 + 1);    unsigned int objectLength = theString.subString(colonIndex1 + 1,                                                    colonIndex2 - colonIndex1 -                                                    1).asUInt();    index = incrementNChars(theString, colonIndex2 + 1, objectLength);    return unmarshallToPrimaryObject(theString, context, beginIndex, index,                                     flags);}STAFRC_t STAFObjectConstructReference(STAFObject_t *pObject, STAFObject_t source){    if (pObject == 0) return kSTAFInvalidObject;    if (source  == 0) return kSTAFInvalidObject;    *pObject = new STAFObjectImpl;    STAFObjectImpl &obj = **pObject;    obj = *source;    obj.isRef = true;    return kSTAFOk;}STAFRC_t STAFObjectConstructNone(STAFObject_t *pObject){    if (pObject == 0) return kSTAFInvalidObject;    *pObject = new STAFObjectImpl;    STAFObjectImpl &obj = **pObject;    obj.type = kSTAFNoneObject;    obj.isRef = false;    return kSTAFOk;}STAFRC_t STAFObjectConstructScalarString(STAFObject_t *pObject,                                         STAFStringConst_t aString){    if (pObject == 0) return kSTAFInvalidObject;    *pObject = new STAFObjectImpl;    STAFObjectImpl &obj = **pObject;    obj.type = kSTAFScalarStringObject;    obj.isRef = false;    // XXX: Used to be this    // STAFStringConstructCopy(&obj.scalarStringValue, aString, 0);    obj.scalarStringValue = new STAFString(aString);    return kSTAFOk;}STAFRC_t STAFObjectConstructList(STAFObject_t *pObject){    if (pObject == 0) return kSTAFInvalidObject;    *pObject = new STAFObjectImpl;    STAFObjectImpl &obj = **pObject;    obj.type = kSTAFListObject;    obj.isRef = false;    obj.listValue = new STAFObjectList;    return kSTAFOk;}STAFRC_t STAFObjectConstructListIterator(STAFObjectIterator_t *pIter,                                         STAFObject_t list){    if (pIter == 0) return kSTAFInvalidObject;    // XXX: Might this want to be a new kSTAFInvalidOperation ?    if (list->type != kSTAFListObject) return kSTAFInvalidObject;    *pIter = new STAFObjectIteratorImpl;    STAFObjectIteratorImpl &iter = **pIter;    iter.type = kSTAFObjectListIterator;    iter.listIterator = new STAFObjectListIterator;    iter.listIterator->iter = list->listValue->begin();    iter.listIterator->listObject = list->listValue;    return kSTAFOk;}STAFRC_t STAFObjectConstructMap(STAFObject_t *pObject){    if (pObject == 0) return kSTAFInvalidObject;    *pObject = new STAFObjectImpl;    STAFObjectImpl &obj = **pObject;    obj.type = kSTAFMapObject;    obj.isRef = false;    obj.mapValue = new STAFObjectMap;    return kSTAFOk;}STAFRC_t STAFObjectConstructMapKeyIterator(STAFObjectIterator_t *pIter,                                           STAFObject_t map){    if (pIter == 0) return kSTAFInvalidObject;    // XXX: Might this want to be a new kSTAFInvalidOperation ?    if (map->type != kSTAFMapObject) return kSTAFInvalidObject;    *pIter = new STAFObjectIteratorImpl;    STAFObjectIteratorImpl &iter = **pIter;    iter.type = kSTAFObjectMapKeyIterator;    iter.mapIterator = new STAFObjectMapIterator;    iter.mapIterator->iter = map->mapValue->begin();    iter.mapIterator->mapObject = map->mapValue;    return kSTAFOk;}STAFRC_t STAFObjectConstructMapValueIterator(STAFObjectIterator_t *pIter,                                             STAFObject_t map){    if (pIter == 0) return kSTAFInvalidObject;    // XXX: Might this want to be a new kSTAFInvalidOperation ?    if (map->type != kSTAFMapObject) return kSTAFInvalidObject;    *pIter = new STAFObjectIteratorImpl;    STAFObjectIteratorImpl &iter = **pIter;    iter.type = kSTAFObjectMapValueIterator;    iter.mapIterator = new STAFObjectMapIterator;    iter.mapIterator->iter = map->mapValue->begin();    iter.mapIterator->mapObject = map->mapValue;    return kSTAFOk;}STAFRC_t STAFObjectConstructMapClassDefinitionIterator(    STAFObjectIterator_t *pIter, STAFObject_t context){    if (pIter == 0) return kSTAFInvalidObject;    // XXX: Might this want to be a new kSTAFInvalidOperation ?    if (context->type != kSTAFMarshallingContextObject)        return kSTAFInvalidObject;    return STAFObjectConstructMapKeyIterator(               pIter, context->contextValue->mapClassMap);}STAFRC_t STAFObjectConstructMarshallingContext(STAFObject_t *pObject){    if (pObject == 0) return kSTAFInvalidObject;    *pObject = new STAFObjectImpl;    STAFObjectImpl &obj = **pObject;    obj.type = kSTAFMarshallingContextObject;    obj.isRef = false;    obj.contextValue = new STAFObjectMarshallingContext;    STAFObjectConstructNone(&obj.contextValue->rootObject);    STAFObjectConstructMap(&obj.contextValue->mapClassMap);    return kSTAFOk;}STAFRC_t STAFObjectDestruct(STAFObject_t *pObject){    if (pObject  == 0) return kSTAFInvalidObject;    if (*pObject == 0) return kSTAFInvalidObject;    STAFObjectImpl &obj = **pObject;    if (!obj.isRef)    {        if (obj.type == kSTAFScalarStringObject)        {            delete obj.scalarStringValue;        }        else if (obj.type == kSTAFListObject)        {            // First destruct everything in the list            for (STAFObjectList::iterator iter = obj.listValue->begin();                 iter != obj.listValue->end();                 ++iter)            {                STAFObjectDestruct(&(*iter));            }            // Then, get rid of the list            delete obj.listValue;        }        else if (obj.type == kSTAFMapObject)        {            // First get rid of all the object values in the map.            // The keys will be deleted automatically.            for (STAFObjectMap::iterator iter = obj.mapValue->begin();                 iter != obj.mapValue->end();                 ++iter)            {                STAFObjectDestruct(&iter->second);            }            // Then, get rid of the map            delete obj.mapValue;        }        else if (obj.type == kSTAFMarshallingContextObject)        {            STAFObjectDestruct(&obj.contextValue->mapClassMap);            STAFObjectDestruct(&obj.contextValue->rootObject);            delete obj.contextValue;        }    }    delete *pObject;    *pObject = 0;    return kSTAFOk;}STAFRC_t STAFObjectIsStringMarshalledData(STAFStringConst_t string,                                          unsigned int *isMarshalledData){    if (string == 0) return kSTAFInvalidObject;    if (isMarshalledData == 0) return kSTAFInvalidParm;    static STAFString marshalledDataMarker("@SDT/");    return STAFStringStartsWith(string, marshalledDataMarker.getImpl(),                                isMarshalledData, 0);}STAFRC_t STAFObjectGetType(STAFObject_t object, STAFObjectType_t *type){    if (object == 0) return kSTAFInvalidObject;    if (type   == 0) return kSTAFInvalidParm;    *type = object->type;    return kSTAFOk;}STAFRC_t STAFObjectGetSize(STAFObject_t object, unsigned int *size){    if (object == 0) return kSTAFInvalidObject;    if (size   == 0) return kSTAFInvalidParm;    if (object->type == kSTAFNoneObject)        *size = 0;    else if (object->type == kSTAFScalarStringObject)        *size = object->scalarStringValue->length();    else if (object->type == kSTAFMapObject)        *size = object->mapValue->size();    else if (object->type == kSTAFListObject)        *size = object->listValue->size();    else if (object->type == kSTAFMarshallingContextObject)        return STAFObjectGetSize(object->contextValue->mapClassMap, size);    else      *size = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -