VectorMap.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef __VECTORMAP_H__
00018 #define __VECTORMAP_H__
00019 
00020 #include <vector>
00021 
00022 namespace oasys {
00023 
00024 template <typename _Type>
00025 class vector_map {
00026 public:
00027     typedef std::vector<_Type> EntVector;
00028     
00029     vector_map() {}
00030     
00031     template <typename _Predicate>
00032     bool exists(_Predicate eq) const {
00033         EntVector::const_iterator i = std::find_if(ents_.begin(), ents_.end(), eq);
00034         return i != ents_.end();
00035     }
00036 
00037     template <typename _Predicate>
00038     bool insert(_Predicate eq, const _Type& type) {
00039         EntVector::iterator i = std::find_if(ents_.begin(), ents_.end(), eq);
00040         if (i == ents_.end()) 
00041         {
00042             ents_.push_back(type);
00043             return false;
00044         }
00045         else
00046         {
00047             *i = type;
00048             return true;
00049         }
00050     }
00051 
00052     template <typename _Predicate>
00053     const Type& get(_Predicate eq) const {
00054         EntVector::const_iterator i = std::find_if(ents_.begin(), ents_.end(), eq);
00055         return *i;
00056     }
00057 
00058 private:
00059     EntVector ents_;
00060 }; 
00061 
00062 } // namespace oasys
00063 
00064 #if 1 
00065 
00066 #include <cstdio>
00067 
00068 class Equals(int i) 
00069 {
00070     
00071 }
00072 
00073 int
00074 main(int argc, char* argv[])
00075 {
00076     oasys::vector_map<int> vm;
00077 
00078     
00079     if (vm.exists(
00080 }
00081 
00082 #endif
00083 
00084 #endif /* __VECTORMAP_H__ */

Generated on Sat Sep 8 08:36:18 2007 for DTN Reference Implementation by  doxygen 1.5.3