Exemplo n.º 1
0
bool OperCFThread::Copy(FS *srcFs, FSPath &__srcPath, FSList *list, FS *destFs, FSPath &__destPath, cstrhash<bool,unicode_t> &resList)
{
	if (list->Count()<=0) return true;
	
	FSPath srcPath = __srcPath; int srcPos = srcPath.Count();
	FSPath destPath = __destPath; int destPos = destPath.Count();
			
	FSStat st;
	int ret_error;
	int res = destFs->Stat(__destPath, &st, &ret_error, Info());
	if (res == -2) return false;
	
	if (res && !destFs->IsENOENT(ret_error))
	{
		RedMessage( _LT("Can't copy to:\n"), destFs->Uri(destPath).GetUtf8(), bOk, destFs->StrError(ret_error).GetUtf8());
		return false;
	}
	
	bool exist = (res == 0);
	
	
	if (list->Count()>1)
	{
		//если файлов >1 то копировать можно только в каталог
		if (!exist) {
			RedMessage( _LT("Can't copy files, destination is not found:\n"), destFs->Uri(__destPath).GetUtf8(), bOk);
			return false;
		}
	
		if (!st.IsDir()) 
		{
			RedMessage( _LT("Destination is not directory:\n"), destFs->Uri(__destPath).GetUtf8(), bOk);
			return false;
		}
				
		for (FSNode *node = list->First(); node; node = node->next)
		{
			if (Info()->Stopped()) return false;
			
			srcPath.SetItemStr(srcPos, node->Name());
			destPath.SetItemStr(destPos, node->Name());
			
			if (!CopyNode(srcFs, srcPath, node, destFs, destPath, false)) return false;
			resList[node->Name().GetUnicode()] = true;
		}
	} else {
		// 1 element

		if (exist && st.IsDir())
			destPath.SetItemStr(destPos, list->First()->Name());
		
		srcPath.SetItemStr(srcPos, list->First()->Name());
		
		if (!CopyNode(srcFs, srcPath, list->First(), destFs, destPath, false)) return false;
		resList[list->First()->Name().GetUnicode()] = true;
	};
		
	return true;
}
Exemplo n.º 2
0
// only copy a complete independent tree
// when node name exists
void ComputationNetwork::CopySubTree(const ComputationNetwork& fromNet,
                                     const std::wstring fromName, std::wstring toNamePrefix,
                                     const CopyNodeFlags flags)
{
    InvalidateCompiledNetwork();

    if (!(flags & CopyNodeFlags::copyNodeValue))
        LogicError("CopySubTree: you cannot copy a tree without copying the node values.");

    ComputationNodeBasePtr fromRoot = fromNet.GetNodeFromName(fromName);

    if (!fromNet.EvalOrderExists(fromRoot))
        const_cast<ComputationNetwork&>(fromNet).FormEvalOrder(fromRoot);

    for (const auto& fromNode : fromNet.GetEvalOrder(fromRoot)) // BUGBUG: This probably will fail because the precomputed eval orders are invalid at this point.
    {
        wstring fromNodeName = fromNode->NodeName();
        wstring toNodeName = toNamePrefix + fromNodeName;

        ComputationNodeBasePtr toNode = CopyNode(fromNet, fromNodeName,
                                                 toNodeName,
                                                 CopyNodeFlags::copyNodeValue);

        if (flags & CopyNodeFlags::copyNodeInputLinks)
        {
            // copy the children structure but use the new nodes generated
            for (int i = 0; i < fromNode->GetNumInputs(); i++)
                toNode->SetInput(i, GetNodeFromName(toNamePrefix + fromNode->GetInputs()[i]->NodeName()));
        }
    }
}
Exemplo n.º 3
0
// only copy a complete independent tree
// when node name exists
void ComputationNetwork::CopySubTree(const ComputationNetwork& fromNet,
                                     const std::wstring fromName, std::wstring toNamePrefix,
                                     const CopyNodeFlags flags)
{
    InvalidateCompiledNetwork();

    if (!(flags & CopyNodeFlags::copyNodeValue))
        LogicError("CopySubTree: you cannot copy a tree without copying the node values.");

    ComputationNodeBasePtr fromRoot = fromNet.GetNodeFromName(fromName);

    for (const auto& fromNode : GetEvalOrder(fromRoot))
    {
        wstring fromNodeName = fromNode->NodeName();
        wstring toNodeName = toNamePrefix + fromNodeName;

        ComputationNodeBasePtr toNode = CopyNode(fromNet, fromNodeName,
                                                 toNodeName,
                                                 CopyNodeFlags::copyNodeValue);

        if (flags & CopyNodeFlags::copyNodeChildren)
        {
            // copy the children structure but use the new nodes generated
            for (int i = 0; i < fromNode->GetNumInputs(); i++)
                toNode->SetInput(i, GetNodeFromName(toNamePrefix + fromNode->GetInputs()[i]->NodeName()));
        }
    }
}
Exemplo n.º 4
0
void Factory::AddNode(GroupNode *pParent, SceneNode *pChild)
{
  DbgEnter();
  if (pParent && pChild)
  {
    pParent->AddNode(CopyNode(pChild));
  }
}
Exemplo n.º 5
0
Arquivo: dom4c.c Projeto: vhly/cstudy
NodeList FindNodesByName(Node *parent, char type, char *name)
{
    NodeList ret = NULL;
    NodeList head = NULL;
    
    if (parent != NULL && name != NULL) {
        switch (type) {
            case NODE_TYPE_NODE:
            case NODE_TYPE_ELEMENT:
            case NODE_TYPE_ATTRIBUTE:
            case NODE_TYPE_TEXT:
            {
                Node *cur = parent->children;
                while (cur != NULL) {
                    if (cur->nodeType == type) {
                        int cmp = strcmp(cur->nodeName, name);
                        if (cmp == 0) {
                            if (ret == NULL) {
                                ret = CopyNode(cur);
                                head = ret;
                            }else{
                                Node *tmp = CopyNode(cur);
                                ret->nextSub = tmp;
                                tmp->prevSub = ret;
                                ret = tmp;
                            }
                        }
                    }
                    if (cur->nextSub != NULL) {
                        cur = cur->nextSub;
                    } else {
                        break;
                    }
                }
            }
                break;
                
            default:
                break;
        }
    }
    
    return head;
}
Exemplo n.º 6
0
void AdjacencyList::CopyFrom(const AdjacencyList &adjacencyList) {
  if (this == &adjacencyList) return;
  for (Index i = 0; i < numVertices_; ++i) {
    RemoveNode(list_[i]);
  }
  delete [] list_;
  numVertices_ = adjacencyList.numVertices_;
  numEdges_ = adjacencyList.numEdges_;
  list_ = new ListNode * [numVertices_];
  for (Index i = 0; i < numVertices_; ++i) {
    list_[i] = CopyNode(list_[i], adjacencyList.list_[i]);
  }
}
Exemplo n.º 7
0
bool OperCFThread::CopyDir(FS *srcFs, FSPath &__srcPath, FSNode *srcNode, FS *destFs, FSPath &__destPath, bool move)
{
	if (Info()->Stopped()) return false;

	FSList list;
	
	int ret_error;
	
	while (true) {
		int ret = srcFs->ReadDir(&list, __srcPath, &ret_error, Info());
		if (ret == -2) return false;
		if (!ret) break;

		switch ( RedMessage( _LT("Can`t open directory:\n") , srcFs->Uri(__srcPath).GetUtf8(), bRetrySkipCancel, srcFs->StrError(ret_error).GetUtf8()) ) {
		case CMD_SKIP: return true;
		case CMD_RETRY: continue;
		default: return false;
		}
	}
	
	while (destFs->MkDir(__destPath, MkDirMode, &ret_error, Info()) && !destFs->IsEEXIST(ret_error)) {
		switch (RedMessage( _LT("Can't create the directory:\n"), destFs->Uri(__destPath).GetUtf8(), bRetrySkipCancel, destFs->StrError(ret_error).GetUtf8())) {
		case CMD_CANCEL: return false;
		case CMD_SKIP: return true;
		}
	}
		
	
	FSPath srcPath = __srcPath; int srcPos = srcPath.Count();
	FSPath destPath = __destPath; int destPos = destPath.Count();
	
		
	for (FSNode *node = list.First(); node; node = node->next) 
	{
		if (Info()->Stopped()) return false;
		
		srcPath.SetItemStr(srcPos, node->Name());
		destPath.SetItemStr(destPos, node->Name());
		
		if (!CopyNode(srcFs, srcPath, node, destFs, destPath, move)) return false; 
	}

	destFs->SetFileTime(destPath, srcNode->st.mtime, srcNode->st.mtime, 0, Info());

	return !move || RmDir(srcFs, __srcPath);
}
Exemplo n.º 8
0
//========================================================
// Name   : _CopyBranch
// Desc   : recursive internal copy branch 
// Param  :
// Return : 
//--------------------------------------------------------
// Coder    Date                      Desc
// bro      2002-10-29
//========================================================
void _tagXMLNode::_CopyBranch( LPXNode node )
{
	CopyNode( node );

	for( unsigned int i = 0 ; i < node->childs.size(); i++)
	{
		LPXNode child = node->childs[i];
		if( child )
		{
			LPXNode mychild = new XNode;
			mychild->CopyNode( child );
			AppendChild( mychild );

			mychild->_CopyBranch( child );
		}
	}
}
Exemplo n.º 9
0
SceneNode *Factory::CopyNode(SceneNode *pNode)
{
  DbgEnter();
  //check if node already belongs to some parent
  if (pNode && pNode->GetCount() > 0)
  {
    GroupNode *pGroup = dynamic_cast<GroupNode *>(pNode);
    if (pGroup)
    {
      //save list of child nodes
      SceneNodeList &nodes = pGroup->GetNodeList();
      //create new group node
      pGroup = NewObject<GroupNode>();
      //add copies of all child nodes to new group node
      for (SceneNodeList::iterator it = nodes.begin(); it != nodes.end(); it++)
      {
        pGroup->AddNode(CopyNode(*it));
      }
      return pGroup;
    }
  }
  //return original node
  return pNode;
}
Exemplo n.º 10
0
// you can only copy inputs from nodes in the same network
void ComputationNetwork::CopyInputs(const std::wstring fromName, std::wstring toName)
{
    CopyNode(*this, fromName, toName, CopyNodeFlags::copyNodeChildren);
}
Exemplo n.º 11
0
HRESULT CKADmerge::Merge(string sAddOnFileName, BOOL bOverwrite, string sLogFile)
{
    HRESULT hRes = 0;

	IXMLDOMDocument * pXMLAddOn = NULL;

    if(sLogFile != "")
    {
        // open log file
        OpenLog(sLogFile, sDescription + " " + m_sFileName + " with " + sAddOnFileName);
    }

    try
	{
        // load AddOn file
        hRes = LoadXMLFile(sAddOnFileName, &pXMLAddOn);

        IXMLDOMElement * pKadRoot = NULL;
        hRes = GetRootElement(m_pXMLKad, &pKadRoot);
        if(hRes == S_FALSE)
        {
            // create root element
            hRes = GetRootElement(pXMLAddOn, &pKadRoot);
            if(hRes == S_FALSE)
            {
                throw string("ERROR: could not get addon kad root element: " + sAddOnFileName);
            }

            _bstr_t bTagName(GetName(pKadRoot).c_str());
            hRes = m_pXMLKad->createElement(bTagName, &pKadRoot);
            hRes = m_pXMLKad->putref_documentElement(pKadRoot);

            // log changes
            Log("Create Root-Element: " + GetName(pKadRoot) );

            m_bIsDirty = TRUE;
        }

        if(pKadRoot)
            pKadRoot->Release();

	    IXMLDOMNode * pXMLKadNode = NULL;
	    IXMLDOMNode * pXMLAddOnNode = NULL;

        hRes = GetRootElement(m_pXMLKad, &pXMLKadNode);
        hRes = GetRootElement(pXMLAddOn, &pXMLAddOnNode);

        // copy nodes
        hRes = CopyNode(&pXMLKadNode, &pXMLAddOnNode, bOverwrite, "");

	    if(pXMLKadNode != NULL)
		    pXMLKadNode->Release();
	    if(pXMLAddOnNode != NULL)
		    pXMLAddOnNode->Release();

        if(m_bIsDirty)
        {
            hRes = SaveXMLFile(m_sFileName, m_pXMLKad);
            m_bIsDirty = FALSE;
        }
	}
	catch(string str)
	{
        Log(str);
        hRes = S_FALSE;
	}

	if(pXMLAddOn != NULL)
		pXMLAddOn->Release();

    // close log file
    CloseLog();

    return hRes;
}
Exemplo n.º 12
0
HRESULT CKADmerge::CopyNode(IXMLDOMNode ** pXMLDest, IXMLDOMNode ** pXMLSrc, BOOL bOverwrite, string sPath)
{
    HRESULT hRes = 0;

    IXMLDOMNodeList * pNodeList = NULL;

    if(*pXMLDest == NULL || *pXMLSrc == NULL)
    {
        Log("ERROR: CopyNode " + GetName(*pXMLSrc) + " to " + GetName(*pXMLDest));
        hRes = S_FALSE;
        return hRes;
    }

    hRes = (*pXMLSrc)->get_childNodes(&pNodeList);

    if(SUCCEEDED(hRes))
    {
        LONG lListLength = 0;
        hRes = pNodeList->get_length(&lListLength);

        IXMLDOMNode * pCurrentNode = NULL;
        hRes = pNodeList->nextNode(&pCurrentNode);

        while(pCurrentNode != NULL)
        {
            // iterate through the xml tree
            string sPatternString = GetPatternString(pCurrentNode, TRUE);

            IXMLDOMNode * pDestNode = NULL;
            BOOL bHasNode = HasNode(*pXMLDest, sPatternString, &pDestNode);
            if(bHasNode && (!m_Overwriteable[GetName(pCurrentNode)] || !bOverwrite ))
            {
                // copy child elements
                CopyNode(&pDestNode, &pCurrentNode, bOverwrite, sPath + "/" + sPatternString);
            }
            else if(bHasNode && m_Overwriteable[GetName(pCurrentNode)] && bOverwrite)
            {
                // compare element
                sPatternString = GetPatternString(pCurrentNode, TRUE);
                bHasNode = HasNode(*pXMLDest, sPatternString, &pDestNode);

                if(bHasNode)
                {
                    sPatternString = GetPatternString(pCurrentNode, FALSE);
                    bHasNode = HasNode(*pXMLDest, sPatternString, &pDestNode);

                    if(!bHasNode)
                    {
                        // replace element
                        IXMLDOMNode * pNewNode = NULL;
                        IXMLDOMNode * pXMLOldChild = NULL;

                        hRes = pCurrentNode->cloneNode(VARIANT_TRUE, &pNewNode);
                        hRes = (*pXMLDest)->replaceChild(pNewNode,          // new child
                                                         pDestNode,         // old child
                                                         &pXMLOldChild);    // out old child

                        // log changes
                        Log("Replace Element: " + sPath + "/" + sPatternString);

                        if(pNewNode)
                            pNewNode->Release();
                        if(pXMLOldChild)
                            pXMLOldChild->Release();
                        m_bIsDirty = TRUE;
                    }
                }
            }
            else if(!bHasNode)
            {
                // attach entire sub tree
                IXMLDOMNode * pDestNode = NULL;
                IXMLDOMNode * pXMLNewChild = NULL;
                hRes = pCurrentNode->cloneNode(VARIANT_TRUE, &pDestNode);
                hRes = (*pXMLDest)->appendChild(pDestNode,          // new child
                                                &pXMLNewChild);     // out new child

                // log changes
                sPatternString = GetPatternString(pCurrentNode, FALSE);
                Log("Attach Element: " + sPath + "/" + sPatternString);

                if(pDestNode)
                    pDestNode->Release();
                if(pXMLNewChild)
                    pXMLNewChild->Release();
                m_bIsDirty = TRUE;
            }

            hRes = pNodeList->nextNode(&pCurrentNode);
        }
    }

    return hRes;
}
Exemplo n.º 13
0
typename AdjacencyList::ListNode * AdjacencyList::CopyNode(AdjacencyList::ListNode *dest, AdjacencyList::ListNode *src) {
  if (src == NULL) return NULL;
  dest = new ListNode(src->idx, src->weight);
  dest->next = CopyNode(dest->next, src->next);
  return dest;
}