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.
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!
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_
++;
35 this->current_ptr_
= 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.
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!
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;
66 Binary_Search::~Binary_Search ()
68 if (Options::get_opt (Options::DEBUGGING
))
70 "disposing Binary_Search\n"));
73 // Used to initialize the values for the iterators...
75 Binary_Search::Binary_Search ()