gosu 0.7.39-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/COPYING +34 -0
  2. data/Gosu/Async.hpp +50 -0
  3. data/Gosu/Audio.hpp +163 -0
  4. data/Gosu/AutoLink.hpp +16 -0
  5. data/Gosu/Bitmap.hpp +96 -0
  6. data/Gosu/ButtonsMac.hpp +140 -0
  7. data/Gosu/ButtonsWin.hpp +140 -0
  8. data/Gosu/ButtonsX.hpp +141 -0
  9. data/Gosu/Color.hpp +204 -0
  10. data/Gosu/Directories.hpp +36 -0
  11. data/Gosu/Font.hpp +83 -0
  12. data/Gosu/Fwd.hpp +31 -0
  13. data/Gosu/Gosu.hpp +34 -0
  14. data/Gosu/Graphics.hpp +120 -0
  15. data/Gosu/GraphicsBase.hpp +66 -0
  16. data/Gosu/IO.hpp +259 -0
  17. data/Gosu/Image.hpp +138 -0
  18. data/Gosu/ImageData.hpp +58 -0
  19. data/Gosu/Input.hpp +161 -0
  20. data/Gosu/Inspection.hpp +14 -0
  21. data/Gosu/Math.hpp +135 -0
  22. data/Gosu/Platform.hpp +73 -0
  23. data/Gosu/Sockets.hpp +137 -0
  24. data/Gosu/TR1.hpp +44 -0
  25. data/Gosu/Text.hpp +71 -0
  26. data/Gosu/TextInput.hpp +70 -0
  27. data/Gosu/Timing.hpp +16 -0
  28. data/Gosu/Utility.hpp +28 -0
  29. data/Gosu/Version.hpp +526 -0
  30. data/Gosu/WinUtility.hpp +75 -0
  31. data/Gosu/Window.hpp +124 -0
  32. data/README.txt +25 -0
  33. data/examples/ChipmunkIntegration.rb +275 -0
  34. data/examples/CptnRuby.rb +223 -0
  35. data/examples/MoreChipmunkAndRMagick.rb +155 -0
  36. data/examples/OpenGLIntegration.rb +226 -0
  37. data/examples/RMagickIntegration.rb +417 -0
  38. data/examples/TextInput.rb +154 -0
  39. data/examples/Tutorial.rb +131 -0
  40. data/examples/media/Beep.wav +0 -0
  41. data/examples/media/CptnRuby Gem.png +0 -0
  42. data/examples/media/CptnRuby Map.txt +25 -0
  43. data/examples/media/CptnRuby Tileset.png +0 -0
  44. data/examples/media/CptnRuby.png +0 -0
  45. data/examples/media/Cursor.png +0 -0
  46. data/examples/media/Earth.png +0 -0
  47. data/examples/media/Explosion.wav +0 -0
  48. data/examples/media/Landscape.svg +10 -0
  49. data/examples/media/LargeStar.png +0 -0
  50. data/examples/media/Smoke.png +0 -0
  51. data/examples/media/Soldier.png +0 -0
  52. data/examples/media/Space.png +0 -0
  53. data/examples/media/Star.png +0 -0
  54. data/examples/media/Starfighter.bmp +0 -0
  55. data/lib/FreeImage.dll +0 -0
  56. data/lib/OpenAL32.dll +0 -0
  57. data/lib/gosu.for_1_8.so +0 -0
  58. data/lib/gosu.for_1_9.so +0 -0
  59. data/lib/gosu.rb +17 -0
  60. data/lib/gosu/patches.rb +75 -0
  61. data/lib/gosu/preview.rb +121 -0
  62. data/lib/gosu/run.rb +11 -0
  63. data/lib/gosu/swig_patches.rb +48 -0
  64. data/lib/gosu/zen.rb +28 -0
  65. data/lib/libsndfile.dll +0 -0
  66. metadata +138 -0
