void XmlParser::OnStartCdataSection() { obj_ptr<XmlCDATASection> cs = new XmlCDATASection(m_document); newNode(cs, true); }
Node *makeCharacter(char *text) { Node *node= newNode(Character); node->character.value= strdup(text); return node; }
Node *makeClass(char *text) { Node *node= newNode(Class); node->cclass.value= (unsigned char *)strdup(text); return node; }
Node newNodeS (NodeType newType, char* data) { Node result = newNode (newType); result->data.str = data; return result; }
int FEM_Adapt::vertex_split(int n, int n1, int n2, int e1, int e3) { int n_e1 = find_local_node_index(e1, n); int n1_e1 = find_local_node_index(e1, n1); int e2 = theMesh->e2e_getNbr(e1, get_edge_index(n_e1, n1_e1)); int n_e3 = find_local_node_index(e3, n); int n2_e3 = find_local_node_index(e3, n2); int e4 = theMesh->e2e_getNbr(e3, get_edge_index(n_e3, n2_e3)); if (!check_orientation(e1, e3, n, n1, n2)) { int tmp = e3; e3 = e4; e4 = tmp; n_e3 = find_local_node_index(e3, n); n2_e3 = find_local_node_index(e3, n2); } int np = newNode(); int e5 = newElement(); int e6 = newElement(); int nnCount=0, neCount=0; int np_nodes[50], np_elems[50]; // I certainly hope the mesh is not this bad adj_traverse(n, n1, n2, e2, e4, &nnCount, &neCount, np_nodes, np_elems); // Element-to-node updates int nl[3]; if ((n_e1 < n1_e1) || ((n_e1 == 2) && (n1_e1 == 0))) { nl[0] = n1; nl[1] = n; nl[2] = np; theMesh->e2n_setAll(e5, nl); nl[0] = e1; nl[1] = e6; nl[2] = e2; theMesh->e2e_setAll(e5, nl); } else { nl[0] = n; nl[1] = n1; nl[2] = np; theMesh->e2n_setAll(e5, nl); nl[0] = e1; nl[1] = e2; nl[2] = e6; theMesh->e2e_setAll(e5, nl); } if ((n_e3 < n2_e3) || ((n_e3 == 2) && (n2_e3 == 0))) { nl[0] = n2; nl[1] = n; nl[2] = np; theMesh->e2n_setAll(e6, nl); nl[0] = e3; nl[1] = e5; nl[2] = e4; theMesh->e2e_setAll(e6, nl); } else { nl[0] = n; nl[1] = n2; nl[2] = np; theMesh->e2n_setAll(e6, nl); nl[0] = e3; nl[1] = e4; nl[2] = e5; theMesh->e2e_setAll(e6, nl); } theMesh->e2n_replace(e2, n, np); theMesh->e2n_replace(e4, n, np); // Element-to-element updates theMesh->e2e_replace(e1, e2, e5); theMesh->e2e_replace(e2, e1, e5); theMesh->e2e_replace(e3, e4, e6); theMesh->e2e_replace(e4, e3, e6); // Node-to-node updates int i; for (i=0; i<nnCount; i++) { printf("np_nodes[%d] = %d\n", i, np_nodes[i]); theMesh->n2n_remove(n, np_nodes[i]); theMesh->n2n_remove(np_nodes[i], n); theMesh->n2n_add(np, np_nodes[i]); theMesh->n2n_add(np_nodes[i], np); } theMesh->n2n_add(n, np); theMesh->n2n_add(np, n); theMesh->n2n_add(n, n1); theMesh->n2n_add(n1, n); theMesh->n2n_add(n, n2); theMesh->n2n_add(n2, n); // Node-to-element updates for (i=0; i<neCount; i++) { theMesh->n2e_remove(n, np_elems[i]); theMesh->e2n_replace(np_elems[i], n, np); theMesh->n2e_add(np, np_elems[i]); } theMesh->n2e_add(n, e5); theMesh->n2e_add(n, e6); theMesh->n2e_add(n1, e5); theMesh->n2e_add(n2, e6); theMesh->n2e_add(np, e5); theMesh->n2e_add(np, e6); return np; }
/* Parameter must be a ListLine node. Returns a List node. */ Node processListHelper (Node start) { NodeType type, subtype; Node result, curChild, examine, item, previous, l, toBeFreed; if (!start) return 0; if (start->type != ListLine) return 0; if (!start->firstChild) return 0; type = start->firstChild->type; result = newNodeI (List, type == ListBullet ? 1 : type == ListNumbered ? 2 : type == ListIdent ? 3 : 0); curChild = 0; examine = start; while (examine) { toBeFreed = examine; /* We know that examine->firstChild is ListBullet, ListNumbered, etc. Remove it */ removeAndFreeFirstChild (examine); /* Empty list item? */ if (!examine->firstChild) { examine = examine->nextSibling; freeNode (toBeFreed); } /* Does this item start a new list? */ else if (examine->firstChild->type == ListBullet || examine->firstChild->type == ListNumbered || examine->firstChild->type == ListIdent) { /* If we are starting a new list, we want it to be inside the previous list item. */ /* However, if that previous list item does not exist, we need to create a new one. */ if (!curChild) { item = newNode (ListItem); result->firstChild = item; curChild = item; } subtype = examine->firstChild->type; /* progressively remove the firstChild for that sublist */ previous = examine; l = examine->nextSibling; while (l && l->firstChild && l->firstChild->nextSibling && l->firstChild->nextSibling->type == subtype) { removeAndFreeFirstChild (l); previous = l; l = l->nextSibling; } /* trick recursive call into thinking list ends here */ previous->nextSibling = 0; /* notice that the recursive call will take care of freeing the node */ nodeAddChild (curChild, processListHelper (examine)); previous->nextSibling = l; examine = l; } /* Otherwise it's a normal plain old list item */ else { item = newNode (ListItem); if (curChild) curChild->nextSibling = item; else result->firstChild = item; curChild = item; nodeAddChild (curChild, examine->firstChild); examine = examine->nextSibling; freeNode (toBeFreed); } } return result; }
Node newNodeI (NodeType newType, int data) { Node result = newNode (newType); result->data.num = data; return result; }
// // Insert new node with specified value into tree rooted at toNode // void insert (struct Node* toNode, int value) { insertNode(toNode, newNode(value)); }
bool HVACComponent_Impl::removeFromLoop( const HVACComponent & systemStartComponent, const HVACComponent & systemEndComponent, unsigned componentInletPort, unsigned componentOutletPort ) { auto _model = model(); auto thisObject = getObject<HVACComponent>(); if( systemStartComponent.model() != _model ) return false; if( systemEndComponent.model() != _model ) return false; auto inletComponent = connectedObject( componentInletPort ); auto outletComponent = connectedObject( componentOutletPort ); auto inletComponentOutletPort = connectedObjectPort( componentInletPort ); auto outletComponentInletPort = connectedObjectPort( componentOutletPort ); if( ! inletComponent ) return false; if( ! outletComponent ) return false; if( ! inletComponentOutletPort ) return false; if( ! outletComponentInletPort ) return false; auto inletNode = inletComponent->optionalCast<Node>(); auto outletNode = outletComponent->optionalCast<Node>(); boost::optional<Splitter> splitter; boost::optional<Mixer> mixer; if( inletNode ) { if( auto mo = inletNode->inletModelObject() ) { splitter = mo->optionalCast<Splitter>(); } } if( outletNode ) { if( auto mo = outletNode->outletModelObject() ) { mixer = mo->optionalCast<Mixer>(); } } if( systemStartComponent.handle() == inletComponent->handle() && systemEndComponent.handle() == outletComponent->handle() ) { // This component is between the systemStartComponent and the systemEndComponent // ie. the supply or demand inlet or outlet Nodes, // or the oa system end points on either the relief or inlet air streams. _model.disconnect(thisObject,componentInletPort); _model.disconnect(thisObject,componentOutletPort); _model.connect( inletComponent.get(), inletComponentOutletPort.get(), outletComponent.get(), outletComponentInletPort.get() ); return true; } else if( systemEndComponent.handle() == outletComponent->handle() ) { // Here the systemEndComponent is immediately downstream of this component, // but there are other components (besides systemStartComponent) upstream. boost::optional<ModelObject> newInletComponent; boost::optional<unsigned> newInletComponentOutletPort; // Make sure we don't end up with two nodes next to each other after this component is removed if( inletNode && outletNode ) { newInletComponent = inletNode->inletModelObject(); newInletComponentOutletPort = inletNode->connectedObjectPort(inletNode->inletPort()); OS_ASSERT(newInletComponent); OS_ASSERT(newInletComponentOutletPort); } else { newInletComponent = inletComponent; newInletComponentOutletPort = inletComponentOutletPort; } _model.disconnect(thisObject,componentInletPort); _model.disconnect(thisObject,componentOutletPort); // inletNode->remove() would have failed if we did it before the disconnect if( inletNode && outletNode ) { inletNode->remove(); } _model.connect( newInletComponent.get(), newInletComponentOutletPort.get(), outletComponent.get(), outletComponentInletPort.get() ); return true; } else if( splitter && mixer ) { // If the component is the only component (except nodes) between a splitter mixer pair OS_ASSERT(inletNode); OS_ASSERT(outletNode); int i = splitter->branchIndexForOutletModelObject(inletNode.get()); int j = mixer->branchIndexForInletModelObject(outletNode.get()); OS_ASSERT(i == j); splitter->removePortForBranch(i); mixer->removePortForBranch(i); _model.disconnect(thisObject,componentInletPort); _model.disconnect(thisObject,componentOutletPort); inletNode->remove(); outletNode->remove(); if( ! splitter->lastOutletModelObject() ) { Node newNode(_model); _model.connect(splitter.get(),splitter->nextOutletPort(),newNode,newNode.inletPort()); _model.connect(newNode,newNode.outletPort(),mixer.get(),mixer->nextInletPort()); } return true; } else { boost::optional<ModelObject> newOutletComponent; boost::optional<unsigned> newOutletComponentInletPort; if( inletNode && outletNode ) { newOutletComponent = outletNode->outletModelObject(); newOutletComponentInletPort = outletNode->connectedObjectPort(outletNode->outletPort()); } if( ! newOutletComponent ) newOutletComponent = outletComponent; if( ! newOutletComponentInletPort ) newOutletComponentInletPort = outletComponentInletPort; _model.disconnect(thisObject,componentInletPort); _model.disconnect(thisObject,componentOutletPort); // outletNode->remove() would have failed if we did it before the disconnect if( inletNode && outletNode ) { outletNode->remove(); } model().connect( inletComponent.get(), inletComponentOutletPort.get(), newOutletComponent.get(), newOutletComponentInletPort.get() ); return true; } return false; }
int main(){ struct node* root = newNode(7); root->left = newNode(1); root->right = newNode(9); root->left->left = newNode(0); root->left->right = newNode(3); root->right->left = newNode(8); root->right->right = newNode(10); root->left->right->left = newNode(2); root->left->right->right = newNode(5); root->left->right->right->left = newNode(4); root->left->right->right->right = newNode(6); //root->right->right->right = newNode(10); // root->right->left->right->left = newNode(9); //root->right->right->right->right = newNode(10); // struct stack* S = createStack(); // push(S, newNode(10)); // push(S, newNode(20)); // push(S, newNode(30)); // printStack(S->top); // pop(S); // printf("\nElements after stack!:"); // printStack(S->top); int inorder[11] = {0,1,2,3,4,5,6,7,8,9,10}; int preorder[11] = {7,1,0,3,2,5,4,6,9,8,10}; //printf("\nThe zigzag of the tree is: "); //zigzag(root); struct node* newTree = buildPreIn(inorder, preorder, 0, 10); printf("\nInorder Traversal:\n"); inOrder(newTree); return 0; }
void Push(struct node** head, int data) { struct node* temp = newNode(data); temp->next = *head; *head = temp; }
IdMapperBase::Node* IdMapperBase::add () { if (top != NULL && top->weight == limit) { return NULL; } Node *node = newNode (); Node *ret = node; bool left = false; Node *cur = top; if (cur != NULL) { unsigned long w, tw; tw = 0; while (1) { cur->weight ++; w = cur->left == NULL ? 0 : cur->left->weight + 1; if (w + tw < cur->value) { if (cur->left == NULL) { cur->left = node; left = true; node->value = cur->value - 1; break; } cur = cur->left; } else { if (cur->right == NULL) { cur->right = node; left = false; node->value = cur->value + 1; break; } tw += 1 + w; cur = cur->right; } } } else { top = node; node->value = 0; } node->top = cur; node->left = NULL; node->right = NULL; node->balance = 0; node->weight = 0; node = node->top; while (node != NULL) { if (left == false) { if (node->balance == 1) { if (node->right->balance == -1) node = rotateDoubleLeft (node); else node = rotateSingleLeft (node); } else node->balance ++; } else { if (node->balance == -1) { if (node->left->balance == 1) node = rotateDoubleRight (node); else node = rotateSingleRight (node); } else node->balance --; } if (node->top == NULL || node->balance == 0) break; if (node->top->left == node) left = true; else left = false; node = node->top; } return ret; }
int TetMesh::mesh() { Domain* domain = OPS_GetDomain(); if (domain == 0) { opserr << "WARNING: domain is not created\n"; return -1; } // check double size = this->getMeshsize(); if(size <= 0) { opserr<<"WARNING: mesh size <= 0\n"; return -1; } if (mtags.Size() == 0) return 0; // get nodes and elements from boundary mesh ID ndtags; std::vector<TetMeshGenerator::Facet> facets; for (int i=0; i<mtags.Size(); ++i) { // get mesh Mesh* mesh = OPS_getMesh(mtags(i)); if (mesh == 0) { opserr << "WARNING: mesh "<<mtags(i)<<" does not exist\n"; return -1; } // get nodes const ID& tags = mesh->getNodeTags(); for (int j=0; j<tags.Size(); ++j) { ndtags.insert(tags(j)); } const ID& newtags = mesh->getNewNodeTags(); for (int j=0; j<newtags.Size(); ++j) { ndtags.insert(newtags(j)); } // get polygons int numelenodes = mesh->getNumEleNodes(); const ID& elends = mesh->getEleNodes(); TetMeshGenerator::Facet facet; for (int j=0; j<elends.Size()/numelenodes; ++j) { TetMeshGenerator::Polygon polygon(numelenodes); for (int k=0; k<numelenodes; ++k) { polygon[k] = elends(numelenodes*j+k); } facet.push_back(polygon); } // add the mesh as a facet facets.push_back(facet); } if(ndtags.Size() < 4) { opserr<<"WARNING: input number of nodes < 4\n"; return -1; } if(facets.size() < 4) { opserr<<"WARNING: input number of facets < 4\n"; return -1; } this->setNodeTags(ndtags); // get correct index for factes for (unsigned int i=0; i<facets.size(); ++i) { for (unsigned int j=0; j<facets[i].size(); ++j) { for (unsigned int k=0; k<facets[i][j].size(); ++k) { facets[i][j][k] = ndtags.getLocationOrdered(facets[i][j][k]); if (facets[i][j][k] < 0) { opserr << "WARNING: failed to get a node in a facet -- Tetmesh::mesh\n"; return -1; } } } } // calling mesh generator TetMeshGenerator gen; int nodecounter = nextNodeTag(); for(int i=0; i<ndtags.Size(); i++) { // get node Node* theNode = domain->getNode(ndtags(i)); if(theNode == 0) { opserr<<"WARNING: node "<<ndtags(i)<<" is not defined\n"; return -1; } Vector crds = theNode->getCrds(); const Vector& disp = theNode->getTrialDisp(); if(crds.Size() != 3) { opserr<<"WARNING: ndm != 3\n"; return -1; } if (disp.Size() >= crds.Size()) { for (int j=0; j<crds.Size(); ++j) { crds(j) += disp(j); } } // add point gen.addPoint(crds(0), crds(1), crds(2), 0); // add pc if (this->isFluid()) { // create pressure constraint Pressure_Constraint* thePC = domain->getPressure_Constraint(ndtags(i)); if(thePC != 0) { thePC->setDomain(domain); } else { // create pressure node Node* pnode = 0; pnode = new Node(nodecounter++, 1, crds[0], crds[1], crds[2]); if (pnode == 0) { opserr << "WARNING: run out of memory -- BgMesh::gridNodes\n"; return -1; } if (domain->addNode(pnode) == false) { opserr << "WARNING: failed to add node to domain -- BgMesh::gridNodes\n"; delete pnode; return -1; } thePC = new Pressure_Constraint(ndtags(i), pnode->getTag()); if(thePC == 0) { opserr<<"WARNING: no enough memory for Pressure_Constraint\n"; return -1; } if (domain->addPressure_Constraint(thePC) == false) { opserr << "WARNING: failed to add PC to domain -- BgMesh::gridNodes\n"; delete thePC; return -1; } } } } for (unsigned int i=0; i<facets.size(); ++i) { gen.addFacet(facets[i],0); } // meshing gen.mesh(size*size*size/(6.0*1.414),false); // get points and create nodes int nump = gen.getNumPoints(); if (nump == 0) { opserr << "WARNING: no nodes is meshed\n"; return -1; } ID newndtags(nump-ndtags.Size()); ID allndtags(nump); for (int i=0; i<ndtags.Size(); ++i) { allndtags(i) = ndtags(i); } for (int i=ndtags.Size(); i<nump; ++i) { // get point Vector crds(3); int mark = 0; gen.getPoint(i,crds(0),crds(1),crds(2),mark); Node* node = newNode(nodecounter++,crds); if (node == 0) { opserr << "WARING: failed to create node\n"; return -1; } if (domain->addNode(node) == false) { opserr << "WARNING: failed to add node to domain\n"; delete node; return -1; } allndtags(i) = node->getTag(); newndtags(i-ndtags.Size()) = node->getTag(); // add pc if (this->isFluid()) { // create pressure constraint Pressure_Constraint* thePC = domain->getPressure_Constraint(node->getTag()); if(thePC != 0) { thePC->setDomain(domain); } else { // create pressure node Node* pnode = 0; pnode = new Node(nodecounter++, 1, crds(0), crds(1), crds(2)); if (pnode == 0) { opserr << "WARNING: run out of memory -- BgMesh::gridNodes\n"; return -1; } if (domain->addNode(pnode) == false) { opserr << "WARNING: failed to add node to domain -- BgMesh::gridNodes\n"; delete pnode; return -1; } thePC = new Pressure_Constraint(node->getTag(), pnode->getTag()); if(thePC == 0) { opserr<<"WARNING: no enough memory for Pressure_Constraint\n"; return -1; } if (domain->addPressure_Constraint(thePC) == false) { opserr << "WARNING: failed to add PC to domain -- BgMesh::gridNodes\n"; delete thePC; return -1; } } } } this->setNewNodeTags(newndtags); // get tetrahedrons int numtet = gen.getNumTets(); if (numtet == 0) return 0; ID elenodes(numtet*4); for(int i=0; i<numtet; i++) { int p1,p2,p3,p4; gen.getTet(i,p1,p2,p3,p4); elenodes(4*i) = allndtags(p1); elenodes(4*i+1) = allndtags(p2); elenodes(4*i+2) = allndtags(p3); elenodes(4*i+3) = allndtags(p4); } this->setEleNodes(elenodes); // create elemnts if (this->newElements(elenodes) < 0) { opserr << "WARNING: failed to create elements\n"; return -1; } return 0; }
void XmlParser::OnStartElement(const XML_Char *name, const XML_Char **atts) { const XML_Char **p = atts; std::map<exlib::string, exlib::string> nss; exlib::string def_ns; bool has_def = false; while (p[0] && p[1]) { const XML_Char *ns = p[0]; if (!qstrcmp(ns, "xmlns", 5)) { if (ns[5] == ':') nss.insert(std::pair<exlib::string, exlib::string>(ns + 6, p[1])); else if (!ns[5]) { def_ns = p[1]; has_def = true; } } p += 2; } obj_ptr<XmlElement> el; const char *str = qstrchr(name, ':'); if (str) { exlib::string prefix(name, str - name); exlib::string qname(str + 1); std::map<exlib::string, exlib::string>::iterator it; it = nss.find(prefix); if (it != nss.end()) def_ns = it->second; else m_now->lookupNamespaceURI(prefix, def_ns); } else if (!has_def) { int32_t type; m_now->get_nodeType(type); if (type == xml_base::_ELEMENT_NODE) ((XmlElement *)(XmlNode_base *)m_now)->get_defaultNamespace(def_ns); } if (!def_ns.empty()) el = new XmlElement(m_document, def_ns, name, m_isXml); else el = new XmlElement(m_document, name, m_isXml); newNode(el, true); while (atts[0] && atts[1]) { name = atts[0]; str = qstrchr(name, ':'); if (str && str[1]) { exlib::string ns(name, str - name); exlib::string qname(str + 1); std::map<exlib::string, exlib::string>::iterator it; it = nss.find(ns); if (it != nss.end()) def_ns = it->second; else m_now->lookupNamespaceURI(ns, def_ns); } else def_ns.clear(); if (!def_ns.empty()) el->setAttributeNS(def_ns, name, atts[1]); else el->setAttribute(name, atts[1]); atts += 2; } }
/* call an action with actionName and string parameters */ Res *computeExpressionWithParams( const char *actionName, const char **params, int paramsCount, ruleExecInfo_t *rei, int reiSaveFlag, msParamArray_t *msParamArray, rError_t *errmsg, Region *r ) { #ifdef DEBUG char buf[ERR_MSG_LEN > 1024 ? ERR_MSG_LEN : 1024]; snprintf( buf, 1024, "computExpressionWithParams: %s\n", actionName ); writeToTmp( "entry.log", buf ); #endif /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; if ( overflow( actionName, MAX_NAME_LEN ) ) { addRErrorMsg( errmsg, RE_BUFFER_OVERFLOW, "error: potential buffer overflow" ); return newErrorRes( r, RE_BUFFER_OVERFLOW ); } int k; for ( k = 0; k < paramsCount; k++ ) { if ( overflow( params[k], MAX_RULE_LEN ) ) { addRErrorMsg( errmsg, RE_BUFFER_OVERFLOW, "error: potential buffer overflow" ); return newErrorRes( r, RE_BUFFER_OVERFLOW ); } } Node** paramNodes = ( Node ** )region_alloc( r, sizeof( Node * ) * paramsCount ); int i; for ( i = 0; i < paramsCount; i++ ) { Node *node; /*Pointer *e = newPointer2(params[i]); if(e == NULL) { addRErrorMsg(errmsg, -1, "error: can not create Pointer."); return newErrorRes(r, -1); } node = parseTermRuleGen(e, 1, errmsg, r);*/ node = newNode( TK_STRING, params[i], 0, r ); /*if(node==NULL) { addRErrorMsg(errmsg, OUT_OF_MEMORY, "error: out of memory."); return newErrorRes(r, OUT_OF_MEMORY); } else if (getNodeType(node) == N_ERROR) { return newErrorRes(r, RES_ERR_CODE(node)); }*/ paramNodes[i] = node; } Node *node = createFunctionNode( actionName, paramNodes, paramsCount, NULL, r ); Env *global = newEnv( newHashTable2( 10, r ), NULL, NULL, r ); Env *env = newEnv( newHashTable2( 10, r ), global, NULL, r ); if ( msParamArray != NULL ) { convertMsParamArrayToEnv( msParamArray, global, r ); deleteFromHashTable(global->current, "ruleExecOut"); } Res *res = computeNode( node, NULL, env, rei, reiSaveFlag, errmsg, r ); /* deleteEnv(env, 3); */ if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return res; }
bool HVACComponent_Impl::addToNode(Node & node, const HVACComponent & systemStartComponent, const HVACComponent & systemEndComponent, unsigned componentInletPort, unsigned componentOutletPort) { Model _model = model(); ModelObject thisModelObject = getObject<ModelObject>(); if( node.model() != _model ) return false; if( systemStartComponent.model() != _model ) return false; if( systemEndComponent.model() != _model ) return false; if( (node == systemEndComponent) && (node.inletModelObject().get() == systemStartComponent) ) { unsigned oldOutletPort = node.connectedObjectPort( node.inletPort() ).get(); unsigned oldInletPort = node.inletPort(); ModelObject oldSourceModelObject = node.connectedObject( node.inletPort() ).get(); ModelObject oldTargetModelObject = node; // If systemStartComponent is not a node we need to insert one so that there // is a node between systemStartComponent and this component we are adding // This situation occurs in the oa system relief stream. if( ! systemStartComponent.optionalCast<Node>() ) { Node newNode(_model); _model.connect(oldSourceModelObject,oldOutletPort, newNode,newNode.inletPort()); oldOutletPort = newNode.outletPort(); oldSourceModelObject = newNode; } _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, componentInletPort ); _model.connect( thisModelObject, componentOutletPort, oldTargetModelObject, oldInletPort ); return true; } else if( (node == systemStartComponent) && (node.outletModelObject().get() == systemEndComponent) ) { unsigned oldInletPort = node.connectedObjectPort( node.outletPort() ).get(); unsigned oldOutletPort = node.outletPort(); ModelObject oldTargetModelObject = node.connectedObject( node.outletPort() ).get(); ModelObject oldSourceModelObject = node; // If systemEndComponent is not a node we need to insert one so that there // is a node between systemEndComponent and this component we are adding // This situation occurs in the oa system outdoor air stream. if( ! systemEndComponent.optionalCast<Node>() ) { Node newNode(_model); _model.connect(newNode,newNode.outletPort(), oldTargetModelObject,oldInletPort); oldInletPort = newNode.inletPort(); oldTargetModelObject = newNode; } _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, componentInletPort ); _model.connect( thisModelObject, componentOutletPort, oldTargetModelObject, oldInletPort ); return true; } else if( node == systemEndComponent ) { unsigned oldOutletPort = node.connectedObjectPort( node.inletPort() ).get(); unsigned oldInletPort = node.inletPort(); ModelObject oldSourceModelObject = node.connectedObject( node.inletPort() ).get(); ModelObject oldTargetModelObject = node; Node newNode( _model ); _model.connect( oldSourceModelObject, oldOutletPort, newNode, newNode.inletPort() ); _model.connect( newNode, newNode.outletPort(), thisModelObject, componentInletPort ); _model.connect( thisModelObject, componentOutletPort, oldTargetModelObject, oldInletPort ); return true; } else { unsigned oldOutletPort = node.outletPort(); unsigned oldInletPort = node.connectedObjectPort( node.outletPort() ).get(); ModelObject oldSourceModelObject = node; ModelObject oldTargetModelObject = node.connectedObject( node.outletPort() ).get(); Node newNode( _model ); _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, componentInletPort ); _model.connect( thisModelObject, componentOutletPort, newNode, newNode.inletPort() ); _model.connect( newNode, newNode.outletPort(), oldTargetModelObject, oldInletPort ); return true; } return false; }
int main(int argc, char *argv[]) { if (argc<2) return 0; FILE *f = fopen(argv[1],"r"); if (f==NULL) return 0; struct List *l; newList(&l); char x[20]; struct Entry* node; struct Entry* n1 ; newNode(&n1); n1->element = "N1"; struct Entry* n2 ; newNode(&n2); n2->element = "N2"; struct Entry* n3 ; newNode(&n3); n3->element = "N3"; struct Entry* n4 ; newNode(&n4); n4->element = "N4"; int status = 0; struct Entry* e = l->head; while (fscanf(f,"%s",x)==1) { if (x[0] == '"') continue; if (strcmp(x,"N1")==0) node = n1; if (strcmp(x,"N2")==0) node = n2; if (strcmp(x,"N3")==0) node = n3; if (strcmp(x,"N4")==0) node = n4; if (strcmp(x,"H")==0) node = l->head; //prophet generated patch addLast(&l, &node); } fclose(f); if (hasLoopNext(l)==0 ){ printf("%s","HAS LOOP"); return 0; } if (hasLoopPrev(l)==0 ){ printf("%s","HAS LOOP"); return 0; } struct Entry* n = l->head->next; while (n != (l->head)) { printf("%s ", n->element); printf("%s ", n->previous->element); printf("%s ", n->previous->element); n = n->next; } printf(" %d",l->size); return 0; }
Node *makePeekFor(Node *e) { Node *node= newNode(PeekFor); node->peekFor.element= e; return node; }
/* The PreBlock node returned by the grammar contains one or more PreLine * nodes, each of which has one or two children. The first child is something * representing text. The second, if present, is a Newlines node. We want to * convert those Newlines nodes to empty PreLine nodes, except for the very * last one in the block, which we want to discard. * * It is harmless to call this twice on the same block (the second time won't * make any more changes), but for efficiency, don't. */ Node processPreBlock (Node block) { Node result, examine, newlinesnode, tmpnode; /****** EXAMPLE ****** * * (*) node(type=PreBlock) * | * | firstChild * | * |A(type=PreLine) B(type=PreLine) * (*)------------nextSibling------------(*) * | | * | firstChild | firstChild * | | * |W(type=TextToken) X(type=Newlines) |Y(type=TextToken) Z(type=Newlines) * (*)---nextSibling---(*)(num=2) (*)---nextSibling---(*)(num=1) * * We want to convert X to two PreLine nodes and get rid of Z. * The following is the end-result: * * (*) node(type=PreBlock) * | * | firstChild * | * |A(type=PreLine) C(type=PreLine) D(type=PreLine) B(type=PreLine) * (*)---nextSibling---(*)---nextSibling---(*)---nextSibling---(*) * | | * | firstChild | firstChild * | | * |W(type=TextToken) |Y(type=TextToken) * (*) (*) * * Notice how X has been removed and C and D created instead, while Z has been removed with * no replacement. Notice also that W & Y might as well be TextBlocks, ExtensionTokens, etc. * */ result = block; /* Iteratively examine all of the block's children (A and B) */ examine = block->firstChild; while (examine) { /* If a Newlines node exists (i.e. X or Z)... */ if (examine->firstChild->nextSibling) { newlinesnode = examine->firstChild->nextSibling; /* Detach the Newlines node from examine */ examine->firstChild->nextSibling = 0; /* If this isn't the last PreLine in the block... */ if (examine->nextSibling) { /* Remember the next sibling (B) */ tmpnode = examine->nextSibling; /* Convert Newlines node to empty PreLine nodes */ while (newlinesnode->data.num--) { /* Insert an empty PreLine node (C and D) */ examine->nextSibling = newNode (PreLine); /* Move on to the newly-created node */ examine = examine->nextSibling; } /* Re-attach the next sibling (B) */ examine->nextSibling = tmpnode; } /* Newlines nodes don't have children, no need for freeRecursively */ freeNode (newlinesnode); } examine = examine->nextSibling; } return result; }
Node *makePeekNot(Node *e) { Node *node= newNode(PeekNot); node->peekNot.element= e; return node; }
Node processNestedItalics (Node node) { Node examine, saveExamineSibling, childExamine, childSibling, saveChildSibling; if (!node) return 0; if (node->type != TextBlock) return node; /****** EXAMPLE ****** * * (*) node(type=TextBlock) * | * | firstChild * | * |A(type=TextToken) B(type=Italics) C(type=TextToken) * (*)---nextSibling---(*)---nextSibling---(*) * | * | firstChild * | * (*) T(type=TextBlock) * | * | firstChild * | * |W(type=TextToken) X(type=Italics) Y(type=TextToken) * (*)---nextSibling---(*)---nextSibling---(*) * | * | firstChild * | * (*) Z * * Here we have two Italics nodes nested inside each other (X is inside B). * The following is the end-result: * * (*) node(type=TextBlock) * | * | firstChild * | B new * |A Italics Z Italics C * (*)--nextSibling--(*)--nextSibling--(*)--nextSibling--(*)--nextSibling--(*) * | firstChild | firstChild * (*) T (*) Y * | firstChild * (*) W * * T is no longer really necessary, but specifically freeing it is pointless, so we keep it. * */ for (examine = node->firstChild; examine; examine = examine->nextSibling) { /* In the above example, examine = B, but as new nodes are created and made siblings of B, * examine walks along them. Either way, it is the node just before C. */ if (examine->type == Italics && examine->firstChild && examine->firstChild /* i.e. T */->type == TextBlock) { /* Remember B's original sibling (C). We are going to insert a number of new * siblings after B, so at the end we want to re-attach C to the last one. */ saveExamineSibling = examine->nextSibling; childExamine = examine->firstChild /* i.e. T */->firstChild /* i.e. W */; /* childSibling will be our "iterator" for iterating over the children of T */ childSibling = childExamine->nextSibling; childExamine->nextSibling = 0; /* Detach W's siblings */ while (childSibling) { /* Remember the sibling we want to move on to later */ saveChildSibling = childSibling->nextSibling; /* If we find a nested Italics (X in the example), move its child (Z) out * and make it a sibling of B. */ if (childSibling->type == Italics) { examine->nextSibling = childSibling->firstChild; /* Move examine on to the newly created sibling */ examine = examine->nextSibling; /* Free the now-obsolete Italics node */ /* We have attached its children elsewhere, so don't use freeRecursively */ freeNode (childSibling); } /* Any node that is not an Italics node needs to become attached to one. * (In the above example, this is only Y.) */ else { /* Detach the two */ childSibling->nextSibling = 0; /* If examine already points to an Italics node, don't create a new one. */ /* Instead, combine its child and this one. (Doesn't occur in the example.) */ if (examine->type == Italics) examine->firstChild = makeTextBlock (examine->firstChild, childSibling); else { /* Create a new Italics node, attach the current node (Y) to it, and make * it the next-distant sibling of B */ examine->nextSibling = nodeAddChild (newNode (Italics), childSibling); examine = examine->nextSibling; } } childSibling = saveChildSibling; } /* Now re-attach the previous sibling of B (i.e. C). */ examine->nextSibling = saveExamineSibling; } } return node; }
Node *makeQuery(Node *e) { Node *node= newNode(Query); node->query.element= e; return node; }
void newList(struct List** l) { *l = malloc( sizeof(struct List) ); newNode(&((*l)->head)); (*l)->head->next = (*l)->head; return; }
Node *makeStar(Node *e) { Node *node= newNode(Star); node->star.element= e; return node; }
Node *makeDot(void) { return newNode(Dot); }
Node *makePlus(Node *e) { Node *node= newNode(Plus); node->plus.element= e; return node; }
Node *makeString(char *text) { Node *node= newNode(String); node->string.value= strdup(text); return node; }
/* Build a Genomic Christmas tree * * * This function requires a very specific input that exactly follows a specific * order. It must have at least three space separated arguments: * * For example: * chr 1 Chr1 1 10000 * gene 2 g1 3631 5899 * mRNA 3 g1m1 3631 5899 * CDS 4 g1m1c1 3760 3913 * CDS 4 g1m1c2 3996 4276 * CDS 4 g1m1c3 4486 4605 * gene 2 g2 5928 8737 * ... * * 1: TYPE - This is actually ignored, but must be present. * 2: LEVEL - Fagin uses this number to determine hierarchy level. 0 is root, * but mmust not be included. * 3: NAME - A label with no spaces, it must be less than NAME_LENGTH * characters long. There are no other constraints (currently). * It needn't be unique and can include any non-whitespace * ASCII character. * 4: BEG - The starting position of the interval. * 5: END - The ending position of the interval. * * The file may contain additional columns of data, but at present these will * be ignored. * * The order is REQUIRED to be depth-first recursion order based on the TYPE * filed. Currently Fagin performs NO checking on correctness of order. It * is assumed that the input was created by an (as of yet unwritten) utility * that parsed it from a GFF file and carefully validated it. */ Node * readNodeFile(char * filename, size_t nlevels){ FILE * fp = fopen(filename, "rb"); char * line = NULL; size_t len = 0; ssize_t read; if(fp == NULL){ printf("Cannot open file\n"); exit(1); } // Define root node Node * root = newNode(); strcpy(root->name, "root"); root->type = GENOME; // This is a 3-pass algorithm, a little ugly, but it works. // Pseudocode // 1. create a doubly linked list of all Nodes, return final node // 2. iterate backwards, counting the children of each node, return first node // 3. iterate forwards, filling child arrays and trimming unnecessary links // NOTE: it is necessary to free this memory // 1. create a flat, doubly-linked list of Node objects // the hierarchical level is stored in type {1, 2, ..., nlevels - 1) Node * lastnd = root; while ((read = getline(&line, &len, fp)) != EOF) { Node * nd = newNode(); sscanf(line, "%*s %d %s", &nd->type, nd->name); nd->last = lastnd; lastnd->next = nd; lastnd = nd; } lastnd->next = NULL; size_t counts[nlevels]; for(int i = 0; i < nlevels; i++){ counts[i] = 0; } // 2. Walk backwards and count children Node * node = lastnd; while(node != NULL){ counts[node->type]++; // if all children have been counted, set size if(node->next != NULL && node->type < node->next->type){ node->size = counts[node->type + 1]; counts[node->type + 1] = 0; } node = node->last; } Node * parents[nlevels]; for(int i = 0; i < nlevels; i++){ counts[i] = 0; parents[i] = NULL; } // 3. Makes houses for children and assign them places node = root; parents[0] = node; int pid; while(node != NULL){ // This is the level of the parent (e.g. 0 is GENOME and 4 is EXON) pid = node->type - 1; if(node->next != NULL){ // The input file is required to be ordered such that this works ... if(node->type < node->next->type){ // start collecting children for this node at the appropriate level parents[node->type] = node; // make container for children node->children = (Node**)malloc(node->size * sizeof(Node*)); // reset child count at this level counts[node->type] = 0; } } // assign this child to a parent, unless it is root (pid == -1) if(pid > -1) parents[pid]->children[counts[pid]] = node; // count this child (needed for correct assignment of next sibling) counts[node->type - 1]++; // progress to next node (remember this is still a flat, doubly-linked list) node = node->next; } return(root); }
Node *makePredicate(char *text) { Node *node= newNode(Predicate); node->predicate.text= strdup(text); return node; }
void XmlParser::OnProcessingInstruction(const XML_Char *target, const XML_Char *data) { obj_ptr<XmlProcessingInstruction> pi = new XmlProcessingInstruction(m_document, target, data); newNode(pi); }