00001 /* 00002 00003 Copyright (c) 2003, Arvid Norberg 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions 00008 are met: 00009 00010 * Redistributions of source code must retain the above copyright 00011 notice, this list of conditions and the following disclaimer. 00012 * Redistributions in binary form must reproduce the above copyright 00013 notice, this list of conditions and the following disclaimer in 00014 the documentation and/or other materials provided with the distribution. 00015 * Neither the name of the author nor the names of its 00016 contributors may be used to endorse or promote products derived 00017 from this software without specific prior written permission. 00018 00019 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00022 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00023 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00024 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00025 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00026 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00027 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00028 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00029 POSSIBILITY OF SUCH DAMAGE. 00030 00031 */ 00032 00033 #ifndef TORRENT_FINGERPRINT_HPP_INCLUDED 00034 #define TORRENT_FINGERPRINT_HPP_INCLUDED 00035 00036 #include <string> 00037 #include <sstream> 00038 00039 #include "libtorrent/peer_id.hpp" 00040 00041 namespace libtorrent 00042 { 00043 00044 struct fingerprint 00045 { 00046 fingerprint(const char* id_string, int major, int minor, int revision, int tag) 00047 : major_version(major) 00048 , minor_version(minor) 00049 , revision_version(revision) 00050 , tag_version(tag) 00051 { 00052 assert(id_string); 00053 assert(major >= 0); 00054 assert(minor >= 0); 00055 assert(revision >= 0); 00056 assert(tag >= 0); 00057 assert(std::strlen(id_string) == 2); 00058 name[0] = id_string[0]; 00059 name[1] = id_string[1]; 00060 } 00061 00062 std::string to_string() const 00063 { 00064 std::stringstream s; 00065 s << "-" << name[0] << name[1] 00066 << version_to_char(major_version) 00067 << version_to_char(minor_version) 00068 << version_to_char(revision_version) 00069 << version_to_char(tag_version) << "-"; 00070 return s.str(); 00071 } 00072 00073 char name[2]; 00074 int major_version; 00075 int minor_version; 00076 int revision_version; 00077 int tag_version; 00078 00079 private: 00080 00081 char version_to_char(int v) const 00082 { 00083 if (v >= 0 && v < 10) return '0' + v; 00084 else if (v >= 10) return 'A' + (v - 10); 00085 assert(false); 00086 return '0'; 00087 } 00088 00089 }; 00090 00091 } 00092 00093 #endif // TORRENT_FINGERPRINT_HPP_INCLUDED
1.5.6