Esempio n. 1
0
cxBool cxHashRootLoadWithReader(cxHashRoot root,xmlTextReaderPtr reader)
{
    cxBool ret = false;
    while(xmlTextReaderRead(reader)){
        if(root->isError){
            break;
        }
        if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){
            continue;
        }
        cxConstChars temp = cxXMLReadElementName(reader);
        if(ELEMENT_IS_TYPE(cxHashRoot)){
            ret = true;
            break;
        }
    }
    CX_RETURN(!ret,false);
    cxAutoPoolPush();
    while(xmlTextReaderRead(reader)){
        if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){
            continue;
        }
        cxConstChars temp = cxXMLReadElementName(reader);
        if(ELEMENT_IS_TYPE(cxDBEnv)){
            cxHashRootReadDBEnv(root,reader);
            continue;
        }
        cxConstChars  sid = cxXMLAttr(reader, "id");
        if(sid == NULL){
            CX_WARN("element %s:not set id,data not save to hash table",temp);
            continue;
        }
        cxAny object = NULL;
        if(ELEMENT_IS_TYPE(cxString)){
            //cxTypesString
            object = cxHashRootReadString(root,reader);
        }else if(ELEMENT_IS_TYPE(cxHash)){
            //cxTypesHash
            object = cxHashRootReadHash(root,reader);
        }else if(ELEMENT_IS_TYPE(cxArray)){
            //cxTypesArray
            object = cxHashRootReadArray(root,reader);
        }else{
            //cxTypesNumber
            object = cxHashRootReadNumber(root, temp, reader);
        }
        if(object != NULL){
            cxHashSet(root->items, cxHashStrKey(sid), object);
        }
    }
    cxAutoPoolPop();
    return ret;
}
Esempio n. 2
0
static void cxHashRootReadDB(cxDBEnv env,cxHashRoot root,xmlTextReaderPtr reader)
{
    cxReaderAttrInfo *info = cxReaderAttrInfoMake(reader, root, env);
    int depth = xmlTextReaderDepth(reader);
    while(xmlTextReaderRead(reader) && depth != xmlTextReaderDepth(reader)){
        if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){
            continue;
        }
        cxConstChars temp = cxXMLReadElementName(reader);
        if(!ELEMENT_IS_TYPE(cxDB)){
            continue;
        }
        cxConstChars file = cxXMLAttr(reader,"file");
        cxConstChars table = cxXMLAttr(reader,"table");
        cxConstChars type = cxXMLAttr(reader,"type");
        cxConstChars sid = cxXMLAttr(reader,"id");
        cxConstChars path = cxXMLAttr(reader,"path");
        //assert file copy ->to document
        cxBool copy = cxXMLReadBoolAttr(info, "copy", false);
        if(copy && file != NULL){
            cxCopyFile(file, NULL, NULL);
        }
        cxBool rdonly = cxXMLReadBoolAttr(info,  "rdonly", false);
        if(sid == NULL){
            CX_WARN("db id not set,will can't add dataset");
        }
        cxString sfile = NULL;
        if(cxConstCharsEqu(path, "assert")){
            sfile = cxAssetsPath(file);
            //assert must set true
            rdonly = true;
        }else if(cxConstCharsEqu(path, "document")){
            sfile = cxDocumentPath(file);
        }else{
            CX_ERROR("must set path assert or document");
        }
        cxAny db = NULL;
        if(file != NULL && table != NULL && type != NULL){
            db = cxDBCreate(env, cxStringBody(sfile), table, type, rdonly);
        }
        if(db != NULL && sid != NULL){
            cxHashSet(root->items, cxHashStrKey(sid), cxDBTypesCreate(db));
        }else{
            CX_ERROR("open dbenv type %s,db %s:%s failed",cxStringBody(env->type),file,table);
        }
    }
}
Esempio n. 3
0
cxBool cxUtil::WriteFileData(const cxStr *path,const cxStr *data,cxBool replace)
{
    CX_ASSERT(cxStr::IsOK(path) && cxStr::IsOK(data), "path or data error");
    int length = 0;
    if(FileExists(path, &length) && !replace){
        CX_WARN("file exists not write data");
        return false;
    }
    std::ofstream fs;
    fs.open(path->Data(),std::ios::out|std::ios::binary);
    if(!fs.is_open()){
        return false;
    }
    fs.write(data->Data(), data->Size());
    fs.close();
    return true;
}