1 /*
2  *  tracker/Decompressor.h
3  *
4  *  Copyright 2009 Peter Barth
5  *
6  *  This file is part of Milkytracker.
7  *
8  *  Milkytracker is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  Milkytracker is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with Milkytracker.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 /*
24  *  Decompressor.h
25  *  MilkyTracker
26  *
27  *  Created by Peter Barth on 19.10.07.
28  *
29  */
30 
31 #ifndef __DECOMPRESSOR_H__
32 #define __DECOMPRESSOR_H__
33 
34 #include "BasicTypes.h"
35 #include "SimpleVector.h"
36 
37 class XMFile;
38 
39 class DecompressorBase
40 {
41 public:
42 	enum Hints
43 	{
44 		HintAll,
45 		HintModules,
46 		HintInstruments,
47 		HintSamples,
48 		HintPatterns,
49 		HintTracks
50 	};
51 
DecompressorBase(const PPSystemString & fileName)52 	DecompressorBase(const PPSystemString& fileName) :
53 		fileName(fileName)
54 	{
55 	}
56 
~DecompressorBase()57 	virtual ~DecompressorBase()
58 	{
59 	}
60 
61 	virtual bool identify(XMFile& f) = 0;
62 
63 	virtual bool identify();
64 
65 	virtual bool doesServeHint(Hints hint) = 0;
66 
67 	virtual const PPSimpleVector<Descriptor>& getDescriptors(Hints hint) const = 0;
68 
69 	virtual bool decompress(const PPSystemString& outFileName, Hints hint) = 0;
70 
71 	static void removeFile(const PPSystemString& fileName);
72 
73 	virtual void setFilename(const PPSystemString& fileName);
74 
75 	virtual DecompressorBase* clone() = 0;
76 
77 protected:
78 	PPSystemString fileName;
79 
80 	mutable PPSimpleVector<Descriptor> descriptors;
81 };
82 
83 /*****************************************************************************
84  * Generic decompressor
85  *****************************************************************************/
86 class Decompressor : public DecompressorBase
87 {
88 public:
89 	Decompressor(const PPSystemString& fileName);
90 
91 	virtual bool identify(XMFile& f);
92 
93 	virtual bool doesServeHint(Hints hint);
94 
95 	virtual const PPSimpleVector<Descriptor>& getDescriptors(Hints hint) const;
96 
97 	virtual bool decompress(const PPSystemString& outFileName, Hints hint);
98 
99 	virtual DecompressorBase* clone();
100 
101 	virtual void setFilename(const PPSystemString& fileName);
102 
103 private:
104 	void adjustFilenames(const PPSystemString& fileName);
105 
106 	PPSimpleVector<DecompressorBase> decompressors;
107 
108 public:
109 	static PPSimpleVector<DecompressorBase>& decompressorList();
110 
111 	template<class type>
112 	struct RegisterDecompressor
113 	{
RegisterDecompressorRegisterDecompressor114 		RegisterDecompressor()
115 		{
116 			Decompressor::decompressorList().add(new type(""));
117 		}
118 	};
119 };
120 
121 #endif
122 
123