@@ -38,7 +38,7 @@ using std::unique_ptr;
38
38
*/
39
39
size_t U7object::number_of_objects () {
40
40
U7file* uf = U7FileManager::get_ptr ()->get_file_object (identifier, true );
41
- return uf ? uf->number_of_objects () : 0UL ;
41
+ return (uf != nullptr ) ? uf->number_of_objects () : 0UL ;
42
42
}
43
43
44
44
/* *
@@ -51,7 +51,7 @@ size_t U7object::number_of_objects() {
51
51
unique_ptr<unsigned char []> U7object::retrieve (size_t & len) const {
52
52
U7file* uf = U7FileManager::get_ptr ()->get_file_object (identifier, true );
53
53
len = 0 ;
54
- return uf ? uf->retrieve (objnumber, len) : nullptr ;
54
+ return (uf != nullptr ) ? uf->retrieve (objnumber, len) : nullptr ;
55
55
}
56
56
57
57
/* *
@@ -63,14 +63,14 @@ unique_ptr<unsigned char[]> U7object::retrieve(size_t& len) const {
63
63
* @param objects Vector containing U7objects we will test.
64
64
*/
65
65
void U7multiobject::set_object (const std::vector<U7object>& objects) {
66
- for (const auto & object : objects) {
66
+ for (const auto & obj : objects) {
67
67
size_t len;
68
68
auto buf = object.retrieve (len);
69
69
// Only len > 0 means a valid object.
70
70
if (buf && len > 0 ) {
71
- buffer = std::move (buf); // Gets deleted with class.
72
- length = len;
73
- identifier = object.get_identifier ();
71
+ buffer = std::move (buf); // Gets deleted with class.
72
+ length = len;
73
+ object.set_identifier (obj. get_identifier () );
74
74
break ;
75
75
}
76
76
}
@@ -82,9 +82,9 @@ void U7multiobject::set_object(const std::vector<U7object>& objects) {
82
82
* @param objnum Object number we are looking for.
83
83
*/
84
84
U7multiobject::U7multiobject (const File_spec& file0, int objnum)
85
- : U7object(file0, objnum), buffer(nullptr ), length(0 ) {
85
+ : buffer(nullptr ), length(0 ), object(file0, objnum ) {
86
86
size_t len;
87
- auto buf = U7object:: retrieve (len);
87
+ auto buf = object. retrieve (len);
88
88
// Only len > 0 means a valid object.
89
89
if (buf && len > 0 ) {
90
90
buffer = std::move (buf); // Gets deleted with class.
@@ -100,10 +100,9 @@ U7multiobject::U7multiobject(const File_spec& file0, int objnum)
100
100
*/
101
101
U7multiobject::U7multiobject (
102
102
const File_spec& file0, const File_spec& file1, int objnum)
103
- : U7object(file0, objnum), buffer(nullptr ), length(0 ) {
104
- std::vector<U7object> objects;
105
- objects.emplace_back (file1, objnum);
106
- objects.emplace_back (file0, objnum);
103
+ : buffer(nullptr ), length(0 ), object(file0, objnum) {
104
+ std::vector<U7object> objects{
105
+ U7object (file1, objnum), U7object (file0, objnum)};
107
106
set_object (objects);
108
107
}
109
108
@@ -117,11 +116,10 @@ U7multiobject::U7multiobject(
117
116
U7multiobject::U7multiobject (
118
117
const File_spec& file0, const File_spec& file1, const File_spec& file2,
119
118
int objnum)
120
- : U7object(file0, objnum), buffer(nullptr ), length(0 ) {
121
- std::vector<U7object> objects;
122
- objects.emplace_back (file2, objnum);
123
- objects.emplace_back (file1, objnum);
124
- objects.emplace_back (file0, objnum);
119
+ : buffer(nullptr ), length(0 ), object(file0, objnum) {
120
+ std::vector<U7object> objects{
121
+ U7object (file2, objnum), U7object (file1, objnum),
122
+ U7object (file0, objnum)};
125
123
set_object (objects);
126
124
}
127
125
@@ -136,12 +134,10 @@ U7multiobject::U7multiobject(
136
134
U7multiobject::U7multiobject (
137
135
const File_spec& file0, const File_spec& file1, const File_spec& file2,
138
136
const File_spec& file3, int objnum)
139
- : U7object(file0, objnum), buffer(nullptr ), length(0 ) {
140
- std::vector<U7object> objects;
141
- objects.emplace_back (file3, objnum);
142
- objects.emplace_back (file2, objnum);
143
- objects.emplace_back (file1, objnum);
144
- objects.emplace_back (file0, objnum);
137
+ : buffer(nullptr ), length(0 ), object(file0, objnum) {
138
+ std::vector<U7object> objects{
139
+ U7object (file3, objnum), U7object (file2, objnum),
140
+ U7object (file1, objnum), U7object (file0, objnum)};
145
141
set_object (objects);
146
142
}
147
143
@@ -151,9 +147,9 @@ U7multiobject::U7multiobject(
151
147
* @param objnum Object number we are looking for.
152
148
*/
153
149
U7multiobject::U7multiobject (const std::vector<File_spec>& files, int objnum)
154
- : U7object( " " , objnum), buffer(nullptr ), length(0 ) {
150
+ : buffer(nullptr ), length(0 ), object( " " , objnum ) {
155
151
if (!files.empty ()) {
156
- identifier = files[0 ];
152
+ object. set_identifier ( files[0 ]) ;
157
153
std::vector<U7object> objects;
158
154
objects.reserve (files.size ());
159
155
for (const auto & file : files) {
@@ -163,6 +159,18 @@ U7multiobject::U7multiobject(const std::vector<File_spec>& files, int objnum)
163
159
}
164
160
}
165
161
162
+ U7multiobject::U7multiobject (const U7multiobject& other)
163
+ : buffer(nullptr ), length(0 ), object(other.object) {
164
+ buffer = make_unique<unsigned char []>(other.length );
165
+ std::copy_n (other.buffer .get (), other.length , buffer.get ());
166
+ }
167
+
168
+ U7multiobject& U7multiobject::operator =(const U7multiobject& rhs) {
169
+ U7multiobject tmp (rhs);
170
+ std::swap (*this , tmp);
171
+ return *this ;
172
+ }
173
+
166
174
/* *
167
175
* Uses U7FileManager to get an U7file for the desired file.
168
176
* @param len Receives the size of desired object, if it exists
@@ -175,9 +183,8 @@ unique_ptr<unsigned char[]> U7multiobject::retrieve(size_t& len) const {
175
183
if (length == 0 ) {
176
184
// This means we didn't find the object on construction.
177
185
return nullptr ;
178
- } else {
179
- auto buf = make_unique<unsigned char []>(len);
180
- std::copy_n (buffer.get (), len, buf.get ());
181
- return buf;
182
186
}
187
+ auto buf = make_unique<unsigned char []>(len);
188
+ std::copy_n (buffer.get (), len, buf.get ());
189
+ return buf;
183
190
}
0 commit comments