void CActionHistoric::CRequestEraseNode::redo(IDynamicMapClient *dmc, CScenario &scenario)
{
	//H_AUTO(R2_CRequestEraseNode_redo)
	nlassert(dmc);
	_OldValue = NULL;
	if (scenario.getHighLevel()) // undo allowed ?
	{
		CObject *old = scenario.find(_InstanceId, _AttrName, _Position);
		if (!old)
		{
			nlwarning("Can't redo erase request!!");
			nlassert(0); // TMP TMP
			return;
		}
		if (!old->getNameInParent(_ParentInstanceId, _AttrNameInParent, _PositionInParent))
		{
			nlwarning("Can't retrieve name in parent, requestEraseNode undo will fail!");
		}
		_OldValue = cloneObject(old);

		// modify local version
		scenario.eraseNode(_InstanceId, _AttrName, _Position);
	}
	// send to network
	dmc->doRequestEraseNode(_InstanceId, _AttrName, _Position);
}
コード例 #2
0
ファイル: FloatingObjects.cpp プロジェクト: eocanha/webkit
std::unique_ptr<FloatingObject> FloatingObject::unsafeClone() const
{
    // FIXME: Use make_unique here, once we can get it to compile on all platforms we support.
    std::unique_ptr<FloatingObject> cloneObject(new FloatingObject(renderer(), type(), m_frameRect, m_shouldPaint, m_isDescendant));
    cloneObject->m_paginationStrut = m_paginationStrut;
    cloneObject->m_isPlaced = m_isPlaced;
    return cloneObject;
}
//====================================================================================
CActionHistoric::CRequestSetNode::CRequestSetNode(const std::string &instanceId,
								 const std::string& attrName,
								 CObject* value)
{
	nlassert(value);
	_InstanceId = instanceId;
	_AttrName = attrName;
	_NewValue = cloneObject(value);
}
//====================================================================================
CActionHistoric::CRequestInsertNode::CRequestInsertNode(const std::string& instanceId,
									   const std::string &attrName,
									   sint32 position,
									   const std::string& key,
									   CObject* value)
{
	_InstanceId = instanceId;
	_AttrName = attrName;
	_Position = position;
	_Key = key;
	_Value = cloneObject(value);
}
void CActionHistoric::CRequestInsertNode::redo(IDynamicMapClient *dmc, CScenario &scenario)
{
	//H_AUTO(R2_CRequestInsertNode_redo)
	nlassert(dmc);
	if (scenario.getHighLevel())
	{
		// modify local version
		scenario.insertNode(_InstanceId, _AttrName, _Position, _Key, cloneObject(_Value));
	}
	// send to network
	dmc->doRequestInsertNode(_InstanceId, _AttrName, _Position, _Key, _Value);

	CObject* nodeId = _Value->findAttr("InstanceId");
	CLuaIHM::push(getEditor().getLua(), nodeId->toString());
	getEditor().callEnvMethod("setUndoRedoInstances", 1, 0);
}
void CActionHistoric::CRequestSetNode::redo(IDynamicMapClient *dmc, CScenario &scenario)
{
	//H_AUTO(R2_CRequestSetNode_redo)
	_OldValue = NULL;
	if (scenario.getHighLevel()) // undo allowed ?
	{
		CObject *old = scenario.find(_InstanceId, _AttrName);
		if (old) // may be not found if defined in the base and not redefined yet
		{
			// maybe a shadowed property ?
			/*CObject *shadow = dmc->getPropertyAccessor().getShadowingValue(old);
			if (shadow) old = shadow; // use the shadow instead*/
			_OldValue = cloneObject(old);
			nlwarning("**** backupped value for undo request set node");
			_OldValue->dump();
		}
		// modify local version
		scenario.setNode(_InstanceId, _AttrName, _NewValue);
	}
	// send to network
	dmc->doRequestSetNode(_InstanceId, _AttrName, _NewValue);
}
void CActionHistoric::CRequestEraseNode::undo(IDynamicMapClient *dmc, CScenario &scenario)
{
	//H_AUTO(R2_CRequestEraseNode_undo)
	nlassert(scenario.getHighLevel()); // if this assert fires, then 'clear' was called with a NULL pointer ! The action historic need a start scenario to have undo capability
	nlassert(dmc);
	if (!_OldValue)
	{
		nlwarning("Can't undo erase node, previous node not saved");
		return;
	}
	if (_ParentInstanceId.empty())
	{
		nlwarning("Can't undo erase node, parent name not known");
		return;
	}
	// modify local version
	scenario.insertNode(_ParentInstanceId, _AttrNameInParent, _PositionInParent, "", cloneObject(_OldValue));
	// send to network
	dmc->doRequestInsertNode(_ParentInstanceId, _AttrNameInParent, _PositionInParent, "", _OldValue);
	_OldValue = NULL;

	CLuaIHM::push(getEditor().getLua(), _InstanceId);
	getEditor().callEnvMethod("setUndoRedoInstances", 1, 0);
}
コード例 #8
0
ファイル: d_topicInfo.c プロジェクト: xrl/opensplice_dds
d_topicInfo
d_topicInfoNew(
    d_storeMMFKernel kernel,
    const v_topic vtopic)
{
    d_topicInfo topic;
    c_base base, ddsBase;
    c_type type, srcDataType;
    c_string name;

    if(kernel && vtopic){
        base = c_getBase(kernel);
        ddsBase = c_getBase(vtopic);
        type = c_resolve(base,"durabilityModule2::d_topicInfo");

        if(type){
            topic = c_new(type);
            c_free(type);

            if(topic){
                topic->name = c_stringNew(base, v_entity(vtopic)->name);

                srcDataType = v_topicDataType(vtopic);

                name = c_metaScopedName(c_metaObject(srcDataType));
                topic->typeName = c_stringNew(base, name);
                assert(topic->typeName);
                os_free(name);

                topic->dataType = cloneType(ddsBase, base, srcDataType);
                assert(topic->dataType);

                topic->keyExpr = c_stringNew(base, vtopic->keyExpr);
                assert(topic->keyExpr);

                topic->messageType = messageTypeNew(base, topic->typeName);
                assert(topic->messageType);

                topic->keyType = createTopicKeyType(topic->messageType,
                        topic->keyExpr);
                assert(topic->keyType);

                topic->instanceKeyExpr = createInstanceKeyExpr(base, vtopic);

                topic->sampleType = createSampleType(
                        topic->messageType, topic->name);
                assert(topic->sampleType);

                topic->instanceType = createInstanceType(
                        topic->messageType, topic);
                assert(topic->instanceType);

                topic->qos = cloneObject(ddsBase, base, vtopic->qos);
                assert(topic->qos);
            }
        } else {
            OS_REPORT(OS_ERROR,
                    "d_topicInfoNew",0,
                    "Failed to allocate d_topicInfo.");
            topic = NULL;
        }
    } else {
        OS_REPORT(OS_ERROR,
                "d_topicInfoNew",0,
                "Illegal constructor parameter.");
        topic = NULL;
    }
    return topic;
}
コード例 #9
0
ファイル: hash.c プロジェクト: Alien777/cdnp2psim
static unsigned long int redundancyDemandHashTable(THashTable *hashTable){
	int i;
	int stored;

	unsigned long int demand=0;
	TKeeperHashTable *keeper;
	TCache *cache;
	TListObject *listObjects, *listClones;
	TObject *object, *clone, *walk, *tmp;
	TDataHashTable *data = hashTable->data;

	listClones = createListObject();

	for (i = 0; i < data->size; i++){
		TCollisionHashTable *collision = data->entries[i].head;

		while(collision!=NULL){

			keeper = collision->keepers;

			while (keeper!=NULL){
				TPeer *peer = keeper->peer;
				if (peer->isUp(peer)){
					cache = peer->getCache(peer);
					listObjects = cache->getObjects(cache);
					object = listObjects->getObject(listObjects,keeper->object);
					clone = cloneObject(object);
					listClones->insertOrd(listClones, clone, storedAsCriteriaObject);
				}
				keeper = keeper->next;
			}

			while(!listClones->isEmpty(listClones)){
				object = listClones->getNext(listClones, NULL);
				walk = listClones->getNext(listClones, object);

				stored = getStoredObject(object);
//				demand += stored;

				listClones->removeHead(listClones);

				while(walk!=NULL){
					demand += stored; // add replicated segment
					addStoredObject(walk,-1*stored);
					if (getStoredObject(walk) <= 0){
						tmp = listClones->getNext(listClones, walk);
						listClones->remove(listClones, walk);
						walk = tmp;
					}else{
						walk = listClones->getNext(listClones, walk);
					}
				}
			}

			collision = collision->next;
		}
	}

	listClones->destroy( listClones );

	return demand;
}
コード例 #10
0
ファイル: executor.c プロジェクト: nighca/lang
int calc(Vnode* expr, VM* vm, Contexts* contexts, Method** methods){
	// Already calculated
	if(expr->obj){
		return 0;
	}

	// Variable
	if(expr->name){
		if(strEqual(expr->name, "assign") || strEqual(expr->name, "$") || strEqual(expr->name, "lamda")){
			expr->isMethod = true;
		}else{
			for(int i = 0; methods[i]; i++){
				if(strEqual(expr->name, methods[i]->name)){
					expr->isMethod = true;
					break;
				}
			}
		}

		if(!expr->isMethod){
			expr->obj = findFromContexts(contexts, expr->name);
			assert(expr->obj, "Error: %s not defined!", expr->name);
		}
	}

	// Calculate
	if(expr->childrenNum){
		calc(expr->children[0], vm, contexts, methods);

		Vnode* firstNode = expr->children[0];
		int argNum = expr->childrenNum - 1;

		printf("====================== Calc =======================\n");
		printf("Calc: %s \n", firstNode->name);
		printContexts(contexts);
		printf("End : %s\n", firstNode->name);

		// Native method
		if(firstNode->isMethod){
			if(strEqual(firstNode->name, "assign") || strEqual(firstNode->name, "$")){
				assert(argNum == 2 && expr->children[1]->name, "Error: Wrong arguments for def!");

				char* key = expr->children[1]->name;
				calc(expr->children[2], vm, contexts, methods);
				Object* value = expr->children[2]->obj;
				Context* curr = getTopContext(contexts);

				defineInContext(curr, key, value);
			}else if(strEqual(firstNode->name, "lamda")){
				expr->obj = pushLamda(vm, expr->node);
				expr->obj->lamdaId = lamdaNum;
				lamdaContexts[lamdaNum] = copyContexts(contexts, NULL);
				lamdaNum++;
			}else{
				for(int i = 0; methods[i]; i++){
					if(strEqual(firstNode->name, methods[i]->name)){
						Object** args = malloc(sizeof(Object*) * argNum);
						for(int i = 0; i < argNum; i++){
							calc(expr->children[i+1], vm, contexts, methods);
							args[i] = cloneObject(vm, expr->children[i+1]->obj);
						}
						expr->obj = methods[i]->callee(argNum, args, vm);
						break;
					}
				}
			}
			return 0;
		}

		Object* firstVal = firstNode->obj;

		// First value
		if(firstVal->type != OBJ_LAMDA){
			expr->obj = cloneObject(vm, firstVal);
			return 0;
		}

		// Lamda call
		// get args
		Contexts* cxts = copyContexts(lamdaContexts[firstVal->lamdaId], NULL);
		Context* runCxt = newContext();
		for(int i = 0; i < argNum; i++){
			calc(expr->children[i+1], vm, contexts, methods);
			defineInContext(runCxt, firstVal->args[i], cloneObject(vm, expr->children[i+1]->obj));
		}
		pushContext(cxts, runCxt);
		Vnode* vn = getVnode(firstVal->grammarTree->root, vm);
		calc(vn, vm, cxts, methods);
		expr->obj = vn->obj;

		return 0;
	}

	return 0;
}