Browse Source

Refactored Subfile class and renamed to SubFile

Ivan Arkhipov 7 years ago
parent
commit
33db97b143
2 changed files with 32 additions and 33 deletions
  1. 11 8
      include/SubFile.h
  2. 21 25
      src/SubFile.cpp

+ 11 - 8
include/Subfile.h → include/SubFile.h

@@ -20,17 +20,20 @@ namespace LOTRO_DAT
 
     enum FILE_TYPE : int;
 
-    class Subfile
+    class SubFile
     {
         friend class DatFile;
 		friend class SubDirectory;
     public:
-        Subfile();
-		Subfile(DatFile *dat, const BinaryData &header);
-		Subfile(DatFile *dat, long long dictionary_offset, long long fragments_count, long long unknown1,
+        SubFile() = delete;
+        explicit SubFile(const SubFile &other) = delete;
+		SubFile &operator =(const SubFile &other) = delete;
+
+        SubFile(DatFile &dat, const BinaryData &header);
+		SubFile(DatFile &dat, long long dictionary_offset, long long fragments_count, long long unknown1,
                 long long file_id, long long file_offset, long long file_size, long long timestamp, long long version,
                 long long block_size);
-        Subfile& operator=(const Subfile &b);
+		virtual ~SubFile() = default;
 
         virtual FILE_TYPE FileType() const;
         virtual std::string Extension() const;
@@ -51,13 +54,13 @@ namespace LOTRO_DAT
         long long block_size() const;
 		long long unknown2() const;
 
-		bool operator ==(const Subfile &b) const;
-		bool operator !=(const Subfile &b) const;
+		bool operator ==(const SubFile &b) const;
+		bool operator !=(const SubFile &b) const;
 
         long long category;
 
 	protected:
-		DatFile *dat_;
+		DatFile &dat_;
         long long dictionary_offset_;
 
         long long unknown1_;

+ 21 - 25
src/Subfile.cpp → src/SubFile.cpp

@@ -2,7 +2,7 @@
 // Created by Иван_Архипов on 01.11.2017.
 //
 
-#include "Subfile.h"
+#include "SubFile.h"
 #include "BinaryData.h"
 #include "DatFile.h"
 #include "SubfileData.h"
@@ -16,13 +16,9 @@ const long long MAXSIZE = 50ll * 1024ll * 1024ll; // Setting maximal file size 5
                                                   // of Subfiles and Subdirectories search in DatFile.
 namespace LOTRO_DAT {
 
-    Subfile::Subfile() = default;
-
-    Subfile::Subfile(DatFile *dat, const BinaryData &header) {
+    SubFile::SubFile(DatFile &dat, const BinaryData &header) : dat_(dat) {
         category = 0;
 
-        dat_ = dat;
-
         unknown1_ = header.ToNumber<4>(0); // unknown1
         file_id_ = header.ToNumber<4>(4); // file_id
         file_offset_ = header.ToNumber<4>(8); // file_offset
@@ -33,7 +29,7 @@ namespace LOTRO_DAT {
         unknown2_ = header.ToNumber<4>(28); // unknown2
     }
 
-    Subfile::Subfile(DatFile *dat, long long dictionary_offset, long long unknown1, long long file_id,
+    SubFile::SubFile(DatFile &dat, long long dictionary_offset, long long unknown1, long long file_id,
                                 long long file_offset,
                                 long long file_size, long long timestamp, long long version, long long block_size, long long unknown2) :
             category(0), dat_(dat), dictionary_offset_(dictionary_offset), unknown1_(unknown1), file_id_(file_id),
@@ -41,7 +37,7 @@ namespace LOTRO_DAT {
             file_size_(file_size), timestamp_(timestamp), version_(version), block_size_(block_size), unknown2_(unknown2) {
 
         if (file_size_ > MAXSIZE) {
-            LOG(ERROR) << "Bad Subfile::Subfile() - File size of file " << file_id << " with offset " << file_offset
+            LOG(ERROR) << "Bad SubFile::SubFile() - File size of file " << file_id << " with offset " << file_offset
                        <<" is too much... Maybe it's incorrect..?";
             file_id_ = -1;
             return;
@@ -51,39 +47,39 @@ namespace LOTRO_DAT {
     /// Typical getters of private fields, if there's need for getting information about SubFile from outside class.
 
 
-    long long Subfile::dictionary_offset() const {
+    long long SubFile::dictionary_offset() const {
         return dictionary_offset_;
     }
 
-    long long Subfile::unknown1() const {
+    long long SubFile::unknown1() const {
         return unknown1_;
     }
 
-    long long Subfile::file_id() const {
+    long long SubFile::file_id() const {
         return file_id_;
     }
 
-    long long Subfile::file_offset() const {
+    long long SubFile::file_offset() const {
         return file_offset_;
     }
 
-    long long Subfile::file_size() const {
+    long long SubFile::file_size() const {
         return file_size_;
     }
 
-    long long Subfile::timestamp() const {
+    long long SubFile::timestamp() const {
         return timestamp_;
     }
 
-    long long Subfile::version() const {
+    long long SubFile::version() const {
         return version_;
     }
 
-    long long Subfile::block_size() const {
+    long long SubFile::block_size() const {
         return block_size_;
     }
 
-    long long Subfile::unknown2() const {
+    long long SubFile::unknown2() const {
         return unknown2_;
     }
 
@@ -91,7 +87,7 @@ namespace LOTRO_DAT {
     /// Virtual function, can (and should) be redefined in child class, otherwise an exception will be thrown while exporting/importing file.
     /// Returns enum FILE_TYPE value, which is declared in DatFile.h
 
-    FILE_TYPE Subfile::FileType() const {
+    FILE_TYPE SubFile::FileType() const {
         LOG(ERROR) << "INCORRECT IMPLEMENTATION!";
         return UNKNOWN;
     }
@@ -100,7 +96,7 @@ namespace LOTRO_DAT {
     /// Virtual function, can (and should) be redefined in child class, otherwise an exception will be thrown while exporting/importing file.
     /// Returns std::string with extension, beggined with '.', ex. ".jpg", ".txt" and so on;
 
-    std::string Subfile::Extension() const {
+    std::string SubFile::Extension() const {
         LOG(ERROR) << "INCORRECT IMPLEMENTATION!";
         return ".subfile";
     }
@@ -114,7 +110,7 @@ namespace LOTRO_DAT {
     ///  3) field options - YAML field, which consists of some parameters of file such as file_id, extension and so on.
     /// Returns true if preparation was success. Otherwise returns false;
 
-    SubfileData Subfile::PrepareForExport(const BinaryData &) {
+    SubfileData SubFile::PrepareForExport(const BinaryData &) {
         LOG(ERROR) << "INCORRECT IMPLEMENTATION!";
         return SubfileData();
     }
@@ -128,12 +124,12 @@ namespace LOTRO_DAT {
     ///  3) const field options - YAML field, which consists of some parameters of file such as file_id, extension and so on.
     /// Returns BinaryData - bytes array, prepared for writing in .dat file
 
-    BinaryData Subfile::MakeForImport(const BinaryData &, const SubfileData &) {
+    BinaryData SubFile::MakeForImport(const BinaryData &, const SubfileData &) {
         LOG(ERROR) << "INCORRECT IMPLEMENTATION!";
         return BinaryData(0);
     }
 
-    BinaryData Subfile::MakeHeaderData() const {
+    BinaryData SubFile::MakeHeaderData() const {
         BinaryData header = BinaryData::FromNumber<4>(unknown1_)
                             + BinaryData::FromNumber<4>(file_id_)
                             + BinaryData::FromNumber<4>(file_offset_)
@@ -146,7 +142,7 @@ namespace LOTRO_DAT {
     }
 
 
-    bool Subfile::operator==(const Subfile &b) const {
+    bool SubFile::operator==(const SubFile &b) const {
         return unknown1_ == b.unknown1_
                && file_id_ == b.file_id_
                && file_offset_ == b.file_offset_
@@ -157,11 +153,11 @@ namespace LOTRO_DAT {
                && unknown2_ == b.unknown2_;
     }
 
-    bool Subfile::operator!=(const Subfile &b) const {
+    bool SubFile::operator!=(const SubFile &b) const {
         return !(*this == b);
     }
 
-    Subfile &Subfile::operator=(const Subfile &b) {
+    SubFile &SubFile::operator=(const SubFile &b) {
         if (*this == b)
             return *this;