1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// gqbArrayCollection.cpp - Implementation of Collection Using Arrays
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin3.h"
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "gqb/gqbArrayCollection.h"
#include "gqb/gqbObject.h"
// Destructor
gqbArrayCollection::~gqbArrayCollection()
{
WX_CLEAR_ARRAY(gqbArray);
}
// Add item to array
void gqbArrayCollection::addItem(gqbObject *item)
{
gqbArray.Add(item);
}
// Remove item from array but don't delete it.
void gqbArrayCollection::removeItem(gqbObject *item)
{
gqbArray.Remove(item);
}
// Create an iterator for the objects inside the array
gqbIteratorBase *gqbArrayCollection::createIterator()
{
return (new gqbArrayIterator(&gqbArray));
}
// Create a Down to iterator for the objects inside the array
gqbIteratorBase *gqbArrayCollection::createDownIterator()
{
return (new gqbArrayDownIterator(&gqbArray));
}
// Return the number of elements inside the array
int gqbArrayCollection::count()
{
return gqbArray.Count();
}
// Return true if an element pointer is found inside array
bool gqbArrayCollection::existsObject(gqbObject *item)
{
gqbObject *found = NULL;
int size = gqbArray.GetCount();
for(int i = 0; i < size; i++)
{
if (gqbArray.Item(i) == item)
{
found = gqbArray.Item(i);
break;
}
}
if(found)
return true;
else
return false;
}
// Delete all elements inside array
void gqbArrayCollection::deleteAll()
{
WX_CLEAR_ARRAY(gqbArray);
}
// Removes all elements inside array without deleting
void gqbArrayCollection::removeAll()
{
gqbArray.Empty();
}
// Get Item at certain position at Collection
gqbObject *gqbArrayCollection::getItemAt(int index)
{
if(!gqbArray.IsEmpty())
return gqbArray.Item(index);
else
return NULL;
}
int gqbArrayCollection::getIndex(gqbObject *item)
{
return gqbArray.Index(item);
}
// Insert item into the array before the index
void gqbArrayCollection:: insertAtIndex(gqbObject *item, int index)
{
gqbArray.Insert(item, index);
}
//
// gqbArrayIterator - Manages iterator for the array collection concrete class, from first to last element
//
// Constructor
gqbArrayIterator::gqbArrayIterator(gqbObjsArray *gqbPtrsArray)
{
position = 0;
internalArray = gqbPtrsArray;
}
// Get next item in the array for the iterator
gqbObject *gqbArrayIterator::Next()
{
gqbObject *obj = internalArray->Item(position);
position++;
return obj;
}
// Return true if the array has more elements to return
bool gqbArrayIterator::HasNext()
{
int size = internalArray->GetCount();
if( (size > 0) && (position <= (size - 1)) )
return true;
else
return false;
}
void gqbArrayIterator::ResetIterator()
{
position = 0;
}
//
// gqbArrayDownIterator - Manages iterator for the array collection concrete class from last to first element
//
// Constructor
gqbArrayDownIterator::gqbArrayDownIterator(gqbObjsArray *gqbPtrsArray)
{
internalArray = gqbPtrsArray;
position = internalArray->GetCount() - 1;
}
// Get next item in the array for the iterator
gqbObject *gqbArrayDownIterator::Next()
{
gqbObject *obj = internalArray->Item(position);
position--;
return obj;
}
// Return true if the array has more elements to return
bool gqbArrayDownIterator::HasNext()
{
int size = internalArray->GetCount();
if( (size > 0) && (position <= (size - 1) && position >= 0) )
return true;
else
return false;
}
void gqbArrayDownIterator::ResetIterator()
{
position = internalArray->GetCount() - 1;
}
|