nsresult
nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix,
                               PRInt32 aNamespaceID, nsINodeInfo** aNodeInfo)
{
  NS_ASSERTION(!aName.IsEmpty(),
               "Don't pass an empty string to GetNodeInfo, fix caller.");

  nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID);

  void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);

  if (node) {
    nsINodeInfo* nodeInfo = static_cast<nsINodeInfo *>(node);

    NS_ADDREF(*aNodeInfo = nodeInfo);

    return NS_OK;
  }

  nsRefPtr<nsNodeInfo> newNodeInfo = nsNodeInfo::Create();
  NS_ENSURE_TRUE(newNodeInfo, nsnull);
  
  nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName);
  nsresult rv = newNodeInfo->Init(nameAtom, aPrefix, aNamespaceID, this);
  NS_ENSURE_SUCCESS(rv, rv);

  PLHashEntry *he;
  he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
  NS_ENSURE_TRUE(he, NS_ERROR_FAILURE);

  newNodeInfo.forget(aNodeInfo);

  return NS_OK;
}
already_AddRefed<nsINodeInfo>
nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
                               PRInt32 aNamespaceID)
{
  NS_ENSURE_TRUE(aName, nsnull);
  NS_ASSERTION(!aName->Equals(EmptyString()),
               "Don't pass an empty string to GetNodeInfo, fix caller.");

  nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID);

  void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);

  if (node) {
    nsINodeInfo* nodeInfo = static_cast<nsINodeInfo *>(node);

    NS_ADDREF(nodeInfo);

    return nodeInfo;
  }

  nsRefPtr<nsNodeInfo> newNodeInfo = nsNodeInfo::Create();
  NS_ENSURE_TRUE(newNodeInfo, nsnull);
  
  nsresult rv = newNodeInfo->Init(aName, aPrefix, aNamespaceID, this);
  NS_ENSURE_SUCCESS(rv, nsnull);

  PLHashEntry *he;
  he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
  NS_ENSURE_TRUE(he, nsnull);

  nsNodeInfo *nodeInfo = nsnull;
  newNodeInfo.swap(nodeInfo);

  return nodeInfo;
}
예제 #3
0
IMultiLevelStore *MultiLevelStore::getLevel(const char *key, unsigned int numElm) const{
	if(!key) throw MaudioException("key doesn't exist");
	std::string tmpKey(key);
	if(mLevels.find(tmpKey) == mLevels.end()) throw MaudioException("key doesn't exist");
	auto iter = mLevels.lower_bound(tmpKey);
	auto iterUp = mLevels.upper_bound(tmpKey);
	while(iter != iterUp && numElm != 0){
		iter++;
		numElm--;
	}
	if(numElm != 0) throw MaudioException("numElm out of range");
	return iter->second.get();
}
void CBookKeyChooser::setupCombo(const QString key, const int depth, const int currentItem) {
    CKeyChooserWidget* chooserWidget = m_chooserWidgets.at(depth);

    CSwordTreeKey tmpKey(*m_key);
    tmpKey.key(key);
    tmpKey.parent();
    tmpKey.firstChild();

    QStringList items;
    if (depth > 0) items << QString::null; //insert an empty item at the top

    do {
        items << tmpKey.getLocalNameUnicode();
    }
    while (tmpKey.nextSibling());

    if (chooserWidget) chooserWidget->reset(items, currentItem, false);
}
예제 #5
0
// set property value at a specific time position
GError GProperty::SetValue(const GKeyValue& InputValue, const GTimeValue TimePos, const GValueMethod SetMethod) {

	if (InputValue.KeyType() != HandledType())
		return G_INVALID_PARAMETER;

	GKeyValue tmpKey(InputValue);
	tmpKey.SetTimePosition(TimePos);

	// apply ease (time curve)
	if (gApplyEase && gEaseProperty) {

		GKeyValue easeValue;

		GTimeInterval easeValid = G_FOREVER_TIMEINTERVAL;
		GError err = gEaseProperty->Value(easeValue, easeValid, TimePos, G_ABSOLUTE_VALUE);
		if (err != G_NO_ERROR)
			return err;
		tmpKey.SetTimePosition(easeValue.RealValue());
	}
	return DoSetValue(tmpKey, tmpKey.TimePosition(), SetMethod);
}
예제 #6
0
const SkirmishAIKey* CSkirmishAIHandler::GetLocalSkirmishAILibraryKey(const size_t skirmishAIId) {

	const SkirmishAIKey* key = NULL;

	// fail, if the specified AI is not a local one
	assert(CSkirmishAIHandler::IsLocalSkirmishAI(skirmishAIId));

	id_libKey_t::const_iterator libKey = id_libKey.find(skirmishAIId);
	if (libKey != id_libKey.end()) {
		// already resolved
		key = &(libKey->second);
	} else {
		// resolve it
		const SkirmishAIData* aiData = GetSkirmishAI(skirmishAIId);
		SkirmishAIKey tmpKey(aiData->shortName, aiData->version);
		const SkirmishAIKey& resKey = aiLibManager->ResolveSkirmishAIKey(tmpKey);
		assert(!resKey.IsUnspecified());
		id_libKey[skirmishAIId] = resKey;
		key = &(id_libKey[skirmishAIId]);
	}

	return key;
}
예제 #7
0
	/* static */
	D3DatabasePermissionPtr D3DatabasePermissionBase::Load(DatabasePtr pDB, long lRoleID, long lMetaDatabaseID, bool bRefresh, bool bLazyFetch)
	{
		DatabasePtr		pDatabase = pDB;


		if (!pDatabase)
			return NULL;

		if (pDatabase->GetMetaDatabase() != MetaDatabase::GetMetaDatabase("D3MDDB"))
			pDatabase = pDatabase->GetDatabaseWorkspace()->GetDatabase(MetaDatabase::GetMetaDatabase("D3MDDB"));

		if (!pDatabase)
			return NULL;

		TemporaryKey	tmpKey(*(pDatabase->GetMetaDatabase()->GetMetaEntity(D3MDDB_D3DatabasePermission)->GetPrimaryMetaKey()));

		// Set all key column values
		//
		tmpKey.GetColumn(D3MDDB_D3DatabasePermission_RoleID)->SetValue(lRoleID);
		tmpKey.GetColumn(D3MDDB_D3DatabasePermission_MetaDatabaseID)->SetValue(lMetaDatabaseID);

		return (D3DatabasePermissionPtr) pDatabase->GetMetaDatabase()->GetMetaEntity(D3MDDB_D3DatabasePermission)->GetPrimaryMetaKey()->LoadObject(&tmpKey, pDatabase, bRefresh, bLazyFetch);
	}
