예제 #1
0
int
run_main (int, ACE_TCHAR *[])
{
  int ret = 0;
  int *ptr = 0;

  ACE_START_TEST (ACE_TEXT ("OrdMultiSet_Test"));

  // make an empty set of int and an iterator
  ACE_Ordered_MultiSet<int> set;
  ACE_Ordered_MultiSet_Iterator<int> iter(set);

  // Put in a range of odd ints, without an iterator.
  int i;
  for (i = -10; i < 10; ++i)
    set.insert (2 * i + 1);

  // Put in an interleaved range of even ints, using an iterator.
  for (i = -10; i <= 10; ++i)
    set.insert (2 * i, iter);

  // Remove the first and last elements of range.
  while (set.remove (-20) == 0);
  while (set.remove (20) == 0);

  // Should still have 39 elements in the set.
  ACE_ASSERT (set.is_empty () == 0);
  ACE_ASSERT (set.size () == 39);

  // Iterate forward through the range we created: should be one of
  // each.
  iter.first ();
  for (i = -19; i <= 19; ++i)
    {
      // we should still be in the set
      ACE_ASSERT (iter.done () == 0);

      // make sure the current element is what we expect
      iter.next (ptr);
      ACE_ASSERT (ptr != 0);
      ACE_ASSERT (*ptr == i);

      // move to the next element in the set
      iter.advance ();
    }

  // We should have iterated through the entire set.
  ACE_ASSERT (iter.done () != 0);

  // Iterate backward through the range we created: should be one of
  // each.
  iter.last ();
  for (i = 19; i >= -19; --i)
    {
      // We should still be in the set.
      ACE_ASSERT (iter.done () == 0);

      // Make sure the current element is what we expect.
      int *ptr = 0;
      iter.next (ptr);
      ACE_ASSERT (ptr != 0);
      ACE_ASSERT (*ptr == i);

      // Move to the previous element in the set.
      iter.retreat ();
    }

  // We should have iterated through the entire set.
  ACE_ASSERT (iter.done () != 0);

  // Iterate through the set and use the operator* to get the element
  iter.first ();
  for (i = -19; i <= 19; ++i)
    {
      // we should still be in the set
      ACE_ASSERT (iter.done () == 0);

      // make sure the current element is what we expect
      int& l = *iter;
      ACE_ASSERT (l == i);

      // move to the next element in the set
      iter.advance ();
    }

  // We should have iterated through the entire set.
  ACE_ASSERT (iter.done () != 0);

  // Clear the set, restart the iterator, and make sure the iterator
  // is out of range at both ends, the set is empty, and a subsequent
  // advance or retreat on an out of range iterator does not cause
  // problems
  set.reset ();
  ACE_ASSERT (set.is_empty () != 0);
  iter.first ();
  ACE_ASSERT (iter.done () != 0);
  iter.retreat ();
  iter.last ();
  ACE_ASSERT (iter.done () != 0);
  iter.advance ();

  // Put in a bunch of ints in various relative positions, using an
  // iterator for the odds and no iterator for the evens.
  set.insert (203, iter);
  set.insert (202);
  set.insert (204);
  set.insert (201, iter);
  set.insert (205, iter);

  set.insert (203, iter);
  set.insert (203, iter);

  set.insert (204);
  set.insert (204);
  set.insert (204);
  set.insert (205, iter);
  set.insert (205, iter);
  set.insert (205, iter);
  set.insert (205, iter);
  set.insert (202);

  // remove the middle elements
  while (set.remove (204) == 0);
  while (set.remove (202) == 0);
  while (set.remove (203) == 0);

  // Put the iterator out of range and make sure it stays
  // that way for finds on the missing elements.
  iter.last ();
  iter.advance ();
  set.find (203, iter);
  ACE_ASSERT (iter.done () != 0);
  set.find (202, iter);
  ACE_ASSERT (iter.done () != 0);
  set.find (204, iter);
  ACE_ASSERT (iter.done () != 0);

  // Make sure the other elements can be found.
  set.find (205, iter);
  ACE_ASSERT (iter.done () == 0);
  iter.next (ptr);
  ACE_ASSERT (ptr != 0);
  ACE_ASSERT (*ptr == 205);
  set.find (201, iter);
  ACE_ASSERT (iter.done () == 0);
  iter.next (ptr);
  ACE_ASSERT (ptr != 0);
  ACE_ASSERT (*ptr == 201);

  // Finally, iterate through the set and make sure its contents are
  // correct (one 201 and five 205s).
  iter.first ();
  ACE_ASSERT (iter.done () == 0);
  iter.next (ptr);
  ACE_ASSERT (ptr != 0);
  ACE_ASSERT (*ptr == 201);
  iter.advance ();

  for (i = 1; i <= 5; ++i)
    {
      // Should be in the set, able to access the element, value
      // should be 205
      ACE_ASSERT (iter.done () == 0);
      iter.next (ptr);
      ACE_ASSERT (ptr != 0);
      ACE_ASSERT (*ptr == 205);

      // Move to the next element in the set.
      iter.advance ();
    }

  // Should not be anything else in the set.
  ACE_ASSERT (iter.done () != 0);

  // remove the rest
  while (set.remove (205) == 0);
  while (set.remove (201) == 0);

  // Should have no more elements in the set.
  ACE_ASSERT (set.is_empty () != 0);
  ACE_ASSERT (set.size () == 0);
  iter.first ();
  ACE_ASSERT (iter.done () != 0);
  iter.last ();
  ACE_ASSERT (iter.done () != 0);

  ACE_END_TEST;

  return ret;
}
예제 #2
0
파일: SchedEntry.cpp 프로젝트: asdlei00/ACE
int
Task_Entry::merge_frames (ACE_Unbounded_Set <Dispatch_Entry *> &dispatch_entries,
                          Task_Entry &owner,
                          ACE_Ordered_MultiSet <Dispatch_Entry_Link> &dest,
                          ACE_Ordered_MultiSet <Dispatch_Entry_Link> &src,
                          u_long &dest_period,
                          u_long src_period,
                          u_long number_of_calls,
                          u_long starting_dest_sub_frame)
{
  int status = 0;

  // reframe dispatches in the destination set to the new frame size
  // (expands the destination set's period to be the new enclosing frame)
  if (reframe (dispatch_entries,
               owner,
               dest,
               dest_period,
               ACE::minimum_frame_size (dest_period,
                                        src_period)) < 0)
      return -1;

  // use iterator for efficient insertion into the destination set
  ACE_Ordered_MultiSet_Iterator <Dispatch_Entry_Link> dest_iter (dest);

  // do virtual iteration over the source set in the new frame, adding
  // adjusted dispatch entries to the destination
  Dispatch_Proxy_Iterator src_iter (src,
                                    src_period,
                                    dest_period,
                                    number_of_calls,
                                    starting_dest_sub_frame);

  for (src_iter.first (starting_dest_sub_frame);
       src_iter.done () == 0;
       src_iter.advance ())
    {
      // Policy: disjunctively dispatched operations get their
      // deadline and priority from the original dispatch - when and
      // if it is useful to change any of the merge policies, this
      // should be one of the decisions factored out into the
      // disjunctive merge strategy class.

      Dispatch_Entry *entry_ptr;
      ACE_NEW_RETURN (entry_ptr,
                      Dispatch_Entry (src_iter.arrival (),
                                      src_iter.deadline (),
                                      src_iter.priority (),
                                      src_iter.OS_priority (),
                                      owner),
                      -1);

      // if even one new dispatch was inserted, status is "something happened".
      status = 1;

      // add the new dispatch entry to the set of all dispatches, and
      // a link to it to the dispatch links for this task entry
      if (dispatch_entries.insert (entry_ptr) < 0)
        return -1;

      else if (dest.insert (Dispatch_Entry_Link (*entry_ptr), dest_iter) < 0)
        return -1;

      // TBD - Clients are not assigned priority, but rather obtain it
      // from their call dependencies.  We could complain here if
      // there is a priority specified that doesn't match (or is lower
      // QoS?)
    }

  return status;
}
예제 #3
0
파일: yarpfs.cpp 프로젝트: apaikan/yarp
int yarp_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
                 off_t offset, struct fuse_file_info *fi)
{
    (void) offset;
    (void) fi;

    printf(">>>>>>>>>>>READING DIR\n");


    filler(buf, ".", NULL, 0);
    filler(buf, "..", NULL, 0);

    YPath ypath(path);

    if (ypath.isPort()) {
        filler(buf, "rw", NULL, 0);
        //filler(buf, "write", NULL, 0); //deprecated
        //filler(buf, "status", NULL, 0);
        return 0;
    }

    NameConfig nc;

    ConstString name = nc.getNamespace();
    Bottle msg, reply;
    msg.addString("bot");
    msg.addString("list");
    Network::write(name.c_str(),
                   msg,
                   reply);

    printf("Got %s\n", reply.toString().c_str());

    ACE_Ordered_MultiSet<ConstString> lines;


    for (int i=1; i<reply.size(); i++) {
        Bottle *entry = reply.get(i).asList();
        string rpath = path;
        if (rpath[rpath.length()-1]!='/') {
            rpath = rpath + "/";
        }
        if (entry!=NULL) {
            ConstString name = entry->check("name",Value("")).asString();
            if (name!="") {
                if (strstr(name.c_str(),rpath.c_str())==
                           name.c_str()) {
                    printf(">>> %s is in path %s\n", name.c_str(),
                           rpath.c_str());
                    ConstString part(name.c_str()+rpath.length());
                    if (part[0]=='/') {
                        part = part.substr(1,part.length()-1);
                    }
                    printf("    %s is the addition\n", part.c_str());

                    char *brk = (char*)strstr(part.c_str(),"/");
                    if (brk!=NULL) {
                        *brk = '\0';
                    }
                    ConstString item(part.c_str());
                    printf("    %s is the item\n", item.c_str());
                    if (item!="") {
                        lines.remove(item);
                        lines.insert(item);
                    }
                }
            }
        }
    }

    // return result in alphabetical order
    ACE_Ordered_MultiSet_Iterator<ConstString> iter(lines);
    iter.first();
    while (!iter.done()) {
        printf("adding item %s\n", (*iter).c_str());
        filler(buf, (*iter).c_str(), NULL, 0);
        iter.advance();
    }

    return 0;
}