RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* url.h -*- C++ -*- 00002 Jeremy Barnes, 16 March 2012 00003 Copyright (c) 2012 Datacratic. All rights reserved. 00004 00005 URL class. 00006 */ 00007 00008 #pragma once 00009 00010 #include <string> 00011 #include <memory> 00012 #include "jml/db/persistent_fwd.h" 00013 #include "string.h" 00014 00015 class GURL; 00016 00017 namespace Datacratic { 00018 00019 struct Url { 00020 Url(); 00021 explicit Url(const std::string & s); 00022 explicit Url(const Utf8String & s); 00023 ~Url(); 00024 00025 Utf8String toUtf8String() const; 00026 std::string toString() const; // should be Utf8 by default 00027 00028 const char * c_str() const; 00029 00030 bool valid() const; 00031 bool empty() const; 00032 00033 std::string canonical() const; 00034 std::string scheme() const; 00035 std::string host() const; 00036 bool hostIsIpAddress() const; 00037 bool domainMatches(const std::string & str) const; 00038 int port() const; 00039 std::string path() const; 00040 std::string query() const; 00041 00042 uint64_t urlHash(); 00043 uint64_t hostHash(); 00044 00045 std::shared_ptr<GURL> url; 00046 std::string original; 00047 00048 void serialize(ML::DB::Store_Writer & store) const; 00049 void reconstitute(ML::DB::Store_Reader & store); 00050 }; 00051 00052 inline std::ostream & operator << (std::ostream & stream, const Url & url) 00053 { 00054 return stream << url.toString(); 00055 } 00056 00057 IMPL_SERIALIZE_RECONSTITUTE(Url); 00058 00059 } // namespace Datacratic