Esempio n. 1
0
int Hash_Map_Example::run (void)
{
  ACE_TRACE ("Hash_Map_Example::run");

  for (int i = 0; i < 100; i++)
    {
      map_.bind (i, DataElement (i));
    }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Map has\n")));
  for (int j = 0; j < 100; j++)
    {
      DataElement d;
      map_.find (j, d);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), d.getData ()));
    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));

  // Use the forward iterator.
  this->iterate_forward ();

  // Use the reverse iterator.
  this->iterate_reverse ();

  // Remove all the elements from the map.
  this->remove_all ();

  // Iterate through the map again.
  this->iterate_forward ();

  return 0;
}
Esempio n. 2
0
// Listing 1 code/ch05
int QueueExample::runStackUnboundedQueue (void)
{
  ACE_TRACE ("QueueExample::runStackUnboundedQueue");

  ACE_Unbounded_Queue<DataElement> queue;
  DataElement elem1[10];
  int i;
  for (i = 0; i < 10; i++)
    {
      elem1[i].setData (9-i);
      queue.enqueue_head (elem1[i]);
    }

  DataElement elem2[10];
  for (i = 0; i < 10; i++)
    {
      elem2[i].setData (i+10);
      queue.enqueue_tail (elem2[i]);
    }

  for (ACE_Unbounded_Queue_Iterator<DataElement> iter (queue);
       !iter.done ();
       iter.advance ())
    {
      DataElement *elem = 0;
      iter.next (elem);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), elem->getData ()));
    }

  return 0;
}
Esempio n. 3
0
// Listing 1 code/ch05
int StackExample::runBoundedStack (void)
{
  ACE_TRACE (ACE_TEXT ("StackExample::runBoundedStack"));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Using a bounded stack\n")));

  ACE_Bounded_Stack<DataElement> bstack1 (100);

  // The element array is constrained to this scope.
  {
    DataElement elem[100];
    for (int i = 0; i < 100; i++)
      {
        elem[i].setData(i);
        // Push the element on the stack.
        bstack1.push (elem[i]);
      }
  }

  ACE_Bounded_Stack<DataElement> bstack2 (100);

  // Make a copy!
  bstack2 = bstack1;
  for (int j = 0; j < 100; j++)
    {
      DataElement elem;
      bstack2.pop (elem);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), elem.getData ()));
    }

  return 0;
}
Esempio n. 4
0
// Listing 1
// Listing 2 code/ch05
int SetExample::runUnboundedSet ()
{
  ACE_TRACE (ACE_TEXT ("SetExample::runUnboundedSet"));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Using an unbounded set.\n")));
  ACE_Unbounded_Set<DataElement*> uset;
  for (int m = 0; m < 100; m++)
    {
      DataElement *elem;
      ACE_NEW_RETURN (elem, DataElement (m), -1);
      uset.insert (elem);
    }
  DataElement deBegin (0), deEnd (99);
  if (!uset.find (&deBegin) && !uset.find (&deEnd))
    {
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Found the elements\n")));
    }

  // Iterate and destroy the elements in the set.
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Deleting the elements\n")));
  ACE_Unbounded_Set_Iterator<DataElement*> iter (uset);
  for (iter = uset.begin (); iter != uset.end (); iter++)
    {
      DataElement* elem = (*iter);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), elem->getData ()));
      delete elem;
    }

  return 0;
}
int Tree_Example::run ()
{
  ACE_TRACE (ACE_TEXT ("Tree_Example::run"));

  DataElement *d  = 0;
  for (int i = 0; i < 100; i++)
    {
      ACE_NEW_RETURN (d, DataElement (i), -1);
      int result = tree_.bind(i, d);
      if (result != 0)
        {
          ACE_ERROR_RETURN((LM_ERROR, "%p\n", "Bind"), -1);
        }
    }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Using find: \n")));
  for (int j = 0; j < 100; j++)
    {
      DataElement* d;
      int result = tree_.find (j, d);
      if (result != 0)
        {
          ACE_ERROR_RETURN((LM_ERROR, "%p\n", "Find"), -1);
        }
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), d->getData ()));
    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));

  // Use the forward iterator.
  this->iterate_forward ();

  // Use the reverse iterator.
  this->iterate_reverse ();

  // Remove all elements from the tree.
  ACE_ASSERT (this->remove_all ()!= -1);

  // Iterate through once again.
  this->iterate_forward ();

  return 0;
}
Esempio n. 6
0
// Listing 1
// Listing 2 code/ch05
int StackExample::runFixedStack (void)
{
  ACE_TRACE (ACE_TEXT ("StackExample::runFixedStack"));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Using a fixed stack\n")));

  ACE_Fixed_Stack<DataElement*, 100> fstack;
  for (int k = 0; k < 100; k++)
    {
      DataElement* elem;
      ACE_NEW_RETURN(elem, DataElement (k), -1);
      fstack.push (elem);    // Push the element on the stack.
    }

  for (int l = 0; l < 100; l++)
    {
      DataElement* elem = 0;
      fstack.pop (elem);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), elem->getData ()));
      delete elem;
    }

  return 0;
}
int Map_Example::run (void)
{
  ACE_TRACE (ACE_TEXT ("Map_Example::run"));

  // Corresponding KeyType objects are created on the fly.
  for (int i = 0; i < 100; i++)
    {
      map_.bind (i, DataElement (i));
    }

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Map has\n")));
  for (int j = 0; j < 100; j++)
    {
      DataElement d;
      int result = map_.find (j,d);
      if (result == 0)
        {
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), d.getData ()));
        }
    }
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));

  // Iterate in the forward direction.
  this->iterate_forward ();

  // Iterate in the other direction.
  this->iterate_reverse ();

  // Remove all elements from the map.
  this->remove_all ();

  // Iterate in the forward direction.
  this->iterate_forward ();

  return 0;
}