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


C++ Data类代码示例

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


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

示例1: fullPathForFilename

Data FileUtilsAndroid::getData(const std::string& filename, bool forString)
{
    if (filename.empty())
    {
        return Data::Null;
    }

    unsigned char* data = nullptr;
    ssize_t size = 0;
    string fullPath = fullPathForFilename(filename);

    // by lisyunn
    LOGD("*** 1fullPath = %s ***", fullPath.c_str());

    if (fullPath[0] != '/')
    {
        string relativePath = string();

        size_t position = fullPath.find("assets/");
        if (0 == position) {
            // "assets/" is at the beginning of the path and we don't want it
            relativePath += fullPath.substr(strlen("assets/"));
        } else {
            relativePath += fullPath;
        }
        LOGD("relative path = %s", relativePath.c_str());

        if (nullptr == FileUtilsAndroid::assetmanager) {
            LOGD("... FileUtilsAndroid::assetmanager is nullptr");
            return Data::Null;
        }
        // by lisyunn start
#if 0
        // read asset data
        AAsset* asset =
            AAssetManager_open(FileUtilsAndroid::assetmanager,
                               relativePath.c_str(),
                               AASSET_MODE_UNKNOWN);

        if (nullptr == asset) {
            LOGD("asset is nullptr");
            return Data::Null;
        }

        off_t fileSize = AAsset_getLength(asset);

        if (forString)
        {
            data = (unsigned char*) malloc(fileSize + 1);
            data[fileSize] = '\0';
        }
        else
        {
            data = (unsigned char*) malloc(fileSize);
        }

        int bytesread = AAsset_read(asset, (void*)data, fileSize);
        size = bytesread;

        AAsset_close(asset);


        // using obb expansion for android (cocos2dx-3.x)
#else
        string path = getApkPath();
        LOGD("*** getApkPath = %s ***", path.c_str());
        string datapath = "assets/" + relativePath;
        // zip fileから指定した画像を読み出して表示
        data = FileUtils::getInstance()->getFileDataFromZip(path.c_str() ,datapath.c_str(),&size);
#endif
        // by lisyunn end
    }
    else
    {
        do
        {
            // read rrom other path than user set it
            //CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
            const char* mode = nullptr;
            if (forString)
                mode = "rt";
            else
                mode = "rb";

            FILE *fp = fopen(fullPath.c_str(), mode);
            CC_BREAK_IF(!fp);

            long fileSize;
            fseek(fp,0,SEEK_END);
            fileSize = ftell(fp);
            fseek(fp,0,SEEK_SET);
            if (forString)
            {
                data = (unsigned char*) malloc(fileSize + 1);
                data[fileSize] = '\0';
            }
            else
            {
                data = (unsigned char*) malloc(fileSize);
            }
//.........这里部分代码省略.........
开发者ID:chaosren,项目名称:mySample2,代码行数:101,代码来源:CCFileUtilsAndroid.cpp

示例2: GetType

    int Ardb::SortCommand(Context& ctx, const Slice& key, SortOptions& options, DataArray& values)
    {
        values.clear();

        KeyType keytype = KEY_END;
        GetType(ctx, key, keytype);

        switch (keytype)
        {
            case LIST_META:
            {
                ListRange(ctx, key, 0, -1);
                break;
            }
            case SET_META:
            {
                SetMembers(ctx, key);
                break;
            }
            case ZSET_META:
            {
                ZSetRange(ctx, key, 0, -1, false, false, OP_GET);
                if (NULL == options.by)
                {
                    options.nosort = true;
                }
                break;
            }
            default:
            {
                return ERR_INVALID_TYPE;
            }
        }
        DataArray sortvals;
        if (ctx.reply.MemberSize() > 0)
        {
            for (uint32 i = 0; i < ctx.reply.MemberSize(); i++)
            {
                Data v;
                v.SetString(ctx.reply.MemberAt(i).str, true);
                sortvals.push_back(v);
            }
        }
        if (sortvals.empty())
        {
            return 0;
        }
        if (options.with_limit)
        {
            if (options.limit_offset < 0)
            {
                options.limit_offset = 0;
            }
            if ((uint32) options.limit_offset > sortvals.size())
            {
                values.clear();
                return 0;
            }
            if (options.limit_count < 0)
            {
                options.limit_count = sortvals.size();
            }
        }

        std::vector<SortValue> sortvec;
        if (!options.nosort)
        {
            if (NULL != options.by)
            {
                sortvec.reserve(sortvals.size());
            }
            for (uint32 i = 0; i < sortvals.size(); i++)
            {
                if (NULL != options.by)
                {
                    sortvec.push_back(SortValue(&sortvals[i]));
                    if (GetValueByPattern(ctx, options.by, sortvals[i], sortvec[i].cmp) < 0)
                    {
                        DEBUG_LOG("Failed to get value by pattern:%s", options.by);
                        sortvec[i].cmp.Clear();
                        continue;
                    }
                }
                if (options.with_alpha)
                {
                    if (NULL != options.by)
                    {
                        sortvec[i].cmp.ToString();
                    }
                    else
                    {
                        sortvals[i].ToString();
                    }
                }
            }
            if (NULL != options.by)
            {
                if (!options.is_desc)
                {
                    std::sort(sortvec.begin(), sortvec.end(), less_value<SortValue>);
//.........这里部分代码省略.........
开发者ID:mastergyp,项目名称:ardb,代码行数:101,代码来源:sort.cpp

示例3: ret

Data Data::operator *(const Data &data) const
{
    if(data.type == INT)
    {
        Data ret(Data::INT);
        ret.value.i = value.i * data.value.i;
        return ret;
    }
    if(value.i < 0)
    {
        throw QString("Runtime error: invalid multiplication of multiset " + this->toString() + " * " + data.toString() );
    }
    if(data.type == MULTIUNIT)
    {
        Data ret(Data::MULTIUNIT);
        ret.value.multiUnit = value.i * data.value.multiUnit;
        return ret;
    }
    else if(data.type == MULTIBOOL)
    {
        Data ret(Data::MULTIBOOL);
        ret.value.multiBool.t = value.i * data.value.multiBool.t;
        ret.value.multiBool.f = value.i * data.value.multiBool.f;
        return ret;
    }
    else if(data.type == MULTIINT)
    {
        Data ret(Data::MULTIINT);
        QMapIterator<int, int>i(*data.value.multiInt);
        while(i.hasNext())
        {
            i.next();
            if(value.i)
                ret.value.multiInt->insert(i.key(), i.value() * value.i);
        }
        return ret;
    }
    Q_ASSERT(false);
    return Data();
}
开发者ID:LordNavro,项目名称:CPNSimulator,代码行数:40,代码来源:compiler.cpp

示例4: fullPathForFilename

Data FileUtilsAndroid::getData(const std::string& filename, bool forString)
{
    if (filename.empty())
    {
        return Data::Null;
    }

    unsigned char* data = nullptr;
    ssize_t size = 0;
    string fullPath = fullPathForFilename(filename);
    cocosplay::updateAssets(fullPath);

    if (fullPath[0] != '/')
    {
        string relativePath = string();

        size_t position = fullPath.find("assets/");
        if (0 == position) {
            // "assets/" is at the beginning of the path and we don't want it
            relativePath += fullPath.substr(strlen("assets/"));
        } else {
            relativePath += fullPath;
        }
        CCLOGINFO("relative path = %s", relativePath.c_str());

        if (nullptr == FileUtilsAndroid::assetmanager) {
            LOGD("... FileUtilsAndroid::assetmanager is nullptr");
            return Data::Null;
        }

        // read asset data
        AAsset* asset =
            AAssetManager_open(FileUtilsAndroid::assetmanager,
                               relativePath.c_str(),
                               AASSET_MODE_UNKNOWN);
        if (nullptr == asset) {
            LOGD("asset is nullptr");
            return Data::Null;
        }

        off_t fileSize = AAsset_getLength(asset);

        if (forString)
        {
            data = (unsigned char*) malloc(fileSize + 1);
            data[fileSize] = '\0';
        }
        else
        {
            data = (unsigned char*) malloc(fileSize);
        }

        int bytesread = AAsset_read(asset, (void*)data, fileSize);
        size = bytesread;

        AAsset_close(asset);
    }
    else
    {
        do
        {
            // read rrom other path than user set it
            //CCLOG("GETTING FILE ABSOLUTE DATA: %s", filename);
            const char* mode = nullptr;
            if (forString)
                mode = "rt";
            else
                mode = "rb";

            FILE *fp = fopen(fullPath.c_str(), mode);
            CC_BREAK_IF(!fp);

            long fileSize;
            fseek(fp,0,SEEK_END);
            fileSize = ftell(fp);
            fseek(fp,0,SEEK_SET);
            if (forString)
            {
                data = (unsigned char*) malloc(fileSize + 1);
                data[fileSize] = '\0';
            }
            else
            {
                data = (unsigned char*) malloc(fileSize);
            }
            fileSize = fread(data,sizeof(unsigned char), fileSize,fp);
            fclose(fp);

            size = fileSize;
        } while (0);
    }

    Data ret;
    if (data == nullptr || size == 0)
    {
        std::string msg = "Get data from file(";
        msg.append(filename).append(") failed!");
        CCLOG("%s", msg.c_str());
    }
    else
//.........这里部分代码省略.........
开发者ID:colaholicu,项目名称:custom-cocos2dx,代码行数:101,代码来源:CCFileUtils-android.cpp

示例5: listen

Data Server::listen()
{
    Data d;

    // read the key from the incoming data
    try
    {
        int key = -1;
        boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&key), sizeof(int)));

        switch( key )
        {
            case 0: // open image
            {
                // send back an image id
                int image_id = 1;
                boost::asio::write(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&image_id), sizeof(int)));

                // get width & height
                int width, height, rArea, version;
                float currentFrame;

                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&width), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&height), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&rArea), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&version), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&currentFrame), sizeof(int)));

                // create data object
                d.mType = key;
                d.mWidth = width;
                d.mHeight = height;
                d.mRArea = rArea;
                d.mVersion = version;
                d.mCurrentFrame = currentFrame;
                break;
            }
            case 1: // image data
            {
                d.mType = key;

                // receive image id
                int image_id;
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&image_id), sizeof(int)) );

                // get data info
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mX), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mY), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mWidth), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mHeight), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mRArea), sizeof(long long)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mVersion), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mCurrentFrame), sizeof(float)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mSpp), sizeof(int)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mRam), sizeof(long long)));
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mTime), sizeof(int)));

                // get aov name's size
                size_t aov_size=0;
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&aov_size), sizeof(size_t)));

                // get aov name
                d.mAovName = new char[aov_size];
                boost::asio::read(mSocket, boost::asio::buffer(d.mAovName, aov_size));

                // get pixels
                int num_samples = d.width() * d.height() * d.spp();
                d.mPixelStore.resize(num_samples);
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&d.mPixelStore[0]), sizeof(float)*num_samples)) ;
                break;
            }
            case 2: // close image
            {
                int image_id;
                d.mType = key;
                boost::asio::read(mSocket, boost::asio::buffer(reinterpret_cast<char*>(&image_id), sizeof(int)));
                mSocket.close();
                break;
            }
            case 9: // quit
            {
                d.mType = 9;

                //debug Closing socket
                std::cout << "Socket closed" << std::endl;

                mSocket.close();

                // This fixes all nuke destructor issues on windows
                mAcceptor.close();
                break;
            }
        }
    }
    catch( ... )
    {
        mSocket.close();
        throw std::runtime_error("Could not read from socket!");
    }
    return d;
