Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / apps / soreduce / Sig_List.cpp
blobe7b8bf01dfe7dcd8765be49c5ce01c4ff0935610
1 // File: Sig_List.cpp
3 // Author: Phil Mesnier
5 #include "ace/OS_NS_string.h"
6 #include "Sig_List.h"
8 //-----------------------------------------------------------------------------
10 Sig_List::Sig_List (int cap)
11 : size_(0),
12 capacity_(cap),
13 index_(0),
14 has_nulls_(0),
15 modified_(0),
16 array_(0)
18 array_ = new Signature*[capacity_];
21 Sig_List::~Sig_List ()
23 for (int i = 0; i < size_; i++)
24 if (array_[i]) array_[i]->release();
25 delete [] array_;
28 void
29 Sig_List::add (const ACE_CString &s)
31 if (this->index_of (s) != -1)
32 return;
33 modified_ = 1;
34 if (has_nulls_)
35 for (int i = 0; i < size_; i++)
36 if (array_[i] == 0) {
37 array_[i] = new Signature (s);
38 has_nulls_ --;
39 return;
41 if (size_ == capacity_) {
42 int ncap = capacity_ * 2;
43 Signature ** narray = new Signature *[ncap];
44 ACE_OS::memcpy (narray,array_,capacity_ * sizeof(Signature*));
45 delete [] array_;
46 array_ = narray;
47 capacity_ = ncap;
49 array_[size_++] = new Signature(s);
52 void
53 Sig_List::add (const Sig_List &other)
55 if (capacity_ < size_ + other.capacity_) {
56 int ncap = size_ + other.capacity_ + 50;
57 Signature ** narray = new Signature *[ncap];
58 ACE_OS::memcpy (narray,array_,capacity_ * sizeof(Signature*));
59 delete [] array_;
60 array_ = narray;
61 capacity_ = ncap;
63 modified_ = 1;
64 for (int i = 0; i < other.size_; i++)
65 if (other.array_[i] != 0 &&
66 this->index_of (other.array_[i]->name()) == -1)
68 if (!has_nulls_)
69 array_[size_++] = other.array_[i]->dup();
70 else
71 for (int i = 0; i < size_; i++)
72 if (array_[i] == 0)
74 array_[i] = other.array_[i]->dup();
75 has_nulls_ --;
76 break;
81 void
82 Sig_List::remove (const Signature &s)
84 for (int i = 0; i < size_; i++)
85 if (array_[i] && array_[i]->name() == s.name()) {
86 array_[i]->release();
87 array_[i] = 0;
88 modified_ = 1;
89 if (i == size_ - 1)
90 size_ --;
91 else
92 has_nulls_ ++;
93 break;
97 void
98 Sig_List::remove_current ()
100 array_[index_]->release();
101 array_[index_] = 0;
102 modified_ = 1;
103 if (index_ == size_ - 1)
104 size_--;
105 else
106 has_nulls_++;
110 Sig_List::index_of (const Signature *s)
112 for (int i = 0; i < size_; i++)
113 if (array_[i] && array_[i]->name() == s->name()) {
114 array_[i]->used();
115 return i;
117 return -1;
121 Sig_List::index_of (const ACE_CString &s)
123 for (int i = 0; i < size_; i++)
124 if (array_[i] && array_[i]->name() == s) {
125 return i;
127 return -1;
131 const Signature *
132 Sig_List::first()
134 for (index_ = 0; index_ < size_; index_++)
135 if (array_[index_] != 0)
136 return array_[index_];
137 return 0;
140 const Signature *
141 Sig_List::next()
143 for (++index_; index_ < size_; index_++)
144 if (array_[index_] != 0)
145 return array_[index_];
146 return 0;
150 Sig_List::hasmore ()
152 return index_ < size_;
156 Sig_List::size()
158 return size_;
162 Sig_List::modified()
164 int rtn = modified_;
165 modified_ = 0;
166 int insert = 0;
167 if (has_nulls_) {
168 for (int i = 0; i < size_; i++)
169 if (array_[i] != 0) {
170 if (i != insert) {
171 array_[insert] = array_[i];
172 array_[i] = 0;
174 insert++;
176 size_ = insert+1;
177 has_nulls_ = 0;
179 return rtn;