1 /*
2 	This file is part of the metalink program
3 	Copyright (C) 2008  A. Bram Neijt <bneijt@gmail.com>
4 
5   This program is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 
21 
22 
23 /*
24 	Should implement this:
25 
26 	<pieces length="131072">
27   <hash type="sha1" piece=”0”>example-sha1-hash</hash>
28   <hash type="sha1" piece=”1”>example-sha1-hash</hash>
29 </pieces>
30 
31 */
32 #ifndef _HashPieces_HH_INCLUDED_
33 #define	_HashPieces_HH_INCLUDED_
34 
35 #include <vector>
36 #include <string>
37 
38 #include "../Hash.hh"
39 
40 #include "../../Preprocessor/foreach.hh"
41 
42 namespace bneijt
43 {
44 class HashPieces: public Hash
45 {
46 		unsigned long long d_size;
47 		unsigned int d_count;
48 		std::vector<Hash *> d_pieces;
49 		Hash * d_h;
50 		std::string d_value;
51 	public:
52 		HashPieces(unsigned long long size = 256*1024);
53 
~HashPieces()54 		~HashPieces()
55 		{
56 			_foreach(h, d_pieces)
57 				if(*h)
58 					delete *h;
59 			if(d_h)
60 				delete d_h;
61 		}
62 
size() const63 		unsigned long long size() const
64 		{
65 			return d_size;
66 		}
67 
68 		virtual std::string name() const;
69 
70 		virtual void update(char const *bytes, unsigned numbytes);
71 
72 		virtual void finalize();
73 
74 		std::string xml() const;
75 
76 		virtual std::string const &value() const;
77 };
78 }//namespace
79 
80 #endif
81 
82