@@ -0,0 +1,36 @@
1
+ //! \file Directories.hpp
2
+ //! Access to a small set of system paths.
3
+
4
+ #ifndef GOSU_DIRECTORIES_HPP
5
+ #define GOSU_DIRECTORIES_HPP
6
+
7
+ #include <string>
8
+
9
+ namespace Gosu
10
+ {
11
+ //! Prefix for a program's own resources.
12
+ //! On Windows, the executable's containing directory.
13
+ //! On OS X, the application's Resources subdirectory.
14
+ //! On Linux, the current directory.
15
+ std::wstring resourcePrefix();
16
+
17
+ //! Prefix for resources of a group of programs.
18
+ //! On Windows, the executable's containing directory.
19
+ //! On OS X, the application's containing subdirectory.
20
+ //! On Linux, the current directory.
21
+ std::wstring sharedResourcePrefix();
22
+
23
+ //! Prefix for user settings.
24
+ //! On Windows, the same as %APPDATA%.
25
+ //! On OS X, the user's Library/Preferences folder.
26
+ //! On Linux, the home directory plus a trailing dot for hidden files.
27
+ std::wstring userSettingsPrefix();
28
+
29
+ //! Prefix for user documents, e.g. save games.
30
+ //! On Windows, the My Documents folder.
31
+ //! On OS X, the user's Documents folder.
32
+ //! On Linux, the home directory.
33
+ std::wstring userDocsPrefix();
34
+ }
35
+
36
+ #endif
data/Gosu/Font.hpp ADDED
@@ -0,0 +1,83 @@
1
+ //! \file Font.hpp
2
+ //! Interface of the Font class.
3
+
4
+ #ifndef GOSU_FONT_HPP
5
+ #define GOSU_FONT_HPP
6
+
7
+ #include <Gosu/Fwd.hpp>
8
+ #include <Gosu/Color.hpp>
9
+ #include <Gosu/GraphicsBase.hpp>
10
+ #include <Gosu/Platform.hpp>
11
+ #include <Gosu/TR1.hpp>
12
+ #include <string>
13
+
14
+ namespace Gosu
15
+ {
16
+ //! A font can be used to draw text on a Graphics object very flexibly.
17
+ //! Fonts are ideal for small texts that change regularly. For large,
18
+ //! static texts you should use createBitmap and turn the result into
19
+ //! an image.
20
+ class Font
21
+ {
22
+ struct Impl;
23
+ std::tr1::shared_ptr<Impl> pimpl;
24
+
25
+ public:
26
+ //! Constructs a font that can be drawn onto the graphics object.
27
+ //! \param fontName Name of a system font, or a filename to a TTF
28
+ //! file (must contain '/', does not work on Linux).
29
+ //! \param fontHeight Height of the font, in pixels.
30
+ //! \param fontFlags Flags used to render individual characters of
31
+ //! the font.
32
+ Font(Graphics& graphics, const std::wstring& fontName,
33
+ unsigned fontHeight, unsigned fontFlags = ffBold);
34
+
35
+ //! Returns the name of the font that was used to create it.
36
+ std::wstring name() const;
37
+
38
+ //! Returns the height of the font, in pixels.
39
+ unsigned height() const;
40
+
41
+ //! Returns the flags used to create the font characters.
42
+ unsigned flags() const;
43
+
44
+ //! Returns the width, in pixels, the given text would occupy if drawn.
45
+ double textWidth(const std::wstring& text, double factorX = 1) const;
46
+
47
+ //! Draws text so the top left corner of the text is at (x; y).
48
+ //! \param text Formatted text without line-breaks.
49
+ void draw(const std::wstring& text, double x, double y, ZPos z,
50
+ double factorX = 1, double factorY = 1,
51
+ Color c = Color::WHITE, AlphaMode mode = amDefault) const;
52
+
53
+ //! Draws text at a position relative to (x; y).
54
+ //! \param relX Determines where the text is drawn horizontally. If
55
+ //! relX is 0.0, the text will be to the right of x, if it is 1.0,
56
+ //! the text will be to the left of x, if it is 0.5, it will be
57
+ //! centered on x. Of course, all real numbers are possible values.
58
+ //! \param relY See relX.
59
+ void drawRel(const std::wstring& text, double x, double y, ZPos z,
60
+ double relX, double relY, double factorX = 1, double factorY = 1,
61
+ Color c = Color::WHITE, AlphaMode mode = amDefault) const;
62
+
63
+ //! Maps a letter to a specific image instead of generating one using
64
+ //! Gosu's built-in text rendering. This can only be called once per
65
+ //! character, and the character must not have been drawn before.
66
+ //! This ensures that Fonts are still sort of immutable.
67
+ void setImage(wchar_t wc, unsigned fontFlags, const Gosu::Image& image);
68
+ //! A shortcut for mapping a character to an image regardless of fontFlags.
69
+ //! Later versions might apply faux italics or faux bold to it (to be decided!).
70
+ void setImage(wchar_t wc, const Gosu::Image& image);
71
+
72
+ #ifndef SWIG
73
+ GOSU_DEPRECATED
74
+ #endif
75
+ //! DEPRECATED: Analogous to draw, but rotates the text by a given angle. Use
76
+ //! a simple pushTransform to achieve the same effect.
77
+ void drawRot(const std::wstring& text, double x, double y, ZPos z, double angle,
78
+ double factorX = 1, double factorY = 1,
79
+ Color c = Color::WHITE, AlphaMode mode = amDefault) const;
80
+ };
81
+ }
82
+
83
+ #endif
data/Gosu/Fwd.hpp ADDED
@@ -0,0 +1,31 @@
1
+ //! \file Fwd.hpp
2
+ //! Contains declarations of all of Gosu's available classes.
3
+
4
+ #ifndef GOSU_FWD_HPP
5
+ #define GOSU_FWD_HPP
6
+
7
+ //! The library's main namespace.
8
+ namespace Gosu
9
+ {
10
+ class Audio;
11
+ class Bitmap;
12
+ class Buffer;
13
+ class Button;
14
+ class Color;
15
+ class File;
16
+ class Font;
17
+ class Graphics;
18
+ class Image;
19
+ class ImageData;
20
+ class Input;
21
+ class Reader;
22
+ class Resource;
23
+ class Sample;
24
+ class Song;
25
+ class TextInput;
26
+ class Timer;
27
+ class Window;
28
+ class Writer;
29
+ }
30
+
31
+ #endif
data/Gosu/Gosu.hpp ADDED
@@ -0,0 +1,34 @@
1
+ //! \file Gosu.hpp
2
+ //! Umbrella header for lazy people with fast compilers, or pre-compiled headers.
3
+
4
+ //! \mainpage Gosu C++ Documentation
5
+ //!
6
+ //! These pages serve as a reference on the C++ interface of Gosu. For a higher-level
7
+ //! discussion of concepts and ideas behind the library, see the Wiki entries linked
8
+ //! from the official website, http://www.libgosu.org/.
9
+
10
+ #ifndef GOSU_GOSU_HPP
11
+ #define GOSU_GOSU_HPP
12
+
13
+ #include <Gosu/Audio.hpp>
14
+ #include <Gosu/Bitmap.hpp>
15
+ #include <Gosu/Color.hpp>
16
+ #include <Gosu/Directories.hpp>
17
+ #include <Gosu/Font.hpp>
18
+ #include <Gosu/Graphics.hpp>
19
+ #include <Gosu/Image.hpp>
20
+ #include <Gosu/ImageData.hpp>
21
+ #include <Gosu/Input.hpp>
22
+ #include <Gosu/Inspection.hpp>
23
+ #include <Gosu/IO.hpp>
24
+ #include <Gosu/Math.hpp>
25
+ #include <Gosu/Platform.hpp>
26
+ #include <Gosu/Sockets.hpp>
27
+ #include <Gosu/Text.hpp>
28
+ #include <Gosu/TextInput.hpp>
29
+ #include <Gosu/Timing.hpp>
30
+ #include <Gosu/Utility.hpp>
31
+ #include <Gosu/Version.hpp>
32
+ #include <Gosu/Window.hpp>
33
+
34
+ #endif
data/Gosu/Graphics.hpp ADDED
@@ -0,0 +1,120 @@
1
+ //! \file Graphics.hpp
2
+ //! Interface of the Graphics class.
3
+
4
+ #ifndef GOSU_GRAPHICS_HPP
5
+ #define GOSU_GRAPHICS_HPP
6
+
7
+ #include <Gosu/Fwd.hpp>
8
+ #include <Gosu/Color.hpp>
9
+ #include <Gosu/GraphicsBase.hpp>
10
+ #include <Gosu/TR1.hpp>
11
+ #include <memory>
12
+
13
+ namespace Gosu
14
+ {
15
+ //! Returns the width, in pixels, of the user's primary screen.
16
+ unsigned screenWidth();
17
+
18
+ //! Returns the height, in pixels, of the user's primary screen.
19
+ unsigned screenHeight();
20
+
21
+ //! Returns the maximum size of an texture that will be allocated
22
+ //! internally by Gosu.
23
+ //! Useful when extending Gosu using OpenGL.
24
+ unsigned const MAX_TEXTURE_SIZE = 1024;
25
+
26
+ typedef std::tr1::array<double, 16> Transform;
27
+ Transform translate(double x, double y);
28
+ Transform rotate(double angle, double aroundX = 0, double aroundY = 0);
29
+ Transform scale(double factor);
30
+ Transform scale(double factorX, double factorY, double fromX = 0, double fromY = 0);
31
+
32
+ //! Serves as the target of all drawing and provides primitive drawing
33
+ //! functionality.
34
+ //! Usually created internally by Gosu::Window.
35
+ class Graphics
36
+ {
37
+ struct Impl;
38
+ const std::auto_ptr<Impl> pimpl;
39
+
40
+ public:
41
+ Graphics(unsigned physicalWidth, unsigned physicalHeight, bool fullscreen);
42
+ ~Graphics();
43
+
44
+ // Undocumented until I have thought about this...
45
+ void setResolution(unsigned virtualWidth, unsigned virtualHeight);
46
+ // End of Undocumented
47
+
48
+ unsigned width() const;
49
+ unsigned height() const;
50
+ bool fullscreen() const;
51
+
52
+ //! Prepares the graphics object for drawing. Nothing must be drawn
53
+ //! without calling begin.
54
+ bool begin(Color clearWithColor = Color::BLACK);
55
+ //! Every call to begin must have a matching call to end.
56
+ void end();
57
+ //! Flushes the Z queue to the screen and starts a new one.
58
+ //! Useful for games that are *very* composite in nature (splitscreen).
59
+ void flush();
60
+
61
+ //! Finishes all pending Gosu drawing operations and executes
62
+ //! the following OpenGL code in a clean environment.
63
+ void beginGL();
64
+ //! Resets Gosu into its default rendering state.
65
+ void endGL();
66
+ //! (Experimental)
67
+ //! Schedules a custom GL functor to be executed at a certain Z level.
68
+ //! The functor is called in a clean GL context (as given by beginGL/endGL).
69
+ //! Gosu's rendering up to the Z level may not yet have been glFlush()ed.
70
+ //! Note: You may not call any Gosu rendering functions from within the
71
+ //! functor, and you must schedule it from within Window::draw's call tree.
72
+ void scheduleGL(const std::tr1::function<void()>& functor, ZPos z);
73
+
74
+ //! Enables clipping to a specified rectangle.
75
+ void beginClipping(double x, double y, double width, double height);
76
+ //! Disables clipping.
77
+ void endClipping();
78
+
79
+ //! Starts recording a macro. Cannot be nested.
80
+ void beginRecording();
81
+ //! Finishes building the macro and returns it as a drawable object.
82
+ //! The width and height affect nothing about the recording process,
83
+ //! the resulting macro will simply return these values when you ask
84
+ //! it.
85
+ //! Most usually, the return value is passed to Image::Image().
86
+ std::auto_ptr<Gosu::ImageData> endRecording(int width, int height);
87
+
88
+ //! Pushes one transformation onto the transformation stack.
89
+ void pushTransform(const Transform& transform);
90
+ //! Pops one transformation from the transformation stack.
91
+ void popTransform();
92
+
93
+ //! Draws a line from one point to another (last pixel exclusive).
94
+ //! Note: OpenGL lines are not reliable at all and may have a missing pixel at the start
95
+ //! or end point. Please only use this for debugging purposes. Otherwise, use a quad or
96
+ //! image to simulate lines, or contribute a better drawLine to Gosu.
97
+ void drawLine(double x1, double y1, Color c1,
98
+ double x2, double y2, Color c2,
99
+ ZPos z, AlphaMode mode = amDefault);
100
+
101
+ void drawTriangle(double x1, double y1, Color c1,
102
+ double x2, double y2, Color c2,
103
+ double x3, double y3, Color c3,
104
+ ZPos z, AlphaMode mode = amDefault);
105
+
106
+ void drawQuad(double x1, double y1, Color c1,
107
+ double x2, double y2, Color c2,
108
+ double x3, double y3, Color c3,
109
+ double x4, double y4, Color c4,
110
+ ZPos z, AlphaMode mode = amDefault);
111
+
112
+ //! Turns a portion of a bitmap into something that can be drawn on
113
+ //! this graphics object.
114
+ std::auto_ptr<ImageData> createImage(const Bitmap& src,
115
+ unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
116
+ unsigned borderFlags);
117
+ };
118
+ }
119
+
120
+ #endif
@@ -0,0 +1,66 @@
1
+ //! \file GraphicsBase.hpp
2
+ //! Contains general typedefs and enums related to graphics.
3
+
4
+ #ifndef GOSU_GRAPHICSBASE_HPP
5
+ #define GOSU_GRAPHICSBASE_HPP
6
+
7
+ #include <Gosu/Platform.hpp>
8
+ #include <limits>
9
+
10
+ namespace Gosu
11
+ {
12
+ //! Represents the Z position of something drawn with Gosu's graphics
13
+ //! system. Draw calls with higher ZPos values will cover those with a
14
+ //! lower ZPos value, that is, they are performed last.
15
+ typedef double ZPos;
16
+
17
+ //! Determines the way colors are combined when one is drawn onto
18
+ //! another.
19
+ enum AlphaMode
20
+ {
21
+ //! The color's channels will be interpolated. The alpha channel
22
+ //! specifies the opacity of the new color, 255 is full opacity.
23
+ amDefault,
24
+ //! The colors' channels will be added. The alpha channel specifies
25
+ //! the percentage of the new color's channels that will be added
26
+ //! to the old color's channels.
27
+ amAdd,
28
+ amAdditive = amAdd,
29
+ //! The color's channels will be multiplied with each other.
30
+ amMultiply
31
+ };
32
+
33
+ enum FontFlags
34
+ {
35
+ ffBold = 1,
36
+ ffItalic = 2,
37
+ ffUnderline = 4,
38
+ ffCombinations = 8
39
+ };
40
+
41
+ enum TextAlign
42
+ {
43
+ taLeft,
44
+ taRight,
45
+ taCenter,
46
+ taJustify
47
+ };
48
+
49
+ //! Flags that affect the tileability of an image.
50
+ enum BorderFlags
51
+ {
52
+ bfSmooth = 0,
53
+ bfTileableLeft = 1,
54
+ bfTileableTop = 2,
55
+ bfTileableRight = 4,
56
+ bfTileableBottom = 8,
57
+ bfTileable = bfTileableLeft | bfTileableTop | bfTileableRight | bfTileableBottom
58
+ };
59
+
60
+ #ifndef SWIG
61
+ // A not so useful optimization.
62
+ GOSU_DEPRECATED const double zImmediate = -std::numeric_limits<double>::infinity();
63
+ #endif
64
+ }
65
+
66
+ #endif
data/Gosu/IO.hpp ADDED
@@ -0,0 +1,259 @@
1
+ //! \file IO.hpp
2
+ //! Contains everything related to input and output.
3
+
4
+ #ifndef GOSU_IO_HPP
5
+ #define GOSU_IO_HPP
6
+
7
+ #include <cstddef>
8
+ #include <algorithm>
9
+ #include <memory>
10
+ #include <string>
11
+ #include <vector>
12
+
13
+ namespace Gosu
14
+ {
15
+ class Resource;
16
+
17
+ enum ByteOrder { boLittle, boBig, boDontCare };
18
+ #ifdef __BIG_ENDIAN__
19
+ const ByteOrder nativeByteOrder = boBig, otherByteOrder = boLittle;
20
+ #else
21
+ const ByteOrder nativeByteOrder = boLittle, otherByteOrder = boBig;
22
+ #endif
23
+
24
+ //! Utility class that points to a specific position in a resource
25
+ //! and offers an interface for sequential reading.
26
+ class Reader
27
+ {
28
+ const Resource* res;
29
+ std::size_t pos;
30
+
31
+ public:
32
+ Reader(const Resource& resource, std::size_t position)
33
+ : res(&resource), pos(position)
34
+ {
35
+ }
36
+
37
+ const Resource& resource() const
38
+ {
39
+ return *res;
40
+ }
41
+
42
+ std::size_t position() const
43
+ {
44
+ return pos;
45
+ }
46
+
47
+ void setPosition(std::size_t value)
48
+ {
49
+ // TODO: Check?
50
+ pos = value;
51
+ }
52
+
53
+ void seek(std::ptrdiff_t offset)
54
+ {
55
+ // TODO: Check?
56
+ pos += offset;
57
+ }
58
+
59
+ void read(void* destBuffer, std::size_t length);
60
+
61
+ //! Convenience function; equivalent to read(&t, sizeof t).
62
+ template<typename T>
63
+ void readPod(T& t, ByteOrder bo = boDontCare)
64
+ {
65
+ read(&t, sizeof t);
66
+ if (bo == otherByteOrder)
67
+ {
68
+ char* begin = reinterpret_cast<char*>(&t);
69
+ std::reverse(begin, begin + sizeof t);
70
+ }
71
+ }
72
+
73
+ //! Similar to readPod(T&), but returns the read value instead.
74
+ template<typename T>
75
+ T getPod(ByteOrder bo = boDontCare)
76
+ {
77
+ T t;
78
+ readPod<T>(t, bo);
79
+ return t;
80
+ }
81
+ };
82
+
83
+ //! Utility class that points to a specific position in a resource
84
+ //! and offers an interface for sequential writing.
85
+ class Writer
86
+ {
87
+ Resource* res;
88
+ std::size_t pos;
89
+
90
+ public:
91
+ Writer(Resource& resource, std::size_t position)
92
+ : res(&resource), pos(position)
93
+ {
94
+ }
95
+
96
+ Resource& resource() const
97
+ {
98
+ return *res;
99
+ }
100
+
101
+ std::size_t position() const
102
+ {
103
+ return pos;
104
+ }
105
+
106
+ void setPosition(std::size_t value)
107
+ {
108
+ // TODO: Check?
109
+ pos = value;
110
+ }
111
+
112
+ void seek(std::ptrdiff_t offset)
113
+ {
114
+ // TODO: Check?
115
+ pos += offset;
116
+ }
117
+
118
+ void write(const void* sourceBuffer, std::size_t length);
119
+
120
+ //! Convenience function; equivalent to write(&t, sizeof t).
121
+ template<typename T>
122
+ void writePod(const T& t, ByteOrder bo = boDontCare)
123
+ {
124
+ if (bo == otherByteOrder)
125
+ {
126
+ char buf[sizeof t];
127
+ const char* begin = reinterpret_cast<const char*>(&t);
128
+ std::reverse_copy(begin, begin + sizeof t, buf);
129
+ write(buf, sizeof buf);
130
+ }
131
+ else
132
+ write(&t, sizeof t);
133
+ }
134
+ };
135
+
136
+ //! Base class for resources. A resource in Gosu is nothing more but a
137
+ //! piece of binary data that can be read or written, for example files
138
+ //! or simply areas of allocated memory.
139
+ //! A resource always knows its size and can resize itself, thereby either
140
+ //! truncating its content or allocating room for more data.
141
+ class Resource
142
+ {
143
+ // Non-copyable
144
+ Resource(const Resource&);
145
+ Resource& operator=(const Resource&);
146
+
147
+ public:
148
+ Resource()
149
+ {
150
+ }
151
+
152
+ virtual ~Resource()
153
+ {
154
+ }
155
+
156
+ //! Convenience: Creates a new Reader that reads from the start of
157
+ //! the resource.
158
+ Reader frontReader() const
159
+ {
160
+ return Reader(*this, 0);
161
+ }
162
+
163
+ //! Convenience: Creates a new Writer that appends data at the
164
+ //! end of the resource.
165
+ Writer backWriter()
166
+ {
167
+ return Writer(*this, size());
168
+ }
169
+
170
+ virtual std::size_t size() const = 0;
171
+
172
+ virtual void resize(std::size_t newSize) = 0;
173
+
174
+ virtual void read(std::size_t offset, std::size_t length,
175
+ void* destBuffer) const = 0;
176
+
177
+ virtual void write(std::size_t offset, std::size_t length,
178
+ const void* sourceBuffer) = 0;
179
+ };
180
+
181
+ //! Piece of memory with the Resource interface.
182
+ class Buffer : public Resource
183
+ {
184
+ std::vector<char> buf;
185
+
186
+ public:
187
+ Buffer()
188
+ {
189
+ }
190
+
191
+ Buffer(const Buffer& other)
192
+ : buf(other.buf)
193
+ {
194
+ }
195
+
196
+ Buffer& operator=(const Buffer& other)
197
+ {
198
+ buf = other.buf;
199
+ return *this;
200
+ }
201
+
202
+ std::size_t size() const;
203
+ void resize(std::size_t newSize);
204
+
205
+ void read(std::size_t offset, std::size_t length,
206
+ void* destBuffer) const;
207
+
208
+ void write(std::size_t offset, std::size_t length,
209
+ const void* sourceBuffer);
210
+
211
+ const void* data() const
212
+ {
213
+ return &buf[0];
214
+ }
215
+
216
+ void* data()
217
+ {
218
+ return &buf[0];
219
+ }
220
+ };
221
+
222
+ enum FileMode
223
+ {
224
+ //! Opens an existing file for reading; throws an exception if the file
225
+ //! cannot be found.
226
+ fmRead,
227
+ //! Writes data to a file. If the file already exists, is emptied on
228
+ //! opening. If the file does not exist, it is created.
229
+ fmReplace,
230
+ //! Opens or creates a file with writing access, but does not clear
231
+ //! existing contents.
232
+ fmAlter
233
+ };
234
+
235
+ //! File with the Resource interface.
236
+ class File : public Resource
237
+ {
238
+ struct Impl;
239
+ const std::auto_ptr<Impl> pimpl;
240
+
241
+ public:
242
+ explicit File(const std::wstring& filename, FileMode mode = fmRead);
243
+ ~File();
244
+
245
+ std::size_t size() const;
246
+ void resize(std::size_t newSize);
247
+ void read(std::size_t offset, std::size_t length,
248
+ void* destBuffer) const;
249
+ void write(std::size_t offset, std::size_t length,
250
+ const void* sourceBuffer);
251
+ };
252
+
253
+ //! Loads a whole file into a buffer.
254
+ void loadFile(Buffer& buffer, const std::wstring& filename);
255
+ //! Creates or overwrites a file with the contents of a buffer.
256
+ void saveFile(const Buffer& buffer, const std::wstring& filename);
257
+ }
258
+
259
+ #endif