LibPkg
sprite_file.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 // Copyright © 2004-2005 Graham Shaw.
3 // Distribution and use are subject to the GNU Lesser General Public License,
4 // a copy of which may be found in the file !LibPkg.Copyright.
5 
6 #ifndef LIBPKG_SPRITE_FILE
7 #define LIBPKG_SPRITE_FILE
8 
9 #include <map>
10 #include <string>
11 #include <fstream>
12 #include <stdexcept>
13 
14 namespace pkg {
15 
16 using std::string;
17 
20 {
21 public:
22  class sprite_info;
23 
25  typedef unsigned long uint32;
26 
27  class not_found;
28  class already_exists;
29  class corrupt;
30 private:
32  class cmp_nocase
33  {
34  public:
40  bool operator()(const string& lhs,const string& rhs) const;
41  };
42 
44  typedef std::map<string,sprite_info,cmp_nocase> map_type;
45 
47  typedef map_type::const_iterator const_iterator;
48 
50  string _pathname;
51 
53  mutable std::fstream _sfs;
54 
56  map_type _directory;
57 
59  uint32 _free;
60 public:
65  sprite_file(const string& pathname,bool writable=false);
66 private:
71  sprite_file(const sprite_file&);
72 public:
74  ~sprite_file();
75 private:
80  sprite_file& operator=(const sprite_file&);
81 public:
85  unsigned int size() const
86  { return _directory.size(); }
87 
92  const sprite_info& operator[](unsigned int index) const;
93 
99  const sprite_info* find(const string& name) const;
100 
105  void copy(sprite_file& src,const string& name);
106 };
107 
110 {
111 private:
113  uint32 _offset;
114 
116  uint32 _size;
117 
119  string _name;
120 public:
122  sprite_info();
123 
127  sprite_info(std::istream& in);
128 
130  ~sprite_info();
131 
135  const uint32 offset() const
136  { return _offset; }
137 
141  const uint32 size() const
142  { return _size; }
143 
147  const string& name() const
148  { return _name; }
149 };
150 
153  public std::runtime_error
154 {
155 public:
159  not_found(const string& name);
160 
165  static string make_message(const string& name);
166 };
167 
170  public std::runtime_error
171 {
172 public:
176  already_exists(const string& name);
177 
182  static string make_message(const string& name);
183 };
184 
187  public std::runtime_error
188 {
189 public:
191  corrupt();
192 };
193 
194 }; /* namespace pkg */
195 
196 #endif
const uint32 offset() const
Get file offset.
Definition: sprite_file.h:135
const string & name() const
Get sprite name.
Definition: sprite_file.h:147
The namespace used to hold the package management library.
Definition: auto_dir.cc:12
sprite_file(const string &pathname, bool writable=false)
Construct sprite file object.
Definition: sprite_file.cc:127
void copy(sprite_file &src, const string &name)
Copy sprite from another sprite file.
Definition: sprite_file.cc:156
An interface class to represent a sprite file.
Definition: sprite_file.h:19
unsigned long uint32
A type to represent an unsigned 32-bit integer.
Definition: sprite_file.h:22
An exception class for reporting corrupt-sprite-file errors.
Definition: sprite_file.h:186
unsigned int size() const
Get number of sprites.
Definition: sprite_file.h:85
const uint32 size() const
Get size.
Definition: sprite_file.h:141
An exception class for reporting already-exists errors.
Definition: sprite_file.h:169
A class to represent a sprite within a sprite file.
Definition: sprite_file.h:109
An exception class for reporting not-found errors.
Definition: sprite_file.h:152
const sprite_info & operator[](unsigned int index) const
Get const sprite information record at index.
const sprite_info * find(const string &name) const
Find const sprite information record for sprite name.
Definition: sprite_file.cc:150
~sprite_file()
Destroy sprite file object.
Definition: sprite_file.cc:205

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)