Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members  

bclist.cpp

Go to the documentation of this file.
00001 // $Id$
00002 
00003 //**********************************************************************
00004 //                                                                     *
00005 //    Description:   List class to hold instances of BellCode class.   *
00006 //                                                                     *
00007 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00008 //                                                                     *
00009 //    Copyright (C) 2003  Monitor Computing Services Ltd.              *
00010 //                                                                     *
00011 //    This program is free software; you can redistribute it and/or    *
00012 //    modify it under the terms of the GNU General Public License      *
00013 //    as published by the Free Software Foundation; either version 2   *
00014 //    of the License, or any later version.                            *
00015 //                                                                     *
00016 //    This program is distributed in the hope that it will be useful,  *
00017 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00018 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00019 //    GNU General Public License for more details.                     *
00020 //                                                                     *
00021 //    You should have received a copy of the GNU General Public        *
00022 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00023 //    program; if not, write to:                                       *
00024 //       The Free Software Foundation Inc.,                            *
00025 //       59 Temple Place - Suite 330,                                  *
00026 //       Boston, MA  02111-1307,                                       *
00027 //       USA.                                                          *
00028 //                                                                     *
00029 //**********************************************************************
00030 //                                                                     *
00031 //    Notes:                                                           *
00032 //                                                                     *
00033 //**********************************************************************
00034 
00035 #include <classlib\listimp.h>
00036 
00037 #include "mytrace.h"
00038 #include "bellcode.h"
00039 
00040 #include "bclist.h"
00041 
00042 
00043 using namespace Monitor::BellMaster;
00044 
00045 
00046 
00047 BellCodeList::BellCodeList() :
00048     myList(0), listSize(0)
00049 {
00050     _USEMYTRACE_("BellCodeList::BellCodeList()")
00051 }
00052 
00053 
00054 
00055 BellCodeList::BellCodeList(const BellCodeList&    other) :
00056     myList(0), listSize(0)
00057 {
00058     _USEMYTRACE_("BellCodeList::BellCodeList(other)")
00059 
00060 
00061     operator=(other);
00062 }
00063 
00064 
00065 
00066 BellCodeList::~BellCodeList()
00067 {
00068     _USEMYTRACE_("BellCodeList::~BellCodeList")
00069 
00070     clear();
00071 }
00072 
00073 
00074 
00075 const BellCodeList&
00076 BellCodeList::operator=(const BellCodeList&    other)
00077 {
00078     _USEMYTRACE_("BellCodeList::operator=(other)")
00079 
00080 
00081     clear();
00082 
00083 
00084     TSListIteratorImp< BellCode >    otherCodes(other.getList());
00085 
00086 
00087     while (0 != otherCodes)
00088     {
00089         addBellCode(otherCodes.Current());
00090 
00091         otherCodes++;
00092     }
00093 
00094     return *this;
00095 }
00096 
00097 
00098 
00099 void
00100 BellCodeList::addBellCode(const BellCode    &newBellCode)
00101 {
00102     _USEMYTRACE_("BellCodeList::addBellCode")
00103 
00104     getList().Add(newBellCode);
00105     listSize++;
00106 }
00107 
00108 
00109 
00110 void
00111 BellCodeList::removeBellCode(const BellCode    &oldBellCode)
00112 {
00113     _USEMYTRACE_("BellCodeList::removeBellCode")
00114 
00115     getList().Detach(oldBellCode);
00116     listSize--;
00117 }
00118 
00119 
00120 
00121 void
00122 BellCodeList::clear()
00123 {
00124     _USEMYTRACE_("BellCodeList::clear")
00125 
00126     delete myList, myList = 0;
00127     listSize = 0;
00128 }
00129 
00130 
00131 
00132 const unsigned&
00133 BellCodeList::size() const
00134 {
00135     return listSize;
00136 }
00137 
00138 
00139 
00140 BellCode&
00141 BellCodeList::operator[](int    index) const
00142 {
00143     TSListIteratorImp< BellCode >    bellCodes(getList());
00144 
00145     while (0 < index)
00146     {
00147         index--;
00148         bellCodes++;
00149     }
00150 
00151     return const_cast< BellCode& >(bellCodes.Current());
00152 }
00153 
00154 
00155 const BellCodeList
00156 BellCodeList::matchSequence(const string&    sequence) const
00157 {
00158     _USEMYTRACE_("BellCodeList::matchSequence(sequence)")
00159 
00160 
00161     BellCodeList                     matchedCodes;
00162     TSListIteratorImp< BellCode >    bellCodes(getList());
00163 
00164 
00165     while (0 != bellCodes)
00166     {
00167         if (bellCodes.Current().matchesSequence(sequence))
00168         {
00169             matchedCodes.addBellCode(bellCodes.Current());
00170         }
00171 
00172         bellCodes++;
00173     }
00174 
00175     return matchedCodes;
00176 }
00177 
00178 
00179 
00180 TSListImp< BellCode >&
00181 BellCodeList::getList() const
00182 {
00183     if (0 == myList)
00184     {
00185         const_cast< BellCodeList* >(this)->myList =
00186             new TSListImp< BellCode >;
00187 
00188         const_cast< BellCodeList* >(this)->listSize = 0;
00189     }
00190 
00191     return *myList;
00192 }
00193 

Generated on Wed Oct 29 20:54:52 2003 for Bellmaster BC Common by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002