Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / apps / drwho / Binary_Search.cpp
blob338b3540fbe771c502ff7cf1645601eb43cf2723
1 #include "Options.h"
2 #include "Binary_Search.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_string.h"
6 // This function is passed to qsort to perform the comparison between
7 // login names for two friends.
9 int
10 Binary_Search::name_compare (const void *s1, const void *s2)
12 return ACE_OS::strcmp ((*(Protocol_Record **) s1)->key_name1_,
13 (*(Protocol_Record **) s2)->key_name1_);
16 // Returns the next friend in the sequence of sorted friends. Note
17 // that this function would be simplified if we expanded the iterator
18 // interface to include an "initialize" and "next" function!
20 Protocol_Record *
21 Binary_Search::get_next_entry ()
23 // Reset the iterator if we are starting from the beginning.
25 if (this->current_ptr_ == 0)
26 this->current_ptr_ = this->sorted_record_;
28 // Now check to see if we've hit the end, in which case we set
29 // things up for the next round!
31 if (this->current_ptr_ < this->sorted_record_ + this->count_)
32 return *this->current_ptr_++;
33 else
35 this->current_ptr_ = 0;
36 return 0;
40 // An iterator, similar to Binary_Search::get_next_friend, though in
41 // this case the friend records are returned in the order they
42 // appeared in the friend file, rather than in sorted order. Also, we
43 // skip over entries that don't have any hosts associated with them.
45 Protocol_Record *
46 Binary_Search::get_each_entry ()
48 // Reset the iterator if we are starting from the beginning.
50 if (this->current_index_ == -1)
51 this->current_index_ = 0;
53 // Now check to see if we've hit the end, in which case we set
54 // things up for the next round!
56 for (;
57 this->current_index_ < this->count_;
58 this->current_index_++)
59 if (this->protocol_record_[this->current_index_].drwho_list_ != 0)
60 return &this->protocol_record_[this->current_index_++];
62 this->current_index_ = -1;
63 return 0;
66 Binary_Search::~Binary_Search ()
68 if (Options::get_opt (Options::DEBUGGING))
69 ACE_DEBUG ((LM_DEBUG,
70 "disposing Binary_Search\n"));
73 // Used to initialize the values for the iterators...
75 Binary_Search::Binary_Search ()
76 : current_ptr_ (0),
77 current_index_ (0)