nint NNavigationConfig::compareTo(const INObject * other) const
            {
                if (this == other)
                    return 0;
                try
                {
                    const NNavigationConfig * obj = dynamic_cast<const NNavigationConfig *>(other);

                    if (obj != NULL)
                    {
                        nint result = 0;
                        if ((result = getView().compare(obj->getView())) == 0)
                        {
                            if (isInitial().getValue() == obj->isInitial().getValue())
                            {
                                if (getNavigationRules() != NULL)
                                {
                                    result = getNavigationRules()->compareTo(obj->getNavigationRules());
                                }
                                else
                                {
                                    if (obj->getNavigationRules() == NULL)
                                    {
                                        result = 0;
                                    }
                                    else
                                    {
                                        result = -1;
                                    }
                                }
                            }
                            else
                            {
                                if (isInitial() == true)
                                {
                                    result = 1;
                                }
                                else
                                {
                                    result = -1;
                                }
                            }
                        }
                        return result;
                    }
                    else
                    {
                        return 1;
                    }
                }
                catch (bad_cast &)
                {
                    return 1;
                }
            }
CommandNode::const_iterator CommandTree::look_up
 (const char* name, CheckResult& status, CommandTree const* & where) const
{
  CommandNode::const_iterator result; // might remain undefined
  CommandNode::const_iterator it = find_prefix(name); // in our |mode| only
  if (it != end() and isInitial(name,it->first)) // anything found here?
  {
    if (isEqual(name,it->first)) // got exact match here
      return status=Found, where=this, it;

    // record partial match, then scan ahead for any further partial matches
    if (status!=NotFound) // we found a partial match, and had at least one
      status = Ambiguous;
    else
    {
      status=PartialMatch; where=this; result=it;
      if (++it != end() and isInitial(name,it->first))
	status = Ambiguous;
    }
  }

  bool not_found_before = status==NotFound;
  // now look in descendant modes; if any has exact match, return that
  for (unsigned int i=0; i<n_desc(); ++i)
  {
    it = nextMode(i).look_up(name,status,where);
    if (status==Found) // found exact match, |where| has been set
      return it; // |where| has been set by recursive |lookup|
    if (not_found_before and status!=NotFound) // got a first partial match
    {
      not_found_before = false; // only one can be the first
      result=it; // export result from first successful recursive |look_up|
    }
  }

  // now |status| can be anything except |Found|
  return result; // value should not be used if |status==NotFound|
}
/*
  add to |e| the set of command names in mode and its descendants,
  that begin with |name|.
*/
void CommandTree::extensions(std::set<const char*,StrCmp>& e,
			     const char* name) const
{
  for (const_iterator it = find_prefix(name); it != end(); ++it)
    if (isInitial(name,it->first))
      e.insert(it->first);
    else
      break; // any element not starting with |name| ends search

  for (size_t j = 0; j < n_desc(); ++j)
  {
    const CommandTree& mode = nextMode(j);
    mode.extensions(e,name);
  }
}
Beispiel #4
0
void State::print(const Automaton& automaton) const
{
    std::cout << "Nom(" << name << ") ";
    if (isInitial()) {
        std::cout << "[initial] ";
    }
    if (isFinal()) {
        std::cout << "[final] ";
    }
    std::cout << std::endl;

    std::cout << "\t== Transitions" << std::endl;

    TransitionSet::const_iterator it;
    for (it = outTransitions.begin(); it != outTransitions.end(); ++it) {
        std::cout << "\t\tavec(" << it->condition << ") => " << automaton.findStateName(it->target) << std::endl;
    }
}
Beispiel #5
0
static void trimLongReadTips()
{
	IDnum index;
	Node *node;
	PassageMarkerI marker, next;

	velvetLog("Trimming read tips\n");

	for (index = 1; index <= nodeCount(graph); index++) {
		node = getNodeInGraph(graph, index);

		if (getUniqueness(node))
			continue;

		for (marker = getMarker(node); marker != NULL_IDX;
		     marker = next) {
			next = getNextInNode(marker);

			if (!isInitial(marker) && !isTerminal(marker))
				continue;

			if (isTerminal(marker))
				marker = getTwinMarker(marker);

			while (!getUniqueness(getNode(marker))) {
				if (next != NULL_IDX
				    && (marker == next
					|| marker == getTwinMarker(next)))
					next = getNextInNode(next);
				if (getNextInSequence(marker) != NULL_IDX) {
					marker = getNextInSequence(marker);
					destroyPassageMarker
					    (getPreviousInSequence
					     (marker));
				} else {
					destroyPassageMarker(marker);
					break;
				}
			}
		}
	}
}
Beispiel #6
0
int isSubsequent(char c) {
    return isInitial(c)
        || isdigit(c)
        || isSpecialSubsequent(c);
}
Beispiel #7
0
// Replaces two consecutive nodes into a single equivalent node
// The extra memory is freed
void concatenateNodes(Node * nodeA, Node * nodeB, Graph * graph)
{
	PassageMarkerI marker, tmpMarker;
	Node *twinA = getTwinNode(nodeA);
	Node *twinB = getTwinNode(nodeB);
	Arc *arc;
	Category cat;

	// Arc management:
	// Freeing useless arcs
	while (getArc(nodeA) != NULL)
		destroyArc(getArc(nodeA), graph);

	// Correct arcs
	for (arc = getArc(nodeB); arc != NULL; arc = getNextArc(arc)) {
		if (getDestination(arc) != twinB)
			createAnalogousArc(nodeA, getDestination(arc),
					   arc, graph);
		else
			createAnalogousArc(nodeA, twinA, arc, graph);
	}

	// Passage marker management in node A:
	for (marker = getMarker(nodeA); marker != NULL_IDX;
	     marker = getNextInNode(marker))
		if (isTerminal(marker))
			incrementFinishOffset(marker,
					      getNodeLength(nodeB));

	// Swapping new born passageMarkers from B to A
	for (marker = getMarker(nodeB); marker != NULL_IDX; marker = tmpMarker) {
		tmpMarker = getNextInNode(marker);

		if (isInitial(marker)
		    || getNode(getPreviousInSequence(marker)) != nodeA) {
			extractPassageMarker(marker);
			transposePassageMarker(marker, nodeA);
			incrementFinishOffset(getTwinMarker(marker),
					      getNodeLength(nodeA));
		} else
			disconnectNextPassageMarker(getPreviousInSequence
						    (marker), graph);
	}

	// Read starts
	concatenateReadStarts(nodeA, nodeB, graph);

	// Gaps
	appendNodeGaps(nodeA, nodeB, graph);

	// Descriptor management (node)
	appendDescriptors(nodeA, nodeB);

	// Update uniqueness:
	setUniqueness(nodeA, getUniqueness(nodeA) || getUniqueness(nodeB));

	// Update virtual coverage
	for (cat = 0; cat < CATEGORIES; cat++)
		incrementVirtualCoverage(nodeA, cat,
					 getVirtualCoverage(nodeB, cat));

	// Update original virtual coverage
	for (cat = 0; cat < CATEGORIES; cat++)
		incrementOriginalVirtualCoverage(nodeA, cat,
						 getOriginalVirtualCoverage
						 (nodeB, cat));

	// Freeing gobbled node
	destroyNode(nodeB, graph);
}
Beispiel #8
0
// Replaces two consecutive nodes into a single equivalent node
// The extra memory is freed
void concatenateStringOfNodes(Node * nodeA, Graph * graph)
{
	Node *twinA = getTwinNode(nodeA);
	Node * nodeB = nodeA;
	Node * twinB;
	Node *currentNode, *nextNode;
	Coordinate totalLength = 0;
	PassageMarkerI marker, tmpMarker;
	Arc *arc;
	Category cat;

	while (simpleArcCount(nodeB) == 1
	       &&
	       simpleArcCount(getTwinNode
			      (getDestination(getArc(nodeB)))) ==
	       1
	       && getDestination(getArc(nodeB)) != getTwinNode(nodeB)
	       && getDestination(getArc(nodeB)) != nodeA) {
		totalLength += getNodeLength(nodeB);
		nodeB = getDestination(getArc(nodeB));
	}
	twinB = getTwinNode(nodeB);
	totalLength += getNodeLength(nodeB);
	reallocateNodeDescriptor(nodeA, totalLength);

	currentNode = nodeA;
	while (currentNode != nodeB) {		
		currentNode = getDestination(getArc(currentNode));

		// Passage marker management in node A:
		for (marker = getMarker(nodeA); marker != NULL_IDX;
		     marker = getNextInNode(marker))
			if (getNode(getNextInSequence(marker)) != currentNode)
				incrementFinishOffset(marker,
						      getNodeLength(currentNode));

		// Swapping new born passageMarkers from B to A
		for (marker = getMarker(currentNode); marker != NULL_IDX; marker = tmpMarker) {
			tmpMarker = getNextInNode(marker);

			if (isInitial(marker)
			    || getNode(getPreviousInSequence(marker)) != nodeA) {
				extractPassageMarker(marker);
				transposePassageMarker(marker, nodeA);
				incrementFinishOffset(getTwinMarker(marker),
						      getNodeLength(nodeA));
			} else
				disconnectNextPassageMarker(getPreviousInSequence
							    (marker), graph);
		}

		// Read starts
		concatenateReadStarts(nodeA, currentNode, graph);

		// Gaps
		appendNodeGaps(nodeA, currentNode, graph);

		// Update uniqueness:
		setUniqueness(nodeA, getUniqueness(nodeA) || getUniqueness(currentNode));

		// Update virtual coverage
		for (cat = 0; cat < CATEGORIES; cat++)
			incrementVirtualCoverage(nodeA, cat,
						 getVirtualCoverage(currentNode, cat));

		// Update original virtual coverage
		for (cat = 0; cat < CATEGORIES; cat++)
			incrementOriginalVirtualCoverage(nodeA, cat,
							 getOriginalVirtualCoverage
							 (currentNode, cat));
		// Descriptor management (node)
		directlyAppendDescriptors(nodeA, currentNode, totalLength);
	}

	// Correct arcs
	for (arc = getArc(nodeB); arc != NULL; arc = getNextArc(arc)) {
		if (getDestination(arc) != twinB)
			createAnalogousArc(nodeA, getDestination(arc),
					   arc, graph);
		else
			createAnalogousArc(nodeA, twinA, arc, graph);
	}

	// Freeing gobbled nodes
	currentNode = getTwinNode(nodeB);
	while (currentNode != getTwinNode(nodeA)) {
		arc = getArc(currentNode);
		nextNode = getDestination(arc);
		destroyNode(currentNode, graph);
		currentNode = nextNode;
	}
}