| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeComposite.h
Go to the documentation of this file.

    00001 /************************************************************************************
    00002 TerraLib - a library for developing GIS applications.
    00003 Copyright © 2001-2007 INPE and Tecgraf/PUC-Rio.
    00004
    00005 This code is part of the TerraLib library.
    00006 This library is free software; you can redistribute it and/or
    00007 modify it under the terms of the GNU Lesser General Public
    00008 License as published by the Free Software Foundation; either
    00009 version 2.1 of the License, or (at your option) any later version.
    00010
    00011 You should have received a copy of the GNU Lesser General Public
    00012 License along with this library.
    00013
    00014 The authors reassure the license terms regarding the warranties.
    00015 They specifically disclaim any warranties, including, but not limited to,
    00016 the implied warranties of merchantability and fitness for a particular purpose.
    00017 The library provided hereunder is on an "as is" basis, and the authors have no
    00018 obligation to provide maintenance, support, updates, enhancements, or modifications.
    00019 In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
    00020 indirect, special, incidental, or consequential damages arising out of the use
    00021 of this library and its documentation.
    00022 *************************************************************************************/
    00027 #ifndef  __TERRALIB_INTERNAL_COMPOSITE_H
    00028 #define  __TERRALIB_INTERNAL_COMPOSITE_H
    00029
    00030 #include "TeCounted.h"
    00031
    00032 #include <vector>
    00033 #include <algorithm>
    00034 using namespace std;
    00035
    00037 template <class T>
    00038 class TeSingle
    00039 {
    00040 public:
    00042            TeSingle<T>() {}
    00043
    00045            virtual ~TeSingle<T>() {}
    00046
    00048            TeSingle<T> ( T& elem ): elem_ ( elem  ) {}
    00049
    00051            void add ( T& elem )
    00052            {          elem_ = elem; }
    00053
    00055            T&         location ()
    00056            {          return elem_; }
    00057
    00059            const T& location() const
    00060            {
    00061                       return elem_;
    00062            }
    00063
    00065            T&         elem ()
    00066            {          return elem_; }
    00067
    00068 protected:
    00069            T          elem_;
    00070
    00071 };
    00072
    00074
    00084 template <class T>
    00085 class TeComposite: public TeCounted
    00086 {
    00087 public:
    00088
    00089            using TeCounted::attach;
    00090            using TeCounted::detach;
    00091
    00093            typedef typename vector<T>::iterator iterator;
    00094            typedef typename vector<T>::const_iterator const_iterator;
    00095
    00097            void add ( const T& elem )
    00098            { components_.push_back ( elem ); }
    00099
    00101            bool erase ( unsigned int i )
    00102            {
    00103                       if ( components_.size() < i )
    00104                                  return false;
    00105                       return ! ( components_.erase ( components_.begin() + i ) == components_.end() );
    00106            }
    00107
    00109
    00112            bool erase ( T& elem )
    00113            {
    00114                       typename vector<T>::iterator location = find(components_.begin(),components_.end(), elem);
    00115                       if ( location != components_.end())
    00116                       {
    00117                                  components_.erase(location);
    00118                                  return true;
    00119                       }
    00120                       else
    00121                                  return false;
    00122            }
    00123
    00125            iterator erase(iterator it)
    00126            {
    00127                       return components_.erase(it);
    00128            }
    00129
    00131            void clear ()
    00132            {          components_.clear (); }
    00133
    00135            size_t size() const
    00136            { return components_.size(); }
    00137
    00139            T& operator [] ( int i )
    00140            { return components_[ i ]; }
    00141
    00143            bool empty() const
    00144            { return components_.empty(); }
    00145
    00147            void reserve(int nelem)
    00148            { components_.reserve(nelem); }
    00149
    00151            iterator begin(void)
    00152            {
    00153                       return components_.begin();
    00154            }
    00155
    00157     iterator end(void)
    00158            {
    00159                       return components_.end();
    00160            }
    00161
    00163            typedef typename vector<T>::reverse_iterator reverse_iterator;
    00164
    00166            reverse_iterator rbegin(void)
    00167            {
    00168                       return components_.rbegin();
    00169            }
    00170
    00172     reverse_iterator rend(void)
    00173            {
    00174                       return components_.rend();
    00175            }
    00176
    00177
    00178 protected:
    00179            vector<T>  components_;
    00180 };
    00181
    00182 #endif
    00183
    00184

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines