@@ -38,7 +38,7 @@ using std::unique_ptr;
3838 */
3939size_t U7object::number_of_objects () {
4040 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 ;
4242}
4343
4444/* *
@@ -51,7 +51,7 @@ size_t U7object::number_of_objects() {
5151unique_ptr<unsigned char []> U7object::retrieve (size_t & len) const {
5252 U7file* uf = U7FileManager::get_ptr ()->get_file_object (identifier, true );
5353 len = 0 ;
54- return uf ? uf->retrieve (objnumber, len) : nullptr ;
54+ return (uf != nullptr ) ? uf->retrieve (objnumber, len) : nullptr ;
5555}
5656
5757/* *
@@ -63,14 +63,14 @@ unique_ptr<unsigned char[]> U7object::retrieve(size_t& len) const {
6363 * @param objects Vector containing U7objects we will test.
6464 */
6565void U7multiobject::set_object (const std::vector<U7object>& objects) {
66- for (const auto & object : objects) {
66+ for (const auto & obj : objects) {
6767 size_t len;
6868 auto buf = object.retrieve (len);
6969 // Only len > 0 means a valid object.
7070 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 () );
7474 break ;
7575 }
7676 }
@@ -82,9 +82,9 @@ void U7multiobject::set_object(const std::vector<U7object>& objects) {
8282 * @param objnum Object number we are looking for.
8383 */
8484U7multiobject::U7multiobject (const File_spec& file0, int objnum)
85- : U7object(file0, objnum), buffer(nullptr ), length(0 ) {
85+ : buffer(nullptr ), length(0 ), object(file0, objnum ) {
8686 size_t len;
87- auto buf = U7object:: retrieve (len);
87+ auto buf = object. retrieve (len);
8888 // Only len > 0 means a valid object.
8989 if (buf && len > 0 ) {
9090 buffer = std::move (buf); // Gets deleted with class.
@@ -100,10 +100,9 @@ U7multiobject::U7multiobject(const File_spec& file0, int objnum)
100100 */
101101U7multiobject::U7multiobject (
102102 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)};
107106 set_object (objects);
108107}
109108
@@ -117,11 +116,10 @@ U7multiobject::U7multiobject(
117116U7multiobject::U7multiobject (
118117 const File_spec& file0, const File_spec& file1, const File_spec& file2,
119118 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)};
125123 set_object (objects);
126124}
127125
@@ -136,12 +134,10 @@ U7multiobject::U7multiobject(
136134U7multiobject::U7multiobject (
137135 const File_spec& file0, const File_spec& file1, const File_spec& file2,
138136 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)};
145141 set_object (objects);
146142}
147143
@@ -151,9 +147,9 @@ U7multiobject::U7multiobject(
151147 * @param objnum Object number we are looking for.
152148 */
153149U7multiobject::U7multiobject (const std::vector<File_spec>& files, int objnum)
154- : U7object( " " , objnum), buffer(nullptr ), length(0 ) {
150+ : buffer(nullptr ), length(0 ), object( " " , objnum ) {
155151 if (!files.empty ()) {
156- identifier = files[0 ];
152+ object. set_identifier ( files[0 ]) ;
157153 std::vector<U7object> objects;
158154 objects.reserve (files.size ());
159155 for (const auto & file : files) {
@@ -163,6 +159,18 @@ U7multiobject::U7multiobject(const std::vector<File_spec>& files, int objnum)
163159 }
164160}
165161
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+
166174/* *
167175 * Uses U7FileManager to get an U7file for the desired file.
168176 * @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 {
175183 if (length == 0 ) {
176184 // This means we didn't find the object on construction.
177185 return nullptr ;
178- } else {
179- auto buf = make_unique<unsigned char []>(len);
180- std::copy_n (buffer.get (), len, buf.get ());
181- return buf;
182186 }
187+ auto buf = make_unique<unsigned char []>(len);
188+ std::copy_n (buffer.get (), len, buf.get ());
189+ return buf;
183190}
0 commit comments