Esempio n. 1
0
//
//   This file contains the C++ code from Program 16.9 of
//   "Data Structures and Algorithms
//    with Object-Oriented Design Patterns in C++"
//   by Bruno R. Preiss.
//
//   Copyright (c) 1998 by Bruno R. Preiss, P.Eng.  All rights reserved.
//
//   http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/programs/pgm16_09.cpp
//
void Digraph::TopologicalOrderTraversal (Visitor& visitor) const
{
    Array<unsigned int> inDegree (numberOfVertices);
    for (Vertex::Number v = 0; v < numberOfVertices; ++v)
	inDegree [v] = 0;
    Iterator& p = Edges ();
    while (!p.IsDone ()) {
	Edge& edge = dynamic_cast<Edge&> (*p);
	++inDegree [edge.V1 ()];
	++p;
    }
    delete &p;

    Queue& queue = *new QueueAsLinkedList ();
    queue.RescindOwnership ();
    for (Vertex::Number v = 0; v < numberOfVertices; ++v)
	if (inDegree [v] == 0)
	    queue.Enqueue (SelectVertex (v));
    while (!queue.IsEmpty () && !visitor.IsDone ())
    {
	Vertex& vertex =
	    dynamic_cast<Vertex&> (queue.Dequeue ());
	visitor.Visit (vertex);
	Iterator& q = EmanatingEdges (vertex);
	while (!q.IsDone ()) {
	    Edge& edge = dynamic_cast<Edge&> (*q);
	    Vertex& to = edge.V1 ();
	    if (--inDegree [to] == 0)
		queue.Enqueue (to);
	    ++q;
	}
	delete &q;
    }
    delete &queue;
}
Esempio n. 2
0
void ListAsArray::Accept(Visitor& visitor)  const 
{
	for(unsigned int i = 0 ; i < count ; ++i){
		visitor.Visit(*array[i]);
	}
	
}
Esempio n. 3
0
 void Visit(Visitor &visitor)
 {
   for(unsigned int i = 0; i < this->Items.size(); ++i)
     {
     visitor.Visit(this->Items[i]);
     }
 }
void StackAsArray::Accept (Visitor& visitor) const
{
    for (unsigned int i = 0; i < count && !visitor.IsDone (); ++i)
    {
    	visitor.Visit (*array [i]);
    }
}
Esempio n. 5
0
void ListAsArray::Accept(Visitor& visitor) const
{
  for(unsigned int i = 0; i < nCount && !visitor.IsDone(); i++)
    {
      visitor.Visit(*(array[i]));
    }
}
Esempio n. 6
0
void ListAsLinkedList::Accept(Visitor& visitor) const
{
  DListElement<Object*> const* ptr;
  for(ptr = linkedList.GetHeadNode(); ptr != NULL && !visitor.IsDone();
      ptr = ptr->GetNextNodeRight())
    {
      visitor.Visit(*ptr->GetData());
    }
}
void BagAsLinkedList::Accept (Visitor& visitor) const
{
    ListElement<Object*> const* ptr;

    for (ptr = list.Head (); ptr != 0 && !visitor.IsDone (); ptr = ptr->Next())
    {
        visitor.Visit (*ptr->Datum ());
    }
}
Esempio n. 8
0
  bool DirSelect::VisitChildren(Visitor &visitor, bool /*onlyVisible*/)
  {
    for (size_t x=0; x<items.size(); x++) {
      if (!visitor.Visit(objects[x])) {
        return false;
      }
    }

    return true;
  }
Esempio n. 9
0
  bool PopupGroup::VisitChildren(Visitor &visitor, bool /*onlyVisible*/)
  {
    if (main!=NULL) {
      if (!visitor.Visit(main)) {
        return false;
      }
    }

    return true;
  }
Esempio n. 10
0
  bool Multi::VisitChildren(Visitor &visitor, bool onlyVisible)
  {
    if (onlyVisible) {
      if (model.Valid() &&
          !model->IsNull() &&
          !visitor.Visit(list[model->GetUnsignedLong()])) {
        return false;
      }
    }
    else {
      for (size_t x=0; x<list.size(); x++) {
        if (!visitor.Visit(list[x])) {
          return false;
        }
      }
    }

    return true;
  }
Esempio n. 11
0
  bool Table::VisitChildren(Visitor &visitor, bool onlyVisible)
  {
    if (hScroller!=NULL && (!onlyVisible || hVisible)) {
      if (!visitor.Visit(hScroller)) {
        return false;
      }
    }

    if (vScroller!=NULL && (!onlyVisible || vVisible)) {
      if (!visitor.Visit(vScroller)) {
        return false;
      }
    }

    if (object!=NULL) {
      if (!visitor.Visit(object)) {
        return false;
      }
    }

    return true;
  }
void Tree::BreadthFirstTraversal (Visitor& visitor) const
{
    Queue& queue = *new QueueAsLinkedList ();
    queue.RescindOwnership ();

    if (!IsEmpty ())
    	queue.Enqueue (const_cast<Tree&> (*this));
    while (!queue.IsEmpty () && !visitor.IsDone ())
    {
    	Tree const& head = dynamic_cast<Tree const &> (queue.Dequeue ());

		visitor.Visit (head.Key ());
		for (unsigned int i = 0; i < head.Degree (); ++i)
		{
			Tree& child = head.Subtree (i);
			if (!child.IsEmpty ())
				queue.Enqueue (child);
		}
    }
    delete &queue;
}
Esempio n. 13
0
void TypedefNode::Accept(Visitor& visitor)
{
    visitor.Visit(*this);
}
Esempio n. 14
0
void BoundConjunctiveConstraint::Accept(Visitor& visitor)
{
    Left()->Accept(visitor);
    Right()->Accept(visitor);
    visitor.Visit(*this);
}
Esempio n. 15
0
 void Accept(Visitor& v) override
 {
     v.Visit(*this);
 }
Esempio n. 16
0
 void DepartmentZ::Accept(Visitor& externalTrainer) {
	 externalTrainer.Visit(*this);
 }
Esempio n. 17
0
		virtual void Accept(Visitor& visitor) { visitor.Visit(m_Element); }
Esempio n. 18
0
void TemplateParameterNode::Accept(Visitor& visitor)
{
    visitor.Visit(*this);
}
Esempio n. 19
0
void BoundAtomicConstraint::Accept(Visitor& visitor)
{
    visitor.Visit(*this);
}
Esempio n. 20
0
void TemplateIdNode::Accept(Visitor& visitor)
{
    visitor.Visit(*this);
}
Esempio n. 21
0
 /**
  *  @brief Visitor用Accept関数 
  */
  void Accept(Visitor &v){
    v.Visit(this);
  }
Esempio n. 22
0
	virtual void VisitWith( Visitor & visitor ) 
	{ 
		visitor.Visit( element ); 
	}