Sirikata
|
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_URI_HPP__ 00006 #define SIRIKATA_CORE_TRANSFER_URI_HPP__ 00007 00008 #include <sirikata/core/util/Platform.hpp> 00009 00010 namespace Sirikata { 00011 namespace Transfer { 00012 00018 class URI { 00019 String mURI; 00020 String mScheme; // Derived from mURI and cached. 00021 00022 public: 00023 explicit URI() { 00024 } 00025 00029 explicit URI(const String& uri) 00030 : mURI(uri) 00031 { 00032 // Find the first colon 00033 String::size_type colon_pos = mURI.find(':'); 00034 if (colon_pos == String::npos) { 00035 mURI = ""; 00036 return; 00037 } 00038 // FIXME we should validate the characters in the scheme. 00039 mScheme = mURI.substr(0, colon_pos); 00040 } 00041 00042 inline const String& scheme() const { 00043 return mScheme; 00044 } 00045 00046 inline String schemeSpecificPart() const { 00047 return mURI.substr(mScheme.size()+1); 00048 } 00049 00050 inline const String& toString () const { 00051 return mURI; 00052 } 00053 00054 inline bool operator<(const URI &other) const { 00055 return mURI < other.mURI; 00056 } 00057 00058 inline bool operator==(const URI &other) const { 00059 return mURI == other.mURI; 00060 } 00061 00062 inline bool operator!=(const URI &other) const { 00063 return mURI != other.mURI; 00064 } 00065 00066 bool empty() const { 00067 return mURI.empty(); 00068 } 00069 00070 operator bool() const { 00071 return !empty(); 00072 } 00073 00074 struct Hasher { 00075 size_t operator() (const URI& uri)const { 00076 return std::tr1::hash<std::string>()(uri.mURI); 00077 } 00078 }; 00079 }; 00080 00081 inline std::ostream &operator<<(std::ostream &str, const URI &uri) { 00082 return str << uri.toString(); 00083 } 00084 00085 } // namespace Transfer 00086 } // namespace Sirikata 00087 00088 #endif /* SIRIKATA_CORE_TRANSFER_URI_HPP__ */