Sirikata
libcore/include/sirikata/core/transfer/DataURI.hpp
Go to the documentation of this file.
00001 // Copyright (c) 2011 Sirikata Authors. All rights reserved.
00002 // Use of this source code is governed by a BSD-style license that can
00003 // be found in the LICENSE file.
00004 
00005 #ifndef SIRIKATA_CORE_TRANSFER_DATA_URI_HPP__
00006 #define SIRIKATA_CORE_TRANSFER_DATA_URI_HPP__
00007 
00008 #include <sirikata/core/util/Platform.hpp>
00009 #include <sirikata/core/transfer/URI.hpp>
00010 
00011 namespace Sirikata {
00012 namespace Transfer {
00013 
00019 class SIRIKATA_EXPORT DataURI {
00020 public:
00021     typedef std::map<String, String> ParameterMap;
00022 
00023 private:
00024     String mMediaType;
00025     ParameterMap mMediaTypeParameters;
00026     String mData;
00027 
00028     void parse(const String& uri);
00029 public:
00030     explicit DataURI() {
00031     }
00032 
00036     explicit DataURI(const String& uri);
00037 
00041     explicit DataURI(const URI& uri);
00042 
00043     inline const String& mediatype() const {
00044         return mMediaType;
00045     }
00046 
00047     inline const ParameterMap& mediatypeParameters() const {
00048         return mMediaTypeParameters;
00049     }
00050 
00051     inline const String& data() const {
00052         return mData;
00053     }
00054 
00055     String toString() const;
00056 
00057     inline bool operator<(const DataURI &other) const {
00058         return (mMediaType < other.mMediaType ||
00059             (mMediaType < other.mMediaType && mData < other.mData));
00060     }
00061 
00062     inline bool operator==(const DataURI &other) const {
00063         return (mMediaType == other.mMediaType && mData < other.mData);
00064     }
00065 
00066     inline bool operator!=(const DataURI &other) const {
00067         return (mMediaType != other.mMediaType || mData != other.mData);
00068     }
00069 
00070     bool empty() const {
00071         return mData.empty();
00072     }
00073 
00074     operator bool() const {
00075         return !empty();
00076     }
00077 
00078     struct Hasher {
00079         size_t operator() (const DataURI& uri)const {
00080             return std::tr1::hash<std::string>()(uri.mMediaType);
00081         }
00082     };
00083 };
00084 
00085 inline std::ostream &operator<<(std::ostream &str, const DataURI &uri) {
00086     return str << uri.toString();
00087 }
00088 
00089 } // namespace Transfer
00090 } // namespace Sirikata
00091 
00092 #endif /* SIRIKATA_CORE_TRANSFER_URI_HPP__ */