LibPkg
sprite_file.h
Go to the documentation of this file.
1 // This file is part of LibPkg.
2 //
3 // Copyright 2003-2020 Graham Shaw
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef LIBPKG_SPRITE_FILE
18 #define LIBPKG_SPRITE_FILE
19 
20 #include <map>
21 #include <string>
22 #include <fstream>
23 #include <stdexcept>
24 
25 namespace pkg {
26 
27 using std::string;
28 
31 {
32 public:
33  class sprite_info;
34 
36  typedef unsigned long uint32;
37 
38  class not_found;
39  class already_exists;
40  class corrupt;
41 private:
43  class cmp_nocase
44  {
45  public:
51  bool operator()(const string& lhs,const string& rhs) const;
52  };
53 
55  typedef std::map<string,sprite_info,cmp_nocase> map_type;
56 
58  typedef map_type::const_iterator const_iterator;
59 
61  string _pathname;
62 
64  mutable std::fstream _sfs;
65 
67  map_type _directory;
68 
70  uint32 _free;
71 public:
76  sprite_file(const string& pathname,bool writable=false);
77 private:
82  sprite_file(const sprite_file&);
83 public:
85  ~sprite_file();
86 private:
91  sprite_file& operator=(const sprite_file&);
92 public:
96  unsigned int size() const
97  { return _directory.size(); }
98 
103  const sprite_info& operator[](unsigned int index) const;
104 
110  const sprite_info* find(const string& name) const;
111 
116  void copy(sprite_file& src,const string& name);
117 };
118 
121 {
122 private:
124  uint32 _offset;
125 
127  uint32 _size;
128 
130  string _name;
131 public:
133  sprite_info();
134 
138  sprite_info(std::istream& in);
139 
141  ~sprite_info();
142 
146  const uint32 offset() const
147  { return _offset; }
148 
152  const uint32 size() const
153  { return _size; }
154 
158  const string& name() const
159  { return _name; }
160 };
161 
164  public std::runtime_error
165 {
166 public:
170  not_found(const string& name);
171 
176  static string make_message(const string& name);
177 };
178 
181  public std::runtime_error
182 {
183 public:
187  already_exists(const string& name);
188 
193  static string make_message(const string& name);
194 };
195 
198  public std::runtime_error
199 {
200 public:
202  corrupt();
203 };
204 
205 }; /* namespace pkg */
206 
207 #endif
const uint32 offset() const
Get file offset.
Definition: sprite_file.h:146
const string & name() const
Get sprite name.
Definition: sprite_file.h:158
The namespace used to hold the package management library.
Definition: auto_dir.cc:23
sprite_file(const string &pathname, bool writable=false)
Construct sprite file object.
Definition: sprite_file.cc:138
void copy(sprite_file &src, const string &name)
Copy sprite from another sprite file.
Definition: sprite_file.cc:167
An interface class to represent a sprite file.
Definition: sprite_file.h:30
unsigned long uint32
A type to represent an unsigned 32-bit integer.
Definition: sprite_file.h:33
An exception class for reporting corrupt-sprite-file errors.
Definition: sprite_file.h:197
unsigned int size() const
Get number of sprites.
Definition: sprite_file.h:96
const uint32 size() const
Get size.
Definition: sprite_file.h:152
An exception class for reporting already-exists errors.
Definition: sprite_file.h:180
A class to represent a sprite within a sprite file.
Definition: sprite_file.h:120
An exception class for reporting not-found errors.
Definition: sprite_file.h:163
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:161
~sprite_file()
Destroy sprite file object.
Definition: sprite_file.cc:216

Reference Manual LibPkg Version 0.9.0 (4 Sep 2020)