FIX: python import
[Tsunagari.git] / src / reader.h
blobbc7bb96ba79fb4a77ec17aa862aa5861c421ef2c
1 /*********************************
2 ** Tsunagari Tile Engine **
3 ** reader.h **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
7 // "OmegaSDG" is defined as Michael D. Reiley and Paul Merrill.
9 // **********
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to
12 // deal in the Software without restriction, including without limitation the
13 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14 // sell copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 // IN THE SOFTWARE.
27 // **********
29 #ifndef READER_H
30 #define READER_H
32 #include <string>
34 #include <boost/shared_ptr.hpp>
35 #include <boost/unordered_map.hpp>
36 #include <libxml/parser.h>
38 #include "bytecode.h"
39 #include "cache.h"
40 #include "image.h"
41 #include "sound.h"
42 #include "tiledimage.h"
43 #include "xml.h"
45 namespace Gosu {
46 class Buffer;
47 class Sample;
48 class Song;
51 // We hand out and manage resources in these forms:
52 typedef boost::shared_ptr<Sound> SampleRef;
54 /**
55 * FIXME
56 * Provides data and resource extraction for a World.
57 * Each World comes bundled with associated data in the form of a Zip file.
58 * A Reader object knows how to navigate the data, extract individual
59 * requested files, and process the files into data structures. The final data
60 * structures are kept in memory for future requests.
62 class Reader
64 public:
65 static bool init(char* argv0);
66 static void deinit();
68 static bool prependPath(const std::string& path);
69 static bool appendPath(const std::string& path);
70 static bool rmPath(const std::string& path);
72 //! Returns true if the World contains a resource by that name.
73 static bool resourceExists(const std::string& name);
74 static bool directoryExists(const std::string& name);
75 static bool fileExists(const std::string& name);
77 static Gosu::Buffer* readBuffer(const std::string& name);
78 static std::string readString(const std::string& name);
80 //! Request an image from the World.
81 static ImageRef getImage(const std::string& name);
83 //! Request an image resource from the World and splits it into a
84 //! number of tiles that each have width and height w by h.
85 static TiledImageRef getTiledImage(const std::string& name,
86 int w, int h);
88 //! Request a sound object from the World. The sound will be
89 //! completely loaded into memory at once.
90 static SampleRef getSample(const std::string& name);
92 //! Request an XML document from the World.
93 static XMLRef getXMLDoc(const std::string& name,
94 const std::string& dtdPath);
96 static BytecodeRef getBytecode(const std::string& path);
98 //! Request a Python script from the World be run.
99 static bool runPythonScript(const std::string& name);
101 //! Request a text file from the World.
102 static std::string getText(const std::string& name);
104 //! Expunge old resources cached in memory. Decisions on which are
105 //! removed and which are kept are based on the global Conf struct.
106 static void garbageCollect();
109 void exportReader();
111 #endif