void CragStackCombiner::combine(const std::vector<Crag>& crags, Crag& crag) { LOG_USER(cragstackcombinerlog) << "combining CRAGs, " << (_requireBbOverlap ? "" : " do not ") << "require bounding box overlap" << std::endl; std::map<Crag::Node, Crag::Node> prevNodeMap; std::map<Crag::Node, Crag::Node> nextNodeMap; for (unsigned int z = 1; z < crags.size(); z++) { LOG_USER(cragstackcombinerlog) << "linking CRAG " << (z-1) << " and " << z << std::endl; if (z == 1) prevNodeMap = copyNodes(crags[0], crag); else prevNodeMap = nextNodeMap; nextNodeMap = copyNodes(crags[z], crag); std::vector<std::pair<Crag::Node, Crag::Node>> links = findLinks(crags[z-1], crags[z]); for (const auto& pair : links) crag.addAdjacencyEdge( prevNodeMap[pair.first], nextNodeMap[pair.second]); } }
static tree_sTable * cloneTree(pwr_tStatus *sts, tree_sTable *otp) { tree_sTable *ntp; ntp = (tree_sTable *) calloc(1, sizeof(*ntp)); if (ntp == NULL) pwr_Return(NULL, sts, TREE__INSVIRMEM); ntp->keySize = otp->keySize; ntp->keyOffset = otp->keyOffset; ntp->recordSize = otp->recordSize; ntp->allocCount = otp->allocCount; ntp->null = allocNode(ntp, NULL); ntp->compareFunc = otp->compareFunc; ntp->key = allocNode(ntp, NULL); ntp->null->bal = 0; ntp->null->left = ntp->null; ntp->null->right = ntp->null; ntp->null->parent = ntp->null; ntp->root = copyNodes(ntp, ntp->null, otp, otp->root); ntp->nNode = otp->nNode; return ntp; }
SortedList<T, Pred>::SortedList(const SortedList<T, Pred> &rhs) throw(SortedListException) :size_(0) { if (rhs.shareAllocator_) { shareAllocator_ = true; freeAllocator_ = false; objAllocator_ = rhs.objAllocator_; } else { shareAllocator_ = false; OAConfig new_config(true); // Use CPP mem manager. objAllocator_ = createAllocator(new_config); } sorter_ = rhs.sorter_; // Build dummy head and tail nodes. /* head_ = allocNode(); tail_ = allocNode();*/ head_ = createNode(0); tail_ = createNode(0); // Everything's good, link'em. head_->Prev = NULL; head_->Next = tail_; tail_->Prev = head_; tail_->Next = NULL; copyNodes(rhs); }
// copy constructor SortSetList::SortSetList(const SortSetList& orig) { if (orig.mainNodePointer == NULL) { this->mainNodePointer = NULL; } else { this->mainNodePointer = copyNodes(*orig.mainNodePointer); } }
static tree_sNode * copyNodes(tree_sTable *ntp, tree_sNode *parent, tree_sTable *otp, tree_sNode *onp) { tree_sNode *nnp; if (onp == otp->null) return ntp->null; nnp = allocNode(ntp, NULL); memcpy(nnp, onp, ntp->recordSize); nnp->parent = parent; nnp->left = copyNodes(ntp, nnp, otp, onp->left); nnp->right = copyNodes(ntp, nnp, otp, onp->right); return nnp; }
Node* CompareList::copyNodes(const Node& current) { if (current.getNext() != NULL) { return new Node(new Data(*(current.getData())), copyNodes(*(current.getNext()))); } else { return new Node(new Data(*(current.getData()))); } }
SortedList<T, Pred>& SortedList<T, Pred>::operator=(const SortedList &rhs) throw(SortedListException) { // Special case, check for self-assignment and short circuit if true. if (this == &rhs) { return(*this); } if (rhs.shareAllocator_) { // We may have to get rid of an existing allocator. if (freeAllocator_) { destroyAllocator(); } freeAllocator_ = false; shareAllocator_ = true; objAllocator_ = rhs.objAllocator_; } else { // Well, we already have an existing allocator, so... // I don't think we want to create a new one. // So, use an old one. shareAllocator_ = false; // OAConfig new_config(true); // Use CPP mem manager. // objAllocator_ = createAllocator(new_config); } sorter_ = rhs.sorter_; // Gank everything! destroyAllNodes(head_); // Build dummy head and tail nodes. /* head_ = allocNode(); tail_ = allocNode();*/ head_ = createNode(0); tail_ = createNode(0); // Everything's good, link'em. head_->Prev = NULL; head_->Next = tail_; tail_->Prev = head_; tail_->Next = NULL; copyNodes(rhs); // All done. return(*this); }
// Commit //------------------------------------------------------------------------------ /*virtual*/ bool FunctionCopy::Commit( NodeGraph & nodeGraph, const BFFIterator & funcStartIter ) const { // make sure all required variables are defined Array< AString > sources( 16, true ); const BFFVariable * dstFileV; if ( !GetStrings( funcStartIter, sources, ".Source", true ) || !GetString( funcStartIter, dstFileV, ".Dest", true ) ) { return false; // GetString will have emitted errors } // Optional AStackString<> sourceBasePath; if ( !GetString( funcStartIter, sourceBasePath, ".SourceBasePath", false ) ) { return false; // GetString will have emitted errors } // Canonicalize the SourceBasePath if ( !sourceBasePath.IsEmpty() ) { AStackString<> cleanValue; NodeGraph::CleanPath( sourceBasePath, cleanValue ); PathUtils::EnsureTrailingSlash( cleanValue ); sourceBasePath = cleanValue; } // check sources are not paths { const AString * const end = sources.End(); for ( const AString * it = sources.Begin(); it != end; ++it ) { const AString & srcFile( *it ); // source must be a file, not a path if ( PathUtils::IsFolderPath( srcFile ) ) { Error::Error_1105_PathNotAllowed( funcStartIter, this, ".Source", srcFile ); return false; } } } // Pre-build dependencies Dependencies preBuildDependencies; if ( !GetNodeList( nodeGraph, funcStartIter, ".PreBuildDependencies", preBuildDependencies, false ) ) { return false; // GetNodeList will have emitted an error } Array< AString > preBuildDependencyNames( preBuildDependencies.GetSize(), false ); for ( const auto & dep : preBuildDependencies ) { preBuildDependencyNames.Append( dep.GetNode()->GetName() ); } // get source node Array< Node * > srcNodes; { const AString * const end = sources.End(); for ( const AString * it = sources.Begin(); it != end; ++it ) { Node * srcNode = nodeGraph.FindNode( *it ); if ( srcNode ) { if ( GetSourceNodes( funcStartIter, srcNode, srcNodes ) == false ) { return false; } } else { // source file not defined by use - assume an external file srcNodes.Append( nodeGraph.CreateFileNode( *it ) ); } } } AStackString<> dstFile; NodeGraph::CleanPath( dstFileV->GetString(), dstFile ); const bool dstIsFolderPath = PathUtils::IsFolderPath( dstFile ); // make all the nodes for copies Dependencies copyNodes( srcNodes.GetSize(), false ); for ( const Node * srcNode : srcNodes ) { AStackString<> dst( dstFile ); // dest can be a file OR a path. If it's a path, use the source filename part if ( dstIsFolderPath ) { // find filename part of source const AString & srcName = srcNode->GetName(); // If the sourceBasePath is specified (and valid) use the name relative to that if ( !sourceBasePath.IsEmpty() && PathUtils::PathBeginsWith( srcName, sourceBasePath ) ) { // Use everything relative to the SourceBasePath dst += srcName.Get() + sourceBasePath.GetLength(); } else { // Use just the file name const char * lastSlash = srcName.FindLast( NATIVE_SLASH ); dst += lastSlash ? ( lastSlash + 1 ) // append filename part if found : srcName.Get(); // otherwise append whole thing } } // check node doesn't already exist if ( nodeGraph.FindNode( dst ) ) { // TODO:C could have a specific error for multiple sources with only 1 output // to differentiate from two rules creating the same dst target Error::Error_1100_AlreadyDefined( funcStartIter, this, dst ); return false; } // create our node CopyFileNode * copyFileNode = nodeGraph.CreateCopyFileNode( dst ); copyFileNode->m_Source = srcNode->GetName(); copyFileNode->m_PreBuildDependencyNames = preBuildDependencyNames; if ( !copyFileNode->Initialize( nodeGraph, funcStartIter, this ) ) { return false; // Initialize will have emitted an error } copyNodes.Append( Dependency( copyFileNode ) ); } // handle alias creation return ProcessAlias( nodeGraph, funcStartIter, copyNodes ); }