Ejemplo n.º 1
0
 char* _spUtil_readFile(const char* path, int* length)
 {
     const DataMap data{Path(path)};
     *length = static_cast<int>(data.size());
     char* blob = new char[data.size()];
     memcpy(blob, data.data(), data.size());
     return blob;
 }
Ejemplo n.º 2
0
void SignalListPresenter::OnNewData(const DataMap& dataMap)
{
	OnClearData();
	auto currentCount = signalList->rowCount();
	signalList->setRowCount(currentCount + dataMap.size());

	for (const auto& sign : dataMap)
	{
		const auto& name = sign.first;
		const auto& currentSignal = sign.second;
		// name item
		auto chanNameItem = new QTableWidgetItem(name);
		chanNameItem->setCheckState(currentSignal.graphic.visible ? Qt::Checked : Qt::Unchecked);
		// domain value item
		auto chanValueItem = new QTableWidgetItem();
		chanValueItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
		// color item
		auto colorButton = new QPushButton(signalList);
		colorButton->setEnabled(currentSignal.graphic.visible);
		colorButton->setStyleSheet(MakeBackgroundStylesheet(currentSignal.graphic.color));
		colorButton->setAutoFillBackground(true);
		const auto& currColor = currentSignal.graphic.color;
		QObject::connect(colorButton, &QPushButton::clicked, [&currColor, name, colorButton, this]{
			const auto color = QColorDialog::getColor(currColor, this->signalList, QString("Change color of %1").arg(name));
			if (color.isValid())
			{
				this->data.setColor(name, color);
			}
		});
		
		auto removeButton = new QPushButton(signalList);
		removeButton->setText("X");
		QObject::connect(removeButton, &QPushButton::clicked, [name, this]{
			const auto reply = QMessageBox::question(nullptr, "Anvedi", QString("Sure to remove '%1'?").arg(name), QMessageBox::Yes | QMessageBox::No);
			if (reply == QMessageBox::Yes)
			{
				this->data.remove(name);
			}
		});

		// adding them all
		signalList->setItem(currentCount, SignalNameIdx, chanNameItem);
		signalList->setItem(currentCount, SignalValueAtDomainIdx, chanValueItem);
		signalList->setCellWidget(currentCount, SignalColorIdx, colorButton);
		signalList->setCellWidget(currentCount, SignalRemoveIdx, removeButton);

		currentCount++;
	}

	if (auto domain = data.getDomain())
	{
		OnDomainChanged(*domain);
	}

	OnSignalFilterEdited(filterEdit->text());
}
Ejemplo n.º 3
0
int main(int argc, char* argv[]) {
  if (argc < 3) {
    std::cout << "Usage: TestTripodSearchGet logPath userId1 [userId2, ...]" << std::endl;
    return 1;
  }
  ostringstream oss;
  com::xiaonei::xce::ConnectionPoolManager::instance();
  oss << argv[1] << "/TripodSearchGet.log";
  std::vector<std::string> keys;
  std::vector<std::string> missedKeys;
  std::string logPath = oss.str();
  MyUtil::init_logger("Mce", logPath, "DEBUG");
  for (int i = 2; i < argc; i++) {
    std::string userId = boost::lexical_cast<std::string>(argv[i]);
    MCE_WARN("logPath:" << logPath << " userId:" << userId);
    keys.push_back(userId);
  }
  TripodClient* testClient = new TripodClient("UserZooKeeper1:2181,UserZooKeeper2:2181,UserZooKeeper3:2181,UserZooKeeper4:2181,UserZooKeeper5:2181/Tripod", "ne0", "SearchCache"); 
  DataMap result;
  try {
    result = testClient->get(keys, missedKeys);
  } catch (Ice::Exception& e) {
    MCE_ERROR("get Error :" << e.what());
  }
  MCE_WARN("result.size:" << result.size());
  for (std::map<std::string, Data>::iterator it = result.begin(); it != result.end(); it++) {
    MCE_WARN("result key:" << it->first);
    TripodCacheDataPtr tmp = new TripodCacheData;
    string dataStr((it->second).begin(), (it->second).end());
    tmp->ParseFromString(dataStr);
    show(it->first, tmp);
    std::cout << "---------------------------------------" <<  std::endl;
  }
  std::cout << "result.size:" << result.size() << std::endl;
  delete testClient;
  return 0;

}
Ejemplo n.º 4
0
/*
*Function:
*Inputs:noneSeekMaxMinTimeLine
*Outputs:none
*Returns:none
*/
void Graph::SeekMaxMinTimeLine(DataMap &l)  // seek max and min in a line
{
	IT_IT("Graph::SeekMaxMinTimeLine");
	
	if(l.size() > 0)
	{  
		if(minTime > (*l.begin()).first)
		{
			minTime = (*l.begin()).first;
		}; 
		if(maxTime < (*l.rbegin()).first)
		{
			maxTime = (*l.rbegin()).first;
		};
	}; 
};
Ejemplo n.º 5
0
Archivo: t_hash.cpp Proyecto: cvan/ardb
OP_NAMESPACE_BEGIN

    int Ardb::HashMultiSet(Context& ctx, ValueObject& meta, DataMap& fs)
    {
        if (meta.meta.encoding != COLLECTION_ECODING_ZIPMAP)
        {
            bool multi_write = fs.size() > 1;
            bool set_meta = meta.meta.len != -1;

            if (meta.meta.Length() > 0)
            {
                multi_write = true;
            }
            BatchWriteGuard guard(GetKeyValueEngine(), multi_write);
            DataMap::iterator it = fs.begin();
            while (it != fs.end())
            {
                ValueObject v(HASH_FIELD);
                v.element = it->second;
                v.key.type = HASH_FIELD;
                v.key.db = meta.key.db;
                v.key.key = meta.key.key;
                v.key.element = it->first;
                SetKeyValue(ctx, v);
                it++;
            }
            if (set_meta)
            {
                meta.meta.len = -1;
                SetKeyValue(ctx, meta);
            }
            fill_int_reply(ctx.reply, fs.size());
        }
        else
        {
            int64 oldlen = meta.meta.Length();
            DataMap::iterator it = fs.begin();
            bool zipsave = true;
            while (it != fs.end())
            {
                const Data& field = it->first;
                Data& value = it->second;
                meta.meta.zipmap[field] = value;
                it++;
                if (!meta.attach.force_zipsave
                        && (field.StringLength() > m_cfg.hash_max_ziplist_value
                                || value.StringLength() > m_cfg.hash_max_ziplist_value))
                {
                    zipsave = false;
                }
            }
            if (meta.meta.zipmap.size() > m_cfg.hash_max_ziplist_entries)
            {
                zipsave = false;
            }
            BatchWriteGuard guard(GetKeyValueEngine(), !zipsave);
            if (!zipsave)
            {
                /*
                 * convert to non zipmap encoding
                 */
                DataMap::iterator fit = meta.meta.zipmap.begin();
                while (fit != meta.meta.zipmap.end())
                {
                    ValueObject v(HASH_FIELD);
                    v.element = fit->second;
                    v.key.type = HASH_FIELD;
                    v.key.db = meta.key.db;
                    v.key.key = meta.key.key;
                    v.key.element = fit->first;
                    SetKeyValue(ctx, v);
                    fit++;
                }
                meta.meta.len = meta.meta.zipmap.size();
                meta.meta.zipmap.clear();
                meta.meta.encoding = COLLECTION_ECODING_RAW;
            }
            SetKeyValue(ctx, meta);
            fill_int_reply(ctx.reply, meta.meta.Length() - oldlen);
        }

        return 0;
    }