当前位置: 首页>>代码示例>>C++>>正文


C++ HANDLE::fail方法代码示例

本文整理汇总了C++中HANDLE::fail方法的典型用法代码示例。如果您正苦于以下问题:C++ HANDLE::fail方法的具体用法?C++ HANDLE::fail怎么用?C++ HANDLE::fail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HANDLE的用法示例。


在下文中一共展示了HANDLE::fail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: open

bool StLangMap::open(const StString& theLngFilePath) {
    myLngFile = theLngFilePath;

#ifdef _WIN32
    // it is possible to use std::ifstream, but only for ANSI filenames
    HANDLE inFile = CreateFileW(myLngFile.toUtfWide().toCString(), GENERIC_READ, FILE_SHARE_READ, NULL,
                                OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if(inFile == INVALID_HANDLE_VALUE) {
        ST_DEBUG_LOG("StLangMap, Failed to open language file \"" + myLngFile + '\"');
        return false;
    }
#else
    std::ifstream inFile;
    inFile.open(myLngFile.toCString());
    if(inFile.fail()) {
        ST_DEBUG_LOG("StLangMap, Failed to open language file \"" + myLngFile + '\"');
        return false;
    }
#endif
    char bufferOrig[READ_BUFFER_SIZE]; bufferOrig[0] = '\0';
    char* bufferLineOrig = new char[1];
    bufferLineOrig[0] = '\0';
    size_t aLineSize = 0;

    StString bufferLineUTF;
    bool isCont = false;
    size_t oldLen = 0;

#ifdef _WIN32
    DWORD aBytesRead = 0;
    while(ReadFile(inFile, bufferOrig, READ_BUFFER_SIZE, &aBytesRead, NULL)) {
        if(aBytesRead < 1) {
            break;
        }
#else
    while(!inFile.eof()) {
        inFile.read(bufferOrig, READ_BUFFER_SIZE);
        const size_t aBytesRead = inFile.gcount();
        if(aBytesRead < 1) {
            break;
        }
#endif
        size_t lineStart = 0;
        for(size_t c = 0; c < (size_t )aBytesRead; ++c) {
            if(bufferOrig[c] == '\n') {
                if(isCont) {
                    char* aCopy = new char[oldLen + c - lineStart + 1];
                    stMemCpy(&aCopy[0], bufferLineOrig, oldLen);
                    stMemCpy(&aCopy[oldLen], &bufferOrig[lineStart], (c - lineStart));
                    aLineSize = oldLen + c - lineStart;
                    delete[] bufferLineOrig;
                    bufferLineOrig = aCopy;
                } else {
                    delete[] bufferLineOrig;
                    bufferLineOrig = new char[c - lineStart + 1];
                    stMemCpy(bufferLineOrig, &bufferOrig[lineStart], (c - lineStart));
                    aLineSize = c - lineStart;
                }
                // remove CR symbol if needed
                if(aLineSize > 0 && bufferLineOrig[aLineSize - 1] == stUtf8_t(13)) {
                    --aLineSize;
                }
                bufferLineOrig[aLineSize] = '\0';

                bufferLineUTF = StString(bufferLineOrig);
                parseLine(bufferLineUTF);

                lineStart = c + 1;
                oldLen = 0;
                isCont = false;

            } else if(c == (READ_BUFFER_SIZE - 1)) {
                char* aCopy = new char[oldLen + READ_BUFFER_SIZE - lineStart];
                if(oldLen > 0) {
                    stMemCpy(aCopy, bufferLineOrig, oldLen);
                }
                stMemCpy(&aCopy[oldLen], &bufferOrig[lineStart], (READ_BUFFER_SIZE - lineStart));
                delete[] bufferLineOrig;
                bufferLineOrig = aCopy;
                oldLen += (READ_BUFFER_SIZE - lineStart);
                isCont = true;
            }

            if(!isCont) {
                delete[] bufferLineOrig;
                bufferLineOrig = new char[1];
                bufferLineOrig[0] = '\0';
            }
        }
    }
    delete[] bufferLineOrig;
#ifdef _WIN32
    CloseHandle(inFile);
#else
    inFile.close();
#endif
    ST_DEBUG_LOG("StLangMap, Loaded language file \"" + myLngFile + '\"');
    return true;
}

//.........这里部分代码省略.........
开发者ID:KindDragon,项目名称:sview,代码行数:101,代码来源:StLangMap.cpp


注:本文中的HANDLE::fail方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。