osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #ifndef OSGEARTHSYMBOLOGY_TAGS_H 00021 #define OSGEARTHSYMBOLOGY_TAGS_H 1 00022 00023 #include <osgEarthSymbology/Common> 00024 #include <osgEarth/StringUtils> 00025 #include <vector> 00026 #include <set> 00027 #include <algorithm> 00028 00029 namespace osgEarth { namespace Symbology 00030 { 00031 typedef std::vector<std::string> TagVector; 00032 typedef std::set<std::string> TagSet; 00033 00034 template<typename T> 00035 class Taggable : public T 00036 { 00037 public: 00038 void addTag( const std::string& tag ) { 00039 _tags.insert( normalize( tag ) ); 00040 } 00041 void addTags( const TagVector& tags ) { 00042 for( TagVector::const_iterator i = tags.begin(); i != tags.end(); ++i ) 00043 _tags.insert( normalize(*i) ); 00044 } 00045 void addTags( const std::string& tagString ) { 00046 TagVector tags; 00047 StringTokenizer( tagString, tags, " ", "\"'", false, true ); 00048 addTags( tags ); 00049 } 00050 void removeTag( const std::string& tag ) { 00051 _tags.erase( normalize( tag ) ); 00052 } 00053 bool containsTag( const std::string& tag ) const { 00054 return _tags.find( normalize( tag )) != _tags.end(); 00055 } 00056 00057 bool containsTags( const TagSet& tags) const { 00058 for( TagSet::const_iterator i = tags.begin(); i != tags.end(); i++ ) { 00059 if ( _tags.find( normalize( *i ) ) == _tags.end() ) 00060 return false; 00061 } 00062 return true; 00063 } 00064 00065 bool containsTags( const TagVector& tags) const { 00066 for( TagVector::const_iterator i = tags.begin(); i != tags.end(); i++ ) { 00067 if ( _tags.find( normalize( *i ) ) == _tags.end() ) 00068 return false; 00069 } 00070 return true; 00071 } 00072 00073 const TagSet& tags() const { return _tags; } 00074 00075 static std::string tagString(const TagSet& tags) { 00076 std::stringstream buf; 00077 for( TagSet::const_iterator i = tags.begin(); i != tags.end(); i++ ) 00078 buf << (i != tags.begin()? " " : "") << *i; 00079 std::string result = buf.str(); 00080 return result; 00081 } 00082 00083 static std::string tagString(const TagVector& tags) { 00084 std::stringstream buf; 00085 for( TagVector::const_iterator i = tags.begin(); i != tags.end(); i++ ) 00086 buf << (i != tags.begin()? " " : "") << *i; 00087 std::string result = buf.str(); 00088 return result; 00089 } 00090 00091 std::string tagString() const { 00092 std::stringstream buf; 00093 for( TagSet::const_iterator i = _tags.begin(); i != _tags.end(); i++ ) 00094 buf << (i != _tags.begin()? " " : "") << *i; 00095 std::string result = buf.str(); 00096 return result; 00097 } 00098 00099 protected: 00100 00101 TagSet _tags; 00102 00103 private: 00104 00105 std::string normalize( const std::string& input ) const { 00106 std::string output = input; 00107 std::transform( output.begin(), output.end(), output.begin(), tolower ); 00108 return output; 00109 } 00110 }; 00111 00112 } } // namespace osgEarth::Symbology 00113 00114 #endif // OSGEARTHSYMBOLOGY_QUERY_H