00001 // Filename: iterator_types.h 00002 // Created by: drose (10Feb99) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef ITERATOR_TYPES_H 00020 #define ITERATOR_TYPES_H 00021 00022 00023 //////////////////////////////////////////////////////////////////// 00024 // Class : first_of_pair_iterator 00025 // Description : This is an iterator adaptor that converts any 00026 // iterator that returns a pair (e.g. a map iterator) 00027 // into one that returns just the first component of 00028 // that pair. 00029 //////////////////////////////////////////////////////////////////// 00030 template<class pair_iterator> 00031 class first_of_pair_iterator : public pair_iterator { 00032 public: 00033 typedef TYPENAME pair_iterator::value_type::first_type value_type; 00034 00035 first_of_pair_iterator() { } 00036 first_of_pair_iterator(const pair_iterator &init) : pair_iterator(init) { } 00037 first_of_pair_iterator(const first_of_pair_iterator<pair_iterator> ©) : pair_iterator(copy) { } 00038 00039 value_type operator *() { 00040 return pair_iterator::operator *().first; 00041 } 00042 }; 00043 00044 //////////////////////////////////////////////////////////////////// 00045 // Class : second_of_pair_iterator 00046 // Description : This is an iterator adaptor that converts any 00047 // iterator that returns a pair (e.g. a map iterator) 00048 // into one that returns just the second component of 00049 // that pair. 00050 //////////////////////////////////////////////////////////////////// 00051 template<class pair_iterator> 00052 class second_of_pair_iterator : public pair_iterator { 00053 public: 00054 typedef TYPENAME pair_iterator::value_type::second_type value_type; 00055 00056 second_of_pair_iterator() { } 00057 second_of_pair_iterator(const pair_iterator &init) : pair_iterator(init) { } 00058 second_of_pair_iterator(const second_of_pair_iterator<pair_iterator> ©) : pair_iterator(copy) { } 00059 00060 value_type operator *() { 00061 return pair_iterator::operator *().second; 00062 } 00063 }; 00064 00065 //////////////////////////////////////////////////////////////////// 00066 // Class : typecast_iterator 00067 // Description : This is an iterator adaptor that explicitly typecasts 00068 // each value returned by the base iterator to the 00069 // indicated type. 00070 //////////////////////////////////////////////////////////////////// 00071 template<class base_iterator, class new_type> 00072 class typecast_iterator : public base_iterator { 00073 public: 00074 typedef new_type value_type; 00075 00076 typecast_iterator() { } 00077 typecast_iterator(const base_iterator &init) : base_iterator(init) { } 00078 typecast_iterator(const typecast_iterator<base_iterator, new_type> ©) : base_iterator(copy) { } 00079 00080 value_type operator *() { 00081 return (new_type)base_iterator::operator *(); 00082 } 00083 }; 00084 00085 #endif
1.3