tbx  0.7.6
resfile.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_RES_RESFILE_H_
26 #define TBX_RES_RESFILE_H_
27 
28 #include "resobject.h"
29 #include "resiteratorbase.h"
30 
31 namespace tbx {
32 
33 namespace res {
34 
35 
42 class ResFile
43 {
44  char *_res;
45  int _length;
46 
47 public:
48  ResFile(void);
49  ~ResFile(void);
50 
51  bool load(const std::string &fname);
52 
53  bool contains(std::string name) const;
54  ResObject object(std::string name) const;
55 
59  class const_iterator : public ResIteratorBase<ResFile>
60  {
61  const_iterator(const ResFile *res_file, int offset) : ResIteratorBase<ResFile>(res_file, offset) {}
62  friend class ResFile;
63  public:
82  };
83  friend class const_iterator;
84 
90  const_iterator begin() const {return const_iterator(this, first_offset());}
96  const_iterator end() const {return const_iterator(this, end_offset());}
108  const_iterator cend() const {return const_iterator(this, end_offset());}
109  const_iterator find(std::string name) const;
110 
111 protected:
112  int first_offset() const;
113  int end_offset() const;
114  void next_object(int &offset) const;
115  ResObject at_offset(int offset) const;
116 };
117 
118 }
119 }
120 
121 #endif
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::res::ResObject
Base class for a resource object that can be edited.
Definition: resobject.h:53
tbx::res::ResFile::const_iterator::operator++
const_iterator & operator++()
Increment iterator.
Definition: resfile.h:69
tbx::res::ResIteratorBase< ResFile >::_offset
int _offset
Offset of current item being iterated.
Definition: resiteratorbase.h:17
tbx::res::ResFile::end_offset
int end_offset() const
Offset of object after last object.
Definition: resfile.cc:172
tbx::res::ResFile::contains
bool contains(std::string name) const
Returns true if the file contains the named object.
Definition: resfile.cc:141
tbx::res::ResFile::object
ResObject object(std::string name) const
Get resource object with given name.
Definition: resfile.cc:151
tbx::res::ResFile::load
bool load(const std::string &fname)
Load a resource file.
Definition: resfile.cc:50
tbx::res::ResFile::begin
const_iterator begin() const
Get constant iterator to first object.
Definition: resfile.h:90
tbx::res::ResFile::next_object
void next_object(int &offset) const
Move to next object.
Definition: resfile.cc:180
tbx::res::ResFile::cend
const_iterator cend() const
Get constant iterator to end object.
Definition: resfile.h:108
tbx::res::ResFile::first_offset
int first_offset() const
Return offset to first object in file.
Definition: resfile.cc:161
tbx::res::ResFile::at_offset
ResObject at_offset(int offset) const
Return object at given offset.
Definition: resfile.cc:203
tbx::res::ResIteratorBase
Base class for Resource component iterators.
Definition: resiteratorbase.h:14
tbx::res::ResFile::const_iterator::operator++
const_iterator operator++(int)
Increment iterator.
Definition: resfile.h:75
tbx::res::ResIteratorBase< ResFile >::_object
const ResFile * _object
Reference to object being iterated.
Definition: resiteratorbase.h:16
tbx::res::ResFile::find
const_iterator find(std::string name) const
Find name in resource.
Definition: resfile.cc:128
tbx::res::ResFile::const_iterator::operator*
ResObject operator*() const
Get object reference by iterator.
Definition: resfile.h:81
tbx::res::ResFile
Load and give read only access to a resource file.
Definition: resfile.h:43
tbx::res::ResFile::const_iterator
Constant iterator of objects in this resource file.
Definition: resfile.h:60
tbx::res::ResFile::end
const_iterator end() const
Get constant iterator to end object.
Definition: resfile.h:96
tbx::res::ResFile::cbegin
const_iterator cbegin() const
Get constant iterator to first object.
Definition: resfile.h:102