tbx  0.7.5
resobject.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  * resobject.h
26  *
27  * Created on: 29 Apr 2010
28  * Author: alanb
29  */
30 
31 #ifndef RESOBJECT_H_
32 #define RESOBJECT_H_
33 
34 #include "resbase.h"
35 #include <string>
36 #include <iostream>
37 
38 #include "resstruct.h"
39 
40 namespace tbx {
41 
42 class Application;
43 typedef int *OsSpriteAreaPtr;
44 
45 namespace res {
46 
47 class ResFile;
48 
52 class ResObject : public ResBase
53 {
54  ResObject(ResObjectHeader *object_header, ResData *data);
55  ResObject(ResObjectHeader *object_header);
56  friend class tbx::Application;
57  friend class ResFile;
58  static OsSpriteAreaPtr _sprite_area_ptr;
59 public:
60  ResObject(const ResObject &other);
61  virtual ~ResObject();
62 
63  ResObject &operator=(const ResObject &other);
64 
65  static ResObject *load(std::istream &file);
66  bool save(std::ostream &file);
67 
68  static OsSpriteAreaPtr client_sprite_pointer();
69  static void client_sprite_pointer(OsSpriteAreaPtr ptr);
70 
74  const ResObjectHeader *object_header() const {return reinterpret_cast<const ResObjectHeader *>(_impl->header());}
75 
79  const char *name() const {return object_header()->name;}
80 
84  void name(std::string name);
85 
89  int class_id() const {return object_header()->class_id;}
93  int object_version() const {return object_header()->version;}
94  void object_version(int new_version);
95 
100  unsigned int object_flags() const {return object_header()->flags;}
101  void object_flags(unsigned int flags);
102 
108  bool create_on_load() const {return (object_header()->flags & 1) != 0;}
109  void create_on_load(bool value);
115  bool show_on_create() const {return (object_header()->flags & 2) != 0;}
116  void show_on_create(bool value);
122  bool shared() const {return (object_header()->flags & 4) != 0;}
123  void shared(bool value);
129  bool ancestor() const {return (object_header()->flags & 8) != 0;}
130  void ancestor(bool value);
131 
132 
133  void check_class_id(int class_id) const;
134 
135 
136 protected:
137  ResObject(std::string name, int class_id, int version, int object_size);
138 
142  ResObjectHeader *object_header() {return reinterpret_cast<ResObjectHeader *>(_impl->header());}
143 
147  void make_writeable();
148 
156  ResData *component_data(char *new_body, int offset, int size) const {return _impl->component_data(new_body, offset, size);}
157  void insert_component(int offset, const ResImpl *comp_impl);
158  void replace_component(int offset, int old_size, const ResImpl *comp_impl);
159  void erase_component(int offset, int size);
160 };
161 
162 
163 }
164 
165 }
166 
167 #endif /* RESOBJECT_H_ */
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
int * OsSpriteAreaPtr
Type for pointer to underlying RISC OS Sprite area.
Definition: sprite.h:214
int object_version() const
Return version number * 100.
Definition: resobject.h:93
Base class for objects, gadgets and menu items from ressources.
Definition: resbase.h:252
int class_id
Object class.
Definition: resstruct.h:78
unsigned int object_flags() const
object flags - use methods below for named access to the bits of the flags
Definition: resobject.h:100
void check_class_id(int class_id) const
Check if this objects class id is as specified.
Definition: resobject.cc:383
void erase_component(int offset, int size)
Erase a component of the given size.
Definition: resobject.cc:424
Classes to use/edit toolbox resources in memory.
The main application class.
Definition: application.h:78
static OsSpriteAreaPtr client_sprite_pointer()
Get pointer to client sprite area.
Definition: resobject.cc:125
bool ancestor() const
Get ancestor flags.
Definition: resobject.h:129
bool create_on_load() const
Get create on load flag.
Definition: resobject.h:108
int version
version * 100
Definition: resstruct.h:80
char name[12]
Null terminated name.
Definition: resstruct.h:81
virtual ~ResObject()
Destructor.
Definition: resobject.cc:102
bool shared() const
Get shared flag.
Definition: resobject.h:122
Common header for all resource objects.
Definition: resstruct.h:76
const char * name() const
Return pointer to name of object.
Definition: resobject.h:79
void make_writeable()
Make object writeable, call before any change.
Definition: resobject.cc:273
void insert_component(int offset, const ResImpl *comp_impl)
Insert a component in an object.
Definition: resobject.cc:397
ResObject & operator=(const ResObject &other)
Assignment.
Definition: resobject.cc:109
static ResObject * load(std::istream &file)
Load a resource object from a stream.
Definition: resobject.cc:146
Load and give read only access to a resource file.
Definition: resfile.h:42
ResObjectHeader * object_header()
Return a pointer to the header information for this object.
Definition: resobject.h:142
Base class for a resource object that can be edited.
Definition: resobject.h:52
bool show_on_create() const
Get show on create flags.
Definition: resobject.h:115
ResData * component_data(char *new_body, int offset, int size) const
Extract a copy of a components data from this object.
Definition: resobject.h:156
bool save(std::ostream &file)
Save a resource object to a stream.
Definition: resobject.cc:216
int flags
flags
Definition: resstruct.h:79
const ResObjectHeader * object_header() const
Return a pointer to the header information for this object.
Definition: resobject.h:74
int class_id() const
Return class id of object.
Definition: resobject.h:89
void replace_component(int offset, int old_size, const ResImpl *comp_impl)
Replace a component.
Definition: resobject.cc:411
ResImpl * _impl
Internal Resource implementation.
Definition: resbase.h:255