nsresult
nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix,
                               PRInt32 aNamespaceID, nsINodeInfo** aNodeInfo)
{
  NS_ENSURE_ARG_POINTER(aName);
  NS_ASSERTION(!aName->Equals(EmptyString()),
               "Don't pass an empty string to GetNodeInfo, fix caller.");

  nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID);

  void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey);

  if (node) {
    *aNodeInfo = static_cast<nsINodeInfo *>(node);

    NS_ADDREF(*aNodeInfo);

    return NS_OK;
  }

  nsNodeInfo *newNodeInfo = nsNodeInfo::Create();
  NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY);

  NS_ADDREF(newNodeInfo);

  nsresult rv = newNodeInfo->Init(aName, aPrefix, aNamespaceID, this);
  NS_ENSURE_SUCCESS(rv, rv);

  PLHashEntry *he;
  he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo);
  NS_ENSURE_TRUE(he, NS_ERROR_OUT_OF_MEMORY);

  *aNodeInfo = newNodeInfo;

  return NS_OK;
}
RddResultCode TopNAction::action(ActionContext* ctx, const BaseRddPartition* input) {
  TopNActionRequest request;
  if (!ctx->getActionParam(ACTION_PARAM, &request)) {
    LOG(ERROR)<< input->getPartitionName() << " parse top N expression error";
    return RRC_INVALID_ACTION_PARAM;
  }

  int32_t fieldSize = request.order_field_size();
  vector<FieldInfo> fields;
  vector<bool> fieldDesc;
  fields.resize(fieldSize);
  fieldDesc.resize(fieldSize);
  string typeName = input->getRddName();
  for (int32_t i = 0; i < fieldSize; ++ i) {
    auto& field = request.order_field(i);
    auto rc = ExpressionFactory::build(&fields[i].expr, field.expr(), ctx->getKeyTemplate(), ctx->getValueTemplate());
    if (idgs::RC_SUCCESS != rc) {
      LOG(ERROR)<< input->getPartitionName() << " parsed filter expression error, caused by " << idgs::getErrorDescription(rc);
      return RRC_NOT_SUPPORT;
    }

    if (field.has_field_name()) {
      fields[i].name = field.field_name();
    } else if (field.expr().name() == "FIELD") {
      fields[i].name = field.expr().value();
    } else {
      fields[i].name = "column" + to_string(i);
    }

    if (field.has_field_type()) {
      fields[i].type = field.field_type();
    } else if (field.expr().name() == "FIELD") {
      FieldExtractor* fieldExt = dynamic_cast<FieldExtractor*>(fields[i].expr);
      auto fldType = fieldExt->getFieldType();
      fields[i].type = static_cast<idgs::pb::DataType>(fldType);
    } else {
      fields[i].type = idgs::pb::STRING;
    }

    fieldDesc[i] = field.desc();
    typeName.append("_").append(fields[i].name);
  }

  string fullTypeName = "idgs.rdd.pb." + typeName;

  auto helper = idgs_rdd_module()->getMessageHelper();
  if (!helper->isMessageRegistered(fullTypeName)) {
    std::lock_guard<std::mutex> lockGuard(lock);
    if (!helper->isMessageRegistered(fullTypeName)) {
      registerTempKeyMessage(input->getPartition(), typeName, fields);
    }
  }

  if (input->empty()) {
    return RRC_SUCCESS;
  }

  PbMessagePtr tmpKeyTemp = helper->createMessage(fullTypeName);
  if (!tmpKeyTemp) {
    LOG(ERROR)<< "RDD \"" << input->getRddName() << "\" partition[" << input->getPartition() << "] generate dynamic key error.";
    return RRC_INVALID_KEY;
  }

  orderless compare(fieldDesc);
  multimap<PbMessagePtr, KeyValueMessagePair, orderless> tmpMap(compare);
  auto tmpDescriptor = tmpKeyTemp->GetDescriptor();

  uint64_t start = 1, dataSize = 0;
  bool hasTop = request.has_top_n();
  if (request.has_start()) {
    start = request.start();
  }

  if (request.has_top_n()) {
    auto topN = request.top_n();
    dataSize = topN + start - 1;
  }

  input->foreach(
    [&ctx, &tmpMap, fields, tmpKeyTemp, tmpDescriptor, dataSize, hasTop, helper]
     (const PbMessagePtr& key, const PbMessagePtr& value) {
      ctx->setKeyValue(&key, &value);
      if (!ctx->evaluateFilterExpr()) {
        return;
      }

      PbMessagePtr tmpKey(tmpKeyTemp->New());
      for (int32_t i = 0; i < tmpDescriptor->field_count(); ++ i) {
        auto field = tmpDescriptor->field(i);
        PbVariant var = fields[i].expr->evaluate(ctx->getExpressionContext());
        helper->setMessageValue(tmpKey.get(), field, var);
      }

      KeyValueMessagePair pair;
      pair.key = &key;
      pair.value = &value;

      tmpMap.insert(std::pair<PbMessagePtr, KeyValueMessagePair>(tmpKey, pair));

      if (hasTop && tmpMap.size() > dataSize) {
        auto itTmp = tmpMap.end();
        -- itTmp;
        tmpMap.erase(itTmp);
      }
    });

  if (!tmpMap.empty()) {
    TopNActionData data;
    data.set_key_name(fullTypeName);

    auto serdesMode = ctx->getSerdesMode();
    auto itfst = tmpMap.begin();
    auto itlst = tmpMap.end();
    for (; itfst != itlst; ++ itfst) {
      auto pair = data.add_data();
      ProtoSerdesHelper::serialize(serdesMode, itfst->first.get(), pair->mutable_key());
      ProtoSerdesHelper::serialize(serdesMode, itfst->second.key->get(), pair->mutable_pair()->mutable_key());
      ProtoSerdesHelper::serialize(serdesMode, itfst->second.value->get(), pair->mutable_pair()->mutable_value());
    }

    string var;
    ProtoSerdesHelper::serialize(serdesMode, &data, &var);
    ctx->addPartitionResult(var);
  }
  return RRC_SUCCESS;
}
예제 #10
0
IMultiLevelStore *MultiLevelStore::addLevel(const char *key){
	std::string tmpKey(key);
	MultiLevelStore *ret = new MultiLevelStore();
	mLevels.insert(std::make_pair(tmpKey, std::unique_ptr<MultiLevelStore>(ret)));
	return ret;
}
예제 #11
0
void MultiLevelStore::add(const char *key, const char *value){
	std::string tmpKey(key);
	if(!checkKey(tmpKey)) return;
	mData.insert(std::make_pair(tmpKey, std::string(value)));
	return;
}