Gnash 0.8.9

ObjectURI.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00003 //   2011 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 <ostream>
00031 #include <sstream>
00032 
00033 //#define GNASH_STATS_OBJECT_URI_NOCASE 1
00034 
00035 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
00036 # include "Stats.h"
00037 #endif
00038 
00039 namespace gnash {
00040 
00042 //
00045 struct ObjectURI
00046 {
00047 
00049     class CaseLessThan;
00050 
00052     class LessThan;
00053 
00055     class CaseEquals;
00056 
00058     class Logger;
00059 
00061     //
00063     ObjectURI()
00064         :
00065         name(0),
00066         nameNoCase(0)
00067     {}
00068 
00070     ObjectURI(NSV::NamedStrings name)
00071         :
00072         name(name),
00073         nameNoCase(0)
00074     {}
00075 
00076 
00077     bool empty() const {
00078         return (name == 0);
00079     }
00080 
00081     const std::string& toString(string_table& st) const {
00082         return st.value(name);
00083     }
00084     
00085     string_table::key noCase(string_table& st) const {
00086 
00087         if (!name) return 0;
00088 
00089         if (!nameNoCase) {
00090             nameNoCase = st.noCase(name);
00091 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
00092             static stats::KeyLookup statNonSkip("ObjectURI::noCase non-skips",
00093                     st, 0, 0, 0);
00094             statNonSkip.check(name);
00095 #endif
00096         }
00097 #ifdef GNASH_STATS_OBJECT_URI_NOCASE
00098         else {
00099             static stats::KeyLookup stat("ObjectURI::noCase skips",
00100                     st, 0, 0, 0);
00101             stat.check(name);
00102         }
00103 #endif
00104 
00105         return nameNoCase;
00106     }
00107 
00108     string_table::key name;
00109 
00110 private:
00111 
00112     mutable string_table::key nameNoCase;
00113 };
00114 
00116 inline string_table::key
00117 getName(const ObjectURI& o)
00118 {
00119     return o.name;
00120 }
00121 
00122 class ObjectURI::LessThan
00123 {
00124 public:
00125     bool operator()(const ObjectURI& a, const ObjectURI& b) const {
00126         return a.name < b.name;
00127     }
00128 };
00129 
00130 class ObjectURI::CaseLessThan
00131 {
00132 public:
00133     CaseLessThan(string_table& st, bool caseless = false)
00134         :
00135         _st(st),
00136         _caseless(caseless)
00137     {}
00138     bool operator()(const ObjectURI& a, const ObjectURI& b) const {
00139         if (_caseless) return a.noCase(_st) < b.noCase(_st);
00140         return a.name < b.name;
00141     }
00142 private:
00143     string_table& _st;
00144     const bool _caseless;
00145 };
00146 
00147 class ObjectURI::CaseEquals
00148 {
00149 public:
00150     CaseEquals(string_table& st, bool caseless = false)
00151         :
00152         _st(st),
00153         _caseless(caseless)
00154     {}
00155     bool operator()(const ObjectURI& a, const ObjectURI& b) const {
00156         if (_caseless) return a.noCase(_st) == b.noCase(_st);
00157         return a.name == b.name;
00158     }
00159 private:
00160     string_table& _st;
00161     const bool _caseless;
00162 };
00163 
00164 class ObjectURI::Logger
00165 {
00166 public:
00167     Logger(string_table& st) : _st(st) {}
00168 
00169     std::string operator()(const ObjectURI& uri) const {
00170         const string_table::key name = getName(uri);
00171         return _st.value(name);
00172     }
00173 
00174     std::string debug(const ObjectURI& uri) const {
00175         std::stringstream ss;
00176         const string_table::key name = getName(uri);
00177         const string_table::key nameNoCase = uri.noCase(_st);
00178         ss << _st.value(name)
00179            << "(" << name << ")/"
00180            << _st.value(nameNoCase)
00181            << "(" << nameNoCase << ")";
00182         return ss.str();
00183     }
00184 
00185 private:
00186     string_table& _st;
00187 };
00188 
00189 } // namespace gnash
00190 #endif