2 // This file is part of the aMule Project.
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 Merkur ( devs@emule-project.net / http://www.emule-project.net )
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #include <common/StringFunctions.h> // Needed for EUtf8Str
32 #include <tags/TagTypes.h>
34 #include "OtherFunctions.h"
39 ///////////////////////////////////////////////////////////////////////////////
45 CTag(const CTag
& rTag
);
46 CTag(const CFileDataIO
& data
, bool bOptUTF8
);
48 CTag
& operator=(const CTag
&);
50 uint8
GetType() const { return m_uType
; }
51 uint8
GetNameID() const { return m_uName
; }
52 const wxString
& GetName() const { return m_Name
; }
54 bool IsStr() const { return m_uType
== TAGTYPE_STRING
; }
55 bool IsInt() const { return
56 (m_uType
== TAGTYPE_UINT64
) ||
57 (m_uType
== TAGTYPE_UINT32
) ||
58 (m_uType
== TAGTYPE_UINT16
) ||
59 (m_uType
== TAGTYPE_UINT8
); }
60 bool IsFloat() const { return m_uType
== TAGTYPE_FLOAT32
; }
61 bool IsHash() const { return m_uType
== TAGTYPE_HASH16
; }
62 bool IsBlob() const { return m_uType
== TAGTYPE_BLOB
; }
63 bool IsBsob() const { return m_uType
== TAGTYPE_BSOB
; }
65 uint64
GetInt() const;
67 const wxString
& GetStr() const;
69 float GetFloat() const;
71 const CMD4Hash
& GetHash() const;
73 const byte
* GetBlob() const;
74 uint32
GetBlobSize() const;
76 const byte
* GetBsob() const;
77 uint32
GetBsobSize() const;
79 CTag
* CloneTag() { return new CTag(*this); }
81 bool WriteTagToFile(CFileDataIO
* file
,
82 EUtf8Str eStrEncode
= utf8strNone
,
83 bool restrictive
= true) const; // old eD2K tags
84 bool WriteNewEd2kTag(CFileDataIO
* file
,
85 EUtf8Str eStrEncode
= utf8strNone
) const; // new eD2K tags
87 wxString
GetFullInfo() const;
90 CTag(const wxString
& Name
);
99 unsigned char* m_pData
;
110 typedef std::list
<CTag
*> TagPtrList
;
112 class CTagIntSized
: public CTag
115 CTagIntSized(const wxString
& name
, uint64 value
, uint8 bitsize
)
117 Init(value
, bitsize
);
120 CTagIntSized(uint8 name
, uint64 value
, uint8 bitsize
)
122 Init(value
, bitsize
);
126 CTagIntSized(const wxString
& name
) : CTag(name
) {}
127 CTagIntSized(uint8 name
) : CTag(name
) {}
129 void Init(uint64 value
, uint8 bitsize
) {
132 wxASSERT(value
<= ULONGLONG(0xFFFFFFFFFFFFFFFF));
134 m_uType
= TAGTYPE_UINT64
;
137 wxASSERT(value
<= 0xFFFFFFFF);
139 m_uType
= TAGTYPE_UINT32
;
142 wxASSERT(value
<= 0xFFFF);
144 m_uType
= TAGTYPE_UINT16
;
147 wxASSERT(value
<= 0xFF);
149 m_uType
= TAGTYPE_UINT8
;
152 throw wxString(wxT("Invalid bitsize on int tag"));
157 class CTagVarInt
: public CTagIntSized
160 CTagVarInt(const wxString
& name
, uint64 value
, uint8 forced_bits
= 0)
161 : CTagIntSized(name
) {
162 SizedInit(value
, forced_bits
);
164 CTagVarInt(uint8 name
, uint64 value
, uint8 forced_bits
= 0)
165 : CTagIntSized(name
) {
166 SizedInit(value
, forced_bits
);
169 void SizedInit(uint64 value
, uint8 forced_bits
) {
171 // The bitsize was forced.
172 Init(value
,forced_bits
);
176 m_uType
= TAGTYPE_UINT8
;
177 } else if (value
<= 0xFFFF) {
178 m_uType
= TAGTYPE_UINT16
;
179 } else if (value
<= 0xFFFFFFFF) {
180 m_uType
= TAGTYPE_UINT32
;
182 m_uType
= TAGTYPE_UINT64
;
188 class CTagInt64
: public CTagIntSized
191 CTagInt64(const wxString
& name
, uint64 value
)
192 : CTagIntSized(name
, value
, 64) { }
194 CTagInt64(uint8 name
, uint64 value
)
195 : CTagIntSized(name
, value
, 64) { }
198 class CTagInt32
: public CTagIntSized
201 CTagInt32(const wxString
& name
, uint64 value
)
202 : CTagIntSized(name
, value
, 32) { }
204 CTagInt32(uint8 name
, uint64 value
)
205 : CTagIntSized(name
, value
, 32) { }
208 class CTagInt16
: public CTagIntSized
211 CTagInt16(const wxString
& name
, uint64 value
)
212 : CTagIntSized(name
, value
, 16) { }
214 CTagInt16(uint8 name
, uint64 value
)
215 : CTagIntSized(name
, value
, 16) { }
218 class CTagInt8
: public CTagIntSized
221 CTagInt8(const wxString
& name
, uint64 value
)
222 : CTagIntSized(name
, value
, 8) { }
224 CTagInt8(uint8 name
, uint64 value
)
225 : CTagIntSized(name
, value
, 8) { }
228 class CTagFloat
: public CTag
231 CTagFloat(const wxString
& name
, float value
)
234 m_uType
= TAGTYPE_FLOAT32
;
237 CTagFloat(uint8 name
, float value
)
240 m_uType
= TAGTYPE_FLOAT32
;
244 class CTagString
: public CTag
247 CTagString(const wxString
& name
, const wxString
& value
)
249 m_pstrVal
= new wxString(value
);
250 m_uType
= TAGTYPE_STRING
;
253 CTagString(uint8 name
, const wxString
& value
)
255 m_pstrVal
= new wxString(value
);
256 m_uType
= TAGTYPE_STRING
;
260 class CTagHash
: public CTag
263 // Implementation on .cpp to allow forward declaration of CMD4Hash
264 CTagHash(const wxString
& name
, const CMD4Hash
& value
);
265 CTagHash(uint8 name
, const CMD4Hash
& value
);
268 class CTagBsob
: public CTag
271 CTagBsob(const wxString
& name
, const byte
* value
, uint8 nSize
)
274 m_uType
= TAGTYPE_BSOB
;
275 m_pData
= new byte
[nSize
];
276 memcpy(m_pData
, value
, nSize
);
281 class CTagBlob
: public CTag
284 CTagBlob(const wxString
& name
, const byte
* value
, uint8 nSize
)
287 m_uType
= TAGTYPE_BLOB
;
288 m_pData
= new byte
[nSize
];
289 memcpy(m_pData
, value
, nSize
);
294 void deleteTagPtrListEntries(TagPtrList
* taglist
);
297 // File_checked_for_headers