//.........这里部分代码省略.........
开发者ID:raulpercy,项目名称:Aton,代码行数:101,代码来源:Server.cpp

示例6: main


//.........这里部分代码省略.........
			} else if (cmdAlarm) {
				// alarm should be turned off
				cmdAlarm = 0;
				speaker = 0;
			}

			cmdRefreshText = false;

		}
		// ## every minute we can dispatch data over serial or over WLAN to uradmonitor
		if (cmdSend) {
			char tmp[200];
			sprintf(tmp,"{\"data\":{ \"id\":\"%08lX\","
					"\"type\":\"%X\",\"detector\":\"%s\","
					"\"cpm\":%lu,\"temperature\":%.2f,\"uptime\": %lu,"
					"\"pressure\":%lu,\"dust\":%.2f,\"co2\":%.2f,\"voc\":%.2f,"
					"\"battery\":%.2f,\"tube\":%u}}",
					deviceID, DEV_MODEL, aux_detectorName(DEV_RAD_DETECTOR), geigerCPM, data.bmp180_temp, time.getTotalSec(),
					data.bmp180_pressure, data.gp2y10_dust,data.vz89_co2, data.vz89_voc, data.battery_voltage, data.geiger_voltage);
			data.serial_sent += strlen(tmp);
			uart0.send(tmp);

			// internet code here

			sprintf(tmp,"id=%08lX&ts=%ld&inv=%d&ind=%d&s1t=%2.2f&cpm=%ld&voc=%.2f&co2=%.2f",
								deviceID,
								time.getTotalSec(),
								data.geiger_voltage,
								data.geiger_duty,
								data.bmp180_temp,
								geigerCPM,
								data.vz89_voc, data.vz89_co2);

						wifi.sendData(tmp);
			cmdSend = false;
		}

		// ## act on the gui elements
		// read a new touch event only if we are done with previous: useful for handling confirmation "modal" "dialogs"
		if (uiResult == 0) {
			uiResult = gui.readTouchEvent();
			// reset backlight timeout on valid touch
			if (uiResult > 0) {
				secTimeout = 0;
				backlight(true);
				// if screen is pressed while alarm is on, stop alarm
				if (cmdAlarm) {
					cmdAlarm = false;
					speaker = 0;
				}
			}
		}
		// handle special cases: click on wlan AP buttons
		if (uiResult >= ID_BUTTON_WLAN_START && uiResult < ID_BUTTON_WLAN_STOP) {
			uint8_t ap_index = uiResult - ID_BUTTON_WLAN_START;
			// connect and return to main screen
			wifi.connectWiFi(data.freeAPList[ap_index], "");
			uiResult = 0;
			gui.drawPage(PAGE_MAIN);
		}
		// handle regular buttons
		switch (uiResult) {
			case  ID_BUTTON_SHUTDOWN: {
				uint16_t result = gui.showYesNoPopup("Are you sure?");
				if (result == ID_YES)
					shutdown();
开发者ID:fluppie,项目名称:uradmonitor_d,代码行数:67,代码来源:Application.cpp

示例7: selector

void VarSelectorFind::getVariables(const Data& iData,
                                   int iInit,
                                   float iOffset,
                                   const Location& iLocation,
                                   std::vector<std::string>& iVariables) const {
    Input* inputF = iData.getInput();
    Input* inputO = iData.getObsInput();

    std::vector<std::string> variables;
    inputF->getVariables(variables);

    int locationId = iLocation.getId();

    // Members
    std::vector<Member> members;
    inputF->getMembers(members);

    std::vector<std::string> varList;
    std::vector<std::string> varRemaining = variables;

    int numDays = (int) Global::getTimeDiff(mEndDate, 0, 0, mStartDate, 0, 0)/24;
    std::vector<float> obsTarget;
    obsTarget.resize(numDays);

    // Load the target observations
    for(int d = 0; d < numDays; d++) {
        int currDate = Global::getDate(mStartDate, 24*d);
        obsTarget[d] = inputO->getValue(currDate, iInit, iOffset, iLocation.getId(), 0, mVariable);
    }

    std::map<std::string, std::vector<float> > forecasts;

    std::vector<std::pair<std::string, float> > corrs;
    SelectorAnalog selector(makeOptionsObs(mVariable), iData);
    Parameters par;
    selector.getDefaultParameters(par);
    for(int v = 0; v < (int) variables.size(); v++) {
        std::string currVar = variables[v];
        // Load the observations
        /*
        std::vector<float> obs;
        obs.resize(numDays);
        for(int d = 0; d < numDays; d++) {
           int currDate = Global::getDate(mStartDate, 24*d);
           obs[d] = inputO->getValue(currDate, iInit, iOffset, iLocation.getId(), 0, variables[v]);
        }
        */
        double startTime = Global::clock();

        // Load forecasts
        forecasts[currVar].resize(numDays-mTrainingDays);
        for(int d = mTrainingDays; d < numDays; d++) {
            int currDate = Global::getDate(mStartDate, 24*d);
            std::vector<float> values;
            inputF->getValues(currDate, iInit, iOffset, iLocation.getId(), currVar, values);
            forecasts[currVar][d-mTrainingDays] = Global::mean(values);
        }

        // For each day, find the analog that would have been the best
        std::vector<float> forecastsAtBest;
        forecastsAtBest.resize(numDays-mTrainingDays);
        for(int d = mTrainingDays; d < numDays; d++) {
            int currDate = Global::getDate(mStartDate, 24*d);

            //Global::logger->setDateInfo(currDate, d-mTrainingDays+1, numDays-mTrainingDays);

            std::vector<Field> slices;
            selector.select(currDate, iInit, iOffset, iLocation, mVariable, par, slices);

            // Get the forecasts at these times
            std::vector<float> temp;
            for(int i = 0; i < (int) slices.size(); i++) {
                // Since the observation dataset is used, past dates may be outside the range
                // TODO: This would be a problem since the selector only picks the n best analogs
                // TODO: Hard coded 10
                if(temp.size() < 10) {
                    if(slices[i].getDate() >= mStartDate && slices[i].getDate() <= mEndDate) {
                        float value = inputF->getValue(slices[i].getDate(), slices[i].getInit(),
                                                       slices[i].getOffset(), iLocation.getId(),
                                                       slices[i].getMember().getId(), variables[v]);
                        temp.push_back(value);
                        //if(variables[v] == "CloudCover")
                        //   std::cout << "DATES: " << slices[i].getDate() << " " << value << std::endl;
                    }
                }
            }
            float fcst = Global::mean(temp); // Forecasts at the best obs
            forecastsAtBest[d-mTrainingDays] = fcst;
        }

        // Compute the score
        float corr = Global::corr(forecasts[currVar], forecastsAtBest);
        if(Global::isValid(corr)) {
            float score = -corr;
            std::pair<std::string, float> p(variables[v], score);
            corrs.push_back(p);
            writeScore(variables[v], corr);
        }
        double endTime = Global::clock();
        //std::cout << "Time = " << endTime - startTime << std::endl;
//.........这里部分代码省略.........
开发者ID:WFRT,项目名称:Comps,代码行数:101,代码来源:Find.cpp

示例8: file

void StateBox::parseFile(string filename){
    ifstream file(filename.c_str());
    if(!file){
        cerr << "fichier inexistant" << endl;
    }
    string s;
    //Titre
    getline (file,s);
    //cout << s << endl;
    //saut de ligne
    getline (file,s);
    //cout << s << endl;
    //Sample size:
    getline (file,s);
    //cout << s << endl;
    int sampleSize;
    file >> sampleSize;
    //cout << sampleSize << endl;
    //saut de ligne
    getline (file,s);
    //cout << s << endl;
    double coord;
    int nbData;
    Point p(4);
    vector<Data*> vectData;
    Data* d;
    while(s.compare(0,5,"Order") != 0){
        file >> s;
        //cout << s << endl;
        //getline (file,s);
        if(s.compare(0,9,"NewBranch") == 0){
            file >> nbData;
            //cout << "nbData : " << nbData << endl;
            d = new Data();
            vectData.push_back(d);
            for(int i = 0; i<nbData; i++){
                //x1
                file >> coord;
                //cout << coord << endl;
                p[0] = coord;
                //y1
                file >> coord;
                //cout << coord << endl;
                p[1] = coord;
                //x2
                file >> coord;
                //cout << coord << endl;
                p[2] = coord;
                //y2
                file >> coord;
                //cout << coord << endl;
                p[3] = coord;
                getline (file,s);
                //cout << s << endl;
                d->addData(p);
            }
            d->setMean(Tools::averageMulDimNorm(*d));
            d->setVar(Tools::varianceMulDimNorm(*d,d->getMean()));
            for(int i = 0; i<sampleSize; i++){
                d->addSample(Tools::generateMulDim(d->getMean(),d->getVar()));
            }
        }
    }
开发者ID:floriandrt,项目名称:projetRiver,代码行数:63,代码来源:statebox.cpp

示例9: fill_error_reply

    int Ardb::LSet(Context& ctx, RedisCommandFrame& cmd)
    {
        int64 index;
        if (!GetInt64Value(ctx, cmd.GetArguments()[1], index))
        {
            fill_error_reply(ctx.reply, "value is not an integer or out of range");
            return 0;
        }
        ValueObject meta;
        int err = GetMetaValue(ctx, cmd.GetArguments()[0], LIST_META, meta);
        CHECK_ARDB_RETURN_VALUE(ctx.reply, err);
        if (0 != err)
        {
            fill_error_reply(ctx.reply, "no such key");
            return 0;
        }
        if (meta.meta.Encoding() == COLLECTION_ENCODING_ZIPLIST)
        {
            Data* entry = GetZipEntry(meta.meta.ziplist, index);
            if (NULL == entry)
            {
                fill_error_reply(ctx.reply, "index out of range");
                return 0;
            }
            else
            {
                entry->SetString(cmd.GetArguments()[2], true);
                SetKeyValue(ctx, meta);
                fill_status_reply(ctx.reply, "OK");
                return 0;
            }
        }
        else
        {
            if (index >= meta.meta.Length() || (-index) > meta.meta.Length())
            {
                fill_error_reply(ctx.reply, "index out of range");
                return 0;
            }

            if (meta.meta.IsSequentialList())
            {
                ValueObject list_element;
                list_element.key.db = meta.key.db;
                list_element.key.key = meta.key.key;
                list_element.key.type = LIST_ELEMENT;
                list_element.key.score = meta.meta.min_index;
                if (index >= 0)
                {
                    list_element.key.score.IncrBy(index);
                }
                else
                {
                    list_element.key.score.IncrBy(index + meta.meta.Length());
                }
                if (0 == GetKeyValue(ctx, list_element.key, &list_element))
                {
                    list_element.element.SetString(cmd.GetArguments()[2], true);
                    SetKeyValue(ctx, list_element);
                    fill_status_reply(ctx.reply, "OK");
                    return 0;
                }
            }
            else
            {
                ListIterator iter;
                ListIter(ctx, meta, iter, index < 0);
                int64 cursor = index >= 0 ? 0 : -1;
                while (iter.Valid())
                {
                    if (cursor == index)
                    {
                        ValueObject v;
                        v.key.db = meta.key.db;
                        v.key.key = meta.key.key;
                        v.key.type = LIST_ELEMENT;
                        v.key.score = *(iter.Score());
                        v.type = LIST_ELEMENT;
                        v.element.SetString(cmd.GetArguments()[2], true);
                        SetKeyValue(ctx, v);
                        fill_status_reply(ctx.reply, "OK");
                        return 0;
                    }
                    if (cursor >= 0)
                    {
                        cursor++;
                    }
                    else
                    {
                        cursor--;
                    }
                    if (index < 0)
                    {
                        iter.Prev();
                    }
                    else
                    {
                        iter.Next();
                    }
                }
//.........这里部分代码省略.........
开发者ID:c4pt0r,项目名称:ardb,代码行数:101,代码来源:t_list.cpp

示例10: GetMetaValue

 int Ardb::LRem(Context& ctx, RedisCommandFrame& cmd)
 {
     int64 count;
     if (!GetInt64Value(ctx, cmd.GetArguments()[1], count))
     {
         return 0;
     }
     int64 toremove = std::abs(count);
     ValueObject meta;
     int err = GetMetaValue(ctx, cmd.GetArguments()[0], LIST_META, meta);
     CHECK_ARDB_RETURN_VALUE(ctx.reply, err);
     if (0 != err)
     {
         fill_int_reply(ctx.reply, 0);
         return 0;
     }
     Data element;
     element.SetString(cmd.GetArguments()[2], true);
     KeyLockerGuard lock(m_key_lock, ctx.currentDB, cmd.GetArguments()[0]);
     if (meta.meta.Encoding() == COLLECTION_ENCODING_ZIPLIST)
     {
         uint32 oldlen = meta.meta.ziplist.size();
         int64 removed = 0;
         DataArray newzip;
         if (count >= 0)
         {
             for (uint32 i = 0; i < oldlen; i++)
             {
                 if (meta.meta.ziplist[i] == element)
                 {
                     if (toremove == 0 || removed < toremove)
                     {
                         removed++;
                         continue;
                     }
                 }
                 newzip.push_back(meta.meta.ziplist[i]);
             }
         }
         else
         {
             for (uint32 i = 0; i < oldlen; i++)
             {
                 if (meta.meta.ziplist[oldlen - 1 - i] == element)
                 {
                     if (toremove == 0 || removed < toremove)
                     {
                         removed++;
                         continue;
                     }
                 }
                 newzip.push_front(meta.meta.ziplist[i]);
             }
         }
         if (removed > 0)
         {
             meta.meta.ziplist = newzip;
             SetKeyValue(ctx, meta);
         }
         fill_int_reply(ctx.reply, removed);
         return 0;
     }
     BatchWriteGuard guard(GetKeyValueEngine());
     ListIterator iter;
     ListIter(ctx, meta, iter, count < 0);
     int64 remove = 0;
     while (iter.Valid())
     {
         if (iter.Element()->Compare(element) == 0)
         {
             meta.meta.len--;
             meta.meta.SetFlag(COLLECTION_FLAG_NORMAL);
             KeyObject k;
             k.db = meta.key.db;
             k.key = meta.key.key;
             k.type = LIST_ELEMENT;
             k.score = *(iter.Score());
             DelRaw(ctx, iter.CurrentRawKey());
             //DelKeyValue(ctx, k);
             remove++;
             if (remove == toremove)
             {
                 break;
             }
         }
         if (count < 0)
         {
             iter.Prev();
         }
         else
         {
             iter.Next();
         }
     }
     if (remove > 0)
     {
         SetKeyValue(ctx, meta);
     }
     fill_int_reply(ctx.reply, remove);
     return 0;
//.........这里部分代码省略.........
开发者ID:c4pt0r,项目名称:ardb,代码行数:101,代码来源:t_list.cpp

示例11: fill_int_reply

    int Ardb::ListInsert(Context& ctx, ValueObject& meta, const std::string* match, const std::string& value, bool head,
            bool abort_nonexist)
    {
        if (WakeBlockList(ctx, meta.key.key, value))
        {
            fill_int_reply(ctx.reply, 1);
            return 0;
        }
        if (NULL != match)
        {
            if (meta.meta.Encoding() == COLLECTION_ENCODING_ZIPLIST)
            {
                Data element;
                element.SetString(value, true);
                DataArray::iterator zit = meta.meta.ziplist.begin();
                while (zit != meta.meta.ziplist.end())
                {
                    std::string tmp;
                    zit->GetDecodeString(tmp);
                    if (tmp == *match)
                    {
                        break;
                    }
                    zit++;
                }
                if (zit == meta.meta.ziplist.end())
                {
                    fill_int_reply(ctx.reply, 0);
                    return 0;
                }
                if (head)
                {
                    meta.meta.ziplist.insert(zit, element);
                }
                else
                {
                    zit++;
                    if (zit != meta.meta.ziplist.end())
                    {
                        meta.meta.ziplist.insert(zit, element);
                    }
                    else
                    {
                        meta.meta.ziplist.push_back(element);
                    }
                }
                if (meta.meta.Length() > 1
                        && (meta.meta.Length() >= m_cfg.list_max_ziplist_entries
                                || element.StringLength() >= m_cfg.list_max_ziplist_value))
                {
                    //convert to non ziplist
                    ZipListConvert(ctx, meta);
                }
            }
            else
            {
                ListIterator iter;
                ListIter(ctx, meta, iter, false);
                std::string tmp;
                Data prev, next;
                Data current;
                bool matched = false;
                while (iter.Valid())
                {
                    if (iter.Element()->GetDecodeString(tmp) == (*match))
                    {
                        current = *(iter.Score());
                        matched = true;
                        if (head)
                        {
                            break;
                        }
                    }
                    if (head)
                    {
                        prev = *(iter.Score());
                        iter.Next();
                    }
                    else
                    {
                        if (matched)
                        {
                            next = *(iter.Score());
                            break;
                        }
                    }
                    iter.Next();
                }
                if (!matched)
                {
                    fill_int_reply(ctx.reply, 0);
                    return 0;
                }
                Data score;
                if (head)
                {
                    if (prev.IsNil())
                    {
                        score = current.IncrBy(-1);
                    }
//.........这里部分代码省略.........
开发者ID:c4pt0r,项目名称:ardb,代码行数:101,代码来源:t_list.cpp

示例12: lua_module_register

bool AppDelegate::applicationDidFinishLaunching()
{
    // set default FPS
    Director::getInstance()->setAnimationInterval(1.0f / 60.0f);

    // register lua module
    auto engine = LuaEngine::getInstance();
    ScriptEngineManager::getInstance()->setScriptEngine(engine);
    lua_State* L = engine->getLuaStack()->getLuaState();
    lua_module_register(L);
	LuaRegister::openLibs(L);
	LuaUtil::openLibs(L);
	LuaNetwork::openLibs(L);
	luaopen_bit(L);
	luaopen_cjson(L);
	luaopen_md5_core(L);
	luaopen_lua_timer(L);

	//初始化lua加载函数
	TDLuaMgr::instance();

    register_all_packages();

    LuaStack* stack = engine->getLuaStack();
	stack->setXXTEAKeyAndSign("2dxLua", strlen("2dxLua"), "XXTEA", strlen("XXTEA"));

#ifdef WIN32
	std::string result = "";
	WCHAR buf[1000 + 1];
	int i = 1000;
	GetCurrentDirectory(1000, buf);  //得到当前工作路径
	cocos2d::StringUtils::UTF16ToUTF8((char16_t*)buf, result);
	result = result + "/../../";
	cocos2d::log("add path is %s", result.c_str());
	FileUtils::getInstance()->addSearchPath(result);
	FileUtils::getInstance()->addSearchPath(result + "/src");
	FileUtils::getInstance()->addSearchPath(result + "/res");

	for (auto path : cocos2d::FileUtils::getInstance()->getSearchPaths()) {
		cocos2d::log("search paths is %s", path.c_str());
	}
#endif
	{
		Data data = FileUtils::getInstance()->getDataFromFile("src/config/GlobalConfig.conf");
		ConfigMgr::instance()->initGlobalConfig((const char*)data.getBytes(), data.getSize());
	}
	// 设置脚本宏
	LuaMgrIns->registerLuaGlobalVariable("SERVER_TYPE", "client");
	Json::Value macro = GlobalConfig.get("lua_macros", Json::objectValue);
	for (auto mr : macro.getMemberNames()) {
		LuaMgrIns->registerLuaGlobalVariable(mr.c_str(), macro[mr.c_str()].asCString());
	}
	{
		Data data = FileUtils::getInstance()->getDataFromFile("src/config/protocol.txt");
		NetConfig::instance()->updateMessage((const char*)data.getBytes(), data.getSize());
	}

	//CommandLine::instance()->CreateCmdLine();

	Director::getInstance()->getScheduler()->schedule(std::bind(&AppDelegate::onUpdate, this, 0.1f), (void *)this, 0.1f, false, "onUpdate");


    //register custom function
    //LuaStack* stack = engine->getLuaStack();
    //register_custom_function(stack->getLuaState());

#if (COCOS2D_DEBUG > 0) && (CC_CODE_IDE_DEBUG_SUPPORT > 0)
    // NOTE:Please don't remove this call if you want to debug with Cocos Code IDE
    auto runtimeEngine = RuntimeEngine::getInstance();
    runtimeEngine->addRuntime(RuntimeLuaImpl::create(), kRuntimeEngineLua);
    runtimeEngine->start();
#else
    if (engine->executeScriptFile("src/main.lua"))
    {
        return false;
    }
#endif

    return true;
}
开发者ID:DiaosiDev,项目名称:tdengine_cocos2dx_demo,代码行数:80,代码来源:AppDelegate.cpp

示例13: slice

leveldb::Slice slice(const Data& data)
{
    return leveldb::Slice(
        reinterpret_cast<const char*>(data.data()), data.size());
}
开发者ID:Airbitz,项目名称:libbitcoin,代码行数:5,代码来源:leveldb_common.hpp

示例14:

void Wind::Event::clear() {
	Data* data = static_cast<Data*>(this->pQuantData);
	if (data != NULL) data->clear();
	delete data;
	this->pQuantData = NULL;
}
开发者ID:chenhq,项目名称:q_Wind,代码行数:6,代码来源:WindEvent.cpp

示例15: recreate_height

uint32_t recreate_height(const Data& raw_data)
{
    const uint8_t* start = reinterpret_cast<const uint8_t*>(raw_data.data());
    return from_little_endian<uint32_t>(start);
}
开发者ID:Airbitz,项目名称:libbitcoin,代码行数:5,代码来源:leveldb_common.hpp


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