Gnash  0.8.10
ObjectURI.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_OBJECTURI_H
00020 #define GNASH_OBJECTURI_H
00021 
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h" // GNASH_STATS_OBJECT_URI_NOCASE
00024 #endif
00025 
00026 #include "string_table.h"
00027 #include "namedStrings.h"
00028 
00029 #include <string>
00030 #include <sstream>
00031 
00032 //#define GNASH_STATS_OBJECT_URI_NOCASE 1
00033 
00034 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
00035 # include "Stats.h"
00036 #endif
00037 
00038 namespace gnash {
00039 
00041 //
00044 struct ObjectURI
00045 {
00046 
00048     class CaseLessThan;
00049 
00051     class LessThan;
00052 
00054     class CaseEquals;
00055 
00057     class Logger;
00058 
00060     //
00062     ObjectURI()
00063         :
00064         name(0),
00065         nameNoCase(0)
00066     {}
00067 
00069     ObjectURI(NSV::NamedStrings name)
00070         :
00071         name(name),
00072         nameNoCase(0)
00073     {}
00074 
00075 
00076     bool empty() const {
00077         return (name == 0);
00078     }
00079 
00080     const std::string& toString(string_table& st) const {
00081         return st.value(name);
00082     }
00083     
00084     string_table::key noCase(string_table& st) const {
00085 
00086         if (!name) return 0;
00087 
00088         if (!nameNoCase) {
00089             nameNoCase = st.noCase(name);
00090 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
00091             static stats::KeyLookup statNonSkip("ObjectURI::noCase non-skips",
00092                     st, 0, 0, 0);
00093             statNonSkip.check(name);
00094 #endif
00095         }
00096 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
00097         else {
00098             static stats::KeyLookup stat("ObjectURI::noCase skips",
00099                     st, 0, 0, 0);
00100             stat.check(name);
00101         }
00102 #endif
00103 
00104         return nameNoCase;
00105     }
00106 
00107     string_table::key name;
00108 
00109 private:
00110 
00111     mutable string_table::key nameNoCase;
00112 };
00113 
00115 inline string_table::key
00116 getName(const ObjectURI& o)
00117 {
00118     return o.name;
00119 }
00120 
00121 class ObjectURI::LessThan
00122 {
00123 public:
00124     bool operator()(const ObjectURI& a, const ObjectURI& b) const {
00125         return a.name < b.name;
00126     }
00127 };
00128 
00129 class ObjectURI::CaseLessThan
00130 {
00131 public:
00132     CaseLessThan(string_table& st, bool caseless = false)
00133         :
00134         _st(st),
00135         _caseless(caseless)
00136     {}
00137     bool operator()(const ObjectURI& a, const ObjectURI& b) const {
00138         if (_caseless) return a.noCase(_st) < b.noCase(_st);
00139         return a.name < b.name;
00140     }
00141 private:
00142     string_table& _st;
00143     const bool _caseless;
00144 };
00145 
00146 class ObjectURI::CaseEquals
00147 {
00148 public:
00149     CaseEquals(string_table& st, bool caseless = false)
00150         :
00151         _st(st),
00152         _caseless(caseless)
00153     {}
00154     bool operator()(const ObjectURI& a, const ObjectURI& b) const {
00155         if (_caseless) return a.noCase(_st) == b.noCase(_st);
00156         return a.name == b.name;
00157     }
00158 private:
00159     string_table& _st;
00160     const bool _caseless;
00161 };
00162 
00163 class ObjectURI::Logger
00164 {
00165 public:
00166     Logger(string_table& st) : _st(st) {}
00167 
00168     std::string operator()(const ObjectURI& uri) const {
00169         const string_table::key name = getName(uri);
00170         return _st.value(name);
00171     }
00172 
00173     std::string debug(const ObjectURI& uri) const {
00174         std::stringstream ss;
00175         const string_table::key name = getName(uri);
00176         const string_table::key nameNoCase = uri.noCase(_st);
00177         ss << _st.value(name)
00178            << "(" << name << ")/"
00179            << _st.value(nameNoCase)
00180            << "(" << nameNoCase << ")";
00181         return ss.str();
00182     }
00183 
00184 private:
00185     string_table& _st;
00186 };
00187 
00188 } // namespace gnash
00189 #endif