tbx  0.7.3
reseditor.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  * reseditor.h
26  *
27  * Created on: 29 Apr 2010
28  * Author: alanb
29  */
30 
31 #ifndef TBX_RESEDITOR_H_
32 #define TBX_RESEDITOR_H_
33 
34 #include "resobject.h"
35 #include <vector>
36 
37 namespace tbx {
38 
39 namespace res {
40 
45 class ResEditor
46 {
47  char *_header;
48  std::vector<ResObject> _objects;
49 
50 public:
51  ResEditor();
52  virtual ~ResEditor();
53 
57  const ResFileHeader *header() const {return reinterpret_cast<ResFileHeader *>(_header);}
58 
62  typedef std::vector<ResObject>::const_iterator const_iterator;
66  typedef std::vector<ResObject>::iterator iterator;
67 
73  const_iterator begin() const {return _objects.begin();}
79  const_iterator end() const {return _objects.end();}
80  const_iterator find(std::string name) const;
81 
87  iterator begin() {return _objects.begin();}
93  iterator end() {return _objects.end();}
94  iterator find(std::string name);
95 
99  unsigned int count() const {return _objects.size();}
100  bool contains(std::string name) const;
101  const ResObject &object(std::string name) const;
102 
103  void clear();
104  void add(ResObject obj);
105  void replace(ResObject obj);
106  void erase(std::string name);
107 
108  iterator insert(iterator before, ResObject obj);
109  iterator erase(iterator where);
110  void replace(iterator where, ResObject obj);
111 
112  bool load(std::string file_name);
113  bool save(std::string file_name);
114 
115 private:
116  // Only editor can change header
117  ResFileHeader *header() {return reinterpret_cast<ResFileHeader *>(_header);}
118 
119 
120 };
121 
122 }
123 
124 }
125 
126 #endif /* TBX_RESEDITOR_H_ */
const_iterator end() const
Get constant iterator to the end of the objects.
Definition: reseditor.h:79
unsigned int count() const
Return number of objects.
Definition: reseditor.h:99
std::vector< ResObject >::const_iterator const_iterator
Constant iterator to iterate through the objects being edited.
Definition: reseditor.h:62
void clear()
Remove all objects from the editor.
Definition: reseditor.cc:60
const ResFileHeader * header() const
Return header details of the file.
Definition: reseditor.h:57
bool contains(std::string name) const
Check if editor contains the named object.
Definition: reseditor.cc:146
const_iterator begin() const
Get constant iterator to first object.
Definition: reseditor.h:73
std::vector< ResObject >::iterator iterator
Iterator to iterate through the objects being edited.
Definition: reseditor.h:66
const ResObject & object(std::string name) const
Get object.
Definition: reseditor.cc:157
const_iterator find(std::string name) const
Find object with given name.
Definition: reseditor.cc:207
void erase(std::string name)
Erase object with given name.
Definition: reseditor.cc:194
Structure representing the header of a resource file.
Definition: resstruct.h:42
iterator begin()
Get iterator to first object.
Definition: reseditor.h:87
void add(ResObject obj)
Add a new object.
Definition: reseditor.cc:170
Base class for a resource object that can be edited.
Definition: resobject.h:52
void replace(ResObject obj)
Replace object with same name as object given.
Definition: reseditor.cc:182
iterator end()
Get iterator to the end of the objects.
Definition: reseditor.h:93
bool save(std::string file_name)
Save resources to the name file.
Definition: reseditor.cc:113
ResEditor()
Construct an empty resource file.
Definition: reseditor.cc:44
Class to allow creation, loading, editing and saving of a toolbox resource file.
Definition: reseditor.h:45
iterator insert(iterator before, ResObject obj)
Insert object before given object.
Definition: reseditor.cc:239
bool load(std::string file_name)
Load resources from a file.
Definition: reseditor.cc:71