Kaynağa Gözat

Merge pull request #1580 from rilian-la-te/modernize-log-fs-events

Modernize next part
Ivan Savenko 2 yıl önce
ebeveyn
işleme
c4de8a5cd0

+ 1 - 1
lib/events/ApplyDamage.cpp

@@ -28,7 +28,7 @@ SubscriptionRegistry<ApplyDamage> * ApplyDamage::getRegistry()
 
 CApplyDamage::CApplyDamage(const Environment * env_, BattleStackAttacked * pack_, std::shared_ptr<battle::Unit> target_)
 	: pack(pack_),
-	target(target_)
+	target(std::move(target_))
 {
 	initalDamage = pack->damageAmount;
 }

+ 7 - 7
lib/filesystem/AdapterLoaders.cpp

@@ -48,7 +48,7 @@ std::unordered_set<ResourceID> CMappedFileLoader::getFilteredFiles(std::function
 {
 	std::unordered_set<ResourceID> foundID;
 
-	for (auto & file : fileList)
+	for(const auto & file : fileList)
 	{
 		if (filter(file.first))
 			foundID.insert(file.first);
@@ -69,7 +69,7 @@ CFilesystemList::~CFilesystemList()
 std::unique_ptr<CInputStream> CFilesystemList::load(const ResourceID & resourceName) const
 {
 	// load resource from last loader that have it (last overridden version)
-	for (auto & loader : boost::adaptors::reverse(loaders))
+	for(const auto & loader : boost::adaptors::reverse(loaders))
 	{
 		if (loader->existsResource(resourceName))
 			return loader->load(resourceName);
@@ -81,7 +81,7 @@ std::unique_ptr<CInputStream> CFilesystemList::load(const ResourceID & resourceN
 
 bool CFilesystemList::existsResource(const ResourceID & resourceName) const
 {
-	for (auto & loader : loaders)
+	for(const auto & loader : loaders)
 		if (loader->existsResource(resourceName))
 			return true;
 	return false;
@@ -115,7 +115,7 @@ std::set<boost::filesystem::path> CFilesystemList::getResourceNames(const Resour
 
 void CFilesystemList::updateFilteredFiles(std::function<bool(const std::string &)> filter) const
 {
-	for (auto & loader : loaders)
+	for(const auto & loader : loaders)
 		loader->updateFilteredFiles(filter);
 }
 
@@ -123,8 +123,8 @@ std::unordered_set<ResourceID> CFilesystemList::getFilteredFiles(std::function<b
 {
 	std::unordered_set<ResourceID> ret;
 
-	for (auto & loader : loaders)
-		for (auto & entry : loader->getFilteredFiles(filter))
+	for(const auto & loader : loaders)
+		for(const auto & entry : loader->getFilteredFiles(filter))
 			ret.insert(entry);
 
 	return ret;
@@ -155,7 +155,7 @@ std::vector<const ISimpleResourceLoader *> CFilesystemList::getResourcesWithName
 {
 	std::vector<const ISimpleResourceLoader *> ret;
 
-	for (auto & loader : loaders)
+	for(const auto & loader : loaders)
 		boost::range::copy(loader->getResourcesWithName(resourceName), std::back_inserter(ret));
 
 	return ret;

+ 5 - 5
lib/filesystem/CArchiveLoader.cpp

@@ -125,7 +125,7 @@ void CArchiveLoader::initVIDArchive(const std::string &mountPoint, CFileInputStr
 		offsets.insert(entry.offset);
 		entries[ResourceID(mountPoint + entry.name)] = entry;
 	}
-	offsets.insert((int)fileStream.getSize());
+	offsets.insert(static_cast<int>(fileStream.getSize()));
 
 	// now when we know position of all files their sizes can be set correctly
 	for (auto & entry : entries)
@@ -201,7 +201,7 @@ std::unordered_set<ResourceID> CArchiveLoader::getFilteredFiles(std::function<bo
 {
 	std::unordered_set<ResourceID> foundID;
 
-	for (auto & file : entries)
+	for(const auto & file : entries)
 	{
 		if (filter(file.first))
 			foundID.insert(file.first);
@@ -209,7 +209,7 @@ std::unordered_set<ResourceID> CArchiveLoader::getFilteredFiles(std::function<bo
 	return foundID;
 }
 
-void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, CInputStream & fileStream, ArchiveEntry entry)
+void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, CInputStream & fileStream, const ArchiveEntry & entry) const
 {
 	si64 currentPosition = fileStream.tell(); // save filestream position
 
@@ -222,12 +222,12 @@ void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, CInput
 	// writeToOutputFile
 	std::ofstream out(extractedFilePath.string(), std::ofstream::binary);
 	out.exceptions(std::ifstream::failbit | std::ifstream::badbit);
-	out.write((char*)data.data(), entry.fullSize);
+	out.write(reinterpret_cast<char *>(data.data()), entry.fullSize);
 
 	fileStream.seek(currentPosition); // restore filestream position
 }
 
-void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, const std::string & mountPoint, ArchiveEntry entry)
+void CArchiveLoader::extractToFolder(const std::string & outputSubFolder, const std::string & mountPoint, ArchiveEntry entry) const
 {
 	std::unique_ptr<CInputStream> inputStream = load(ResourceID(mountPoint + entry.name));
 

+ 2 - 2
lib/filesystem/CArchiveLoader.h

@@ -68,9 +68,9 @@ public:
 	void updateFilteredFiles(std::function<bool(const std::string &)> filter) const override {}
 	std::unordered_set<ResourceID> getFilteredFiles(std::function<bool(const ResourceID &)> filter) const override;
 	/** Extracts one archive entry to the specified subfolder. Used for Video and Sound */
-	void extractToFolder(const std::string & outputSubFolder, CInputStream & fileStream, ArchiveEntry entry);
+	void extractToFolder(const std::string & outputSubFolder, CInputStream & fileStream, const ArchiveEntry & entry) const;
 	/** Extracts one archive entry to the specified subfolder. Used for Images, Sprites, etc */
-	void extractToFolder(const std::string & outputSubFolder, const std::string & mountPoint, ArchiveEntry entry);
+	void extractToFolder(const std::string & outputSubFolder, const std::string & mountPoint, ArchiveEntry entry) const;
 
 private:
 	/**

+ 1 - 1
lib/filesystem/CBinaryReader.cpp

@@ -54,7 +54,7 @@ si64 CBinaryReader::read(ui8 * data, si64 size)
 	si64 bytesRead = stream->read(data, size);
 	if(bytesRead != size)
 	{
-		throw std::runtime_error(getEndOfStreamExceptionMsg((long)size));
+		throw std::runtime_error(getEndOfStreamExceptionMsg(static_cast<long>(size)));
 	}
 	return bytesRead;
 }

+ 5 - 5
lib/filesystem/CCompressedStream.cpp

@@ -26,7 +26,7 @@ si64 CBufferedStream::read(ui8 * data, si64 size)
 {
 	ensureSize(position + size);
 
-	auto start = buffer.data() + position;
+	auto * start = buffer.data() + position;
 	si64 toRead = std::min<si64>(size, buffer.size() - position);
 
 	std::copy(start, start + toRead, data);
@@ -62,7 +62,7 @@ si64 CBufferedStream::getSize()
 
 void CBufferedStream::ensureSize(si64 size)
 {
-	while ((si64)buffer.size() < size && !endOfFileReached)
+	while(static_cast<si64>(buffer.size()) < size && !endOfFileReached)
 	{
 		si64 initialSize = buffer.size();
 		si64 currentStep = std::min<si64>(size, buffer.size());
@@ -127,7 +127,7 @@ si64 CCompressedStream::readMore(ui8 *data, si64 size)
 
 	int decompressed = inflateState->total_out;
 
-	inflateState->avail_out = (uInt)size;
+	inflateState->avail_out = static_cast<uInt>(size);
 	inflateState->next_out = data;
 
 	do
@@ -140,7 +140,7 @@ si64 CCompressedStream::readMore(ui8 *data, si64 size)
 			if (availSize != compressedBuffer.size())
 				gzipStream.reset();
 
-			inflateState->avail_in = (uInt)availSize;
+			inflateState->avail_in = static_cast<uInt>(availSize);
 			inflateState->next_in  = compressedBuffer.data();
 		}
 
@@ -162,7 +162,7 @@ si64 CCompressedStream::readMore(ui8 *data, si64 size)
 			break;
 		default:
 			if (inflateState->msg == nullptr)
-				throw std::runtime_error("Decompression error. Return code was " + boost::lexical_cast<std::string>(ret));
+				throw std::runtime_error("Decompression error. Return code was " + std::to_string(ret));
 			else
 				throw std::runtime_error(std::string("Decompression error: ") + inflateState->msg);
 		}

+ 0 - 5
lib/filesystem/CInputStream.h

@@ -19,11 +19,6 @@ VCMI_LIB_NAMESPACE_BEGIN
 class DLL_LINKAGE CInputStream : public virtual CStream
 {
 public:
-	/**
-	 * D-tor.
-	 */
-	virtual ~CInputStream() {}
-
 	/**
 	 * Reads n bytes from the stream into the data buffer.
 	 *

+ 1 - 1
lib/filesystem/CMemoryBuffer.h

@@ -20,7 +20,7 @@ VCMI_LIB_NAMESPACE_BEGIN
 class DLL_LINKAGE CMemoryBuffer : public CInputOutputStream
 {
 public:
-	typedef std::vector<ui8> TBuffer;
+	using TBuffer = std::vector<ui8>;
 
 	/**
 	 * C-tor.

+ 0 - 5
lib/filesystem/COutputStream.h

@@ -19,11 +19,6 @@ VCMI_LIB_NAMESPACE_BEGIN
 class DLL_LINKAGE COutputStream : public virtual CStream
 {
 public:
-	/**
-	 * D-tor.
-	 */
-	virtual ~COutputStream() {}
-
 	/**
 	 * Write n bytes from the stream into the data buffer.
 	 *

+ 1 - 1
lib/filesystem/CStream.h

@@ -17,7 +17,7 @@ public:
 	/**
 	 * D-tor.
 	 */
-	virtual ~CStream() {}
+	virtual ~CStream() = default;
 
 	/**
 	 * Seeks to the specified position.

+ 17 - 17
lib/filesystem/CZipLoader.cpp

@@ -15,7 +15,7 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-CZipStream::CZipStream(std::shared_ptr<CIOApi> api, const boost::filesystem::path & archive, unz64_file_pos filepos)
+CZipStream::CZipStream(const std::shared_ptr<CIOApi> & api, const boost::filesystem::path & archive, unz64_file_pos filepos)
 {
 	zlib_filefunc64_def zlibApi;
 
@@ -34,7 +34,7 @@ CZipStream::~CZipStream()
 
 si64 CZipStream::readMore(ui8 * data, si64 size)
 {
-	return unzReadCurrentFile(file, data, (unsigned int)size);
+	return unzReadCurrentFile(file, data, static_cast<unsigned int>(size));
 }
 
 si64 CZipStream::getSize()
@@ -53,11 +53,11 @@ ui32 CZipStream::calculateCRC32()
 
 ///CZipLoader
 CZipLoader::CZipLoader(const std::string & mountPoint, const boost::filesystem::path & archive, std::shared_ptr<CIOApi> api):
-	ioApi(api),
-    zlibApi(ioApi->getApiStructure()),
-    archiveName(archive),
-    mountPoint(mountPoint),
-    files(listFiles(mountPoint, archive))
+	ioApi(std::move(api)),
+	zlibApi(ioApi->getApiStructure()),
+	archiveName(archive),
+	mountPoint(mountPoint),
+	files(listFiles(mountPoint, archive))
 {
 	logGlobal->trace("Zip archive loaded, %d files found", files.size());
 }
@@ -82,7 +82,7 @@ std::unordered_map<ResourceID, unz64_file_pos> CZipLoader::listFiles(const std::
 
 			filename.resize(info.size_filename);
 			// Get name of current file. Contrary to docs "info" parameter can't be null
-			unzGetCurrentFileInfo64 (file, &info, filename.data(), (uLong)filename.size(), nullptr, 0, nullptr, 0);
+			unzGetCurrentFileInfo64(file, &info, filename.data(), static_cast<uLong>(filename.size()), nullptr, 0, nullptr, 0);
 
 			std::string filenameString(filename.data(), filename.size());
 			unzGetFilePos64(file, &ret[ResourceID(mountPoint + filenameString)]);
@@ -113,7 +113,7 @@ std::unordered_set<ResourceID> CZipLoader::getFilteredFiles(std::function<bool(c
 {
 	std::unordered_set<ResourceID> foundID;
 
-	for (auto & file : files)
+	for(const auto & file : files)
 	{
 		if (filter(file.first))
 			foundID.insert(file.first);
@@ -124,13 +124,13 @@ std::unordered_set<ResourceID> CZipLoader::getFilteredFiles(std::function<bool(c
 /// extracts currently selected file from zip into stream "where"
 static bool extractCurrent(unzFile file, std::ostream & where)
 {
-	std::array<char, 8 * 1024> buffer;
+	std::array<char, 8 * 1024> buffer{};
 
 	unzOpenCurrentFile(file);
 
-	while (1)
+	while(true)
 	{
-		int readSize = unzReadCurrentFile(file, buffer.data(), (unsigned int)buffer.size());
+		int readSize = unzReadCurrentFile(file, buffer.data(), static_cast<unsigned int>(buffer.size()));
 
 		if (readSize < 0) // error
 			break;
@@ -151,7 +151,7 @@ static bool extractCurrent(unzFile file, std::ostream & where)
 	return false;
 }
 
-std::vector<std::string> ZipArchive::listFiles(boost::filesystem::path filename)
+std::vector<std::string> ZipArchive::listFiles(const boost::filesystem::path & filename)
 {
 	std::vector<std::string> ret;
 
@@ -168,9 +168,9 @@ std::vector<std::string> ZipArchive::listFiles(boost::filesystem::path filename)
 
 			zipFilename.resize(info.size_filename);
 			// Get name of current file. Contrary to docs "info" parameter can't be null
-			unzGetCurrentFileInfo64 (file, &info, zipFilename.data(), (uLong)zipFilename.size(), nullptr, 0, nullptr, 0);
+			unzGetCurrentFileInfo64(file, &info, zipFilename.data(), static_cast<uLong>(zipFilename.size()), nullptr, 0, nullptr, 0);
 
-			ret.push_back(std::string(zipFilename.data(), zipFilename.size()));
+			ret.emplace_back(zipFilename.data(), zipFilename.size());
 		}
 		while (unzGoToNextFile(file) == UNZ_OK);
 	}
@@ -179,14 +179,14 @@ std::vector<std::string> ZipArchive::listFiles(boost::filesystem::path filename)
 	return ret;
 }
 
-bool ZipArchive::extract(boost::filesystem::path from, boost::filesystem::path where)
+bool ZipArchive::extract(const boost::filesystem::path & from, const boost::filesystem::path & where)
 {
 	// Note: may not be fast enough for large archives (should NOT happen with mods)
 	// because locating each file by name may be slow. Unlikely slower than decompression though
 	return extract(from, where, listFiles(from));
 }
 
-bool ZipArchive::extract(boost::filesystem::path from, boost::filesystem::path where, std::vector<std::string> what)
+bool ZipArchive::extract(const boost::filesystem::path & from, const boost::filesystem::path & where, const std::vector<std::string> & what)
 {
 	unzFile archive = unzOpen2_64(from.c_str(), FileStream::GetMinizipFilefunc());
 

+ 4 - 4
lib/filesystem/CZipLoader.h

@@ -29,7 +29,7 @@ public:
 	 * @param archive path to archive to open
 	 * @param filepos position of file to open
 	 */
-	CZipStream(std::shared_ptr<CIOApi> api, const boost::filesystem::path & archive, unz64_file_pos filepos);
+	CZipStream(const std::shared_ptr<CIOApi> & api, const boost::filesystem::path & archive, unz64_file_pos filepos);
 	~CZipStream();
 
 	si64 getSize() override;
@@ -64,13 +64,13 @@ public:
 namespace ZipArchive
 {
 	/// List all files present in archive
-	std::vector<std::string> DLL_LINKAGE listFiles(boost::filesystem::path filename);
+	std::vector<std::string> DLL_LINKAGE listFiles(const boost::filesystem::path & filename);
 
 	/// extracts all files from archive "from" into destination directory "where". Directory must exist
-	bool DLL_LINKAGE extract(boost::filesystem::path from, boost::filesystem::path where);
+	bool DLL_LINKAGE extract(const boost::filesystem::path & from, const boost::filesystem::path & where);
 
 	///same as above, but extracts only files mentioned in "what" list
-	bool DLL_LINKAGE extract(boost::filesystem::path from, boost::filesystem::path where, std::vector<std::string> what);
+	bool DLL_LINKAGE extract(const boost::filesystem::path & from, const boost::filesystem::path & where, const std::vector<std::string> & what);
 }
 
 VCMI_LIB_NAMESPACE_END

+ 3 - 4
lib/filesystem/CZipSaver.cpp

@@ -72,7 +72,7 @@ CZipOutputStream::~CZipOutputStream()
 
 si64 CZipOutputStream::write(const ui8 * data, si64 size)
 {
-	int ret = zipWriteInFileInZip(handle, (const void*)data, (unsigned)size);
+	int ret = zipWriteInFileInZip(handle, data, static_cast<unsigned>(size));
 
 	if (ret == ZIP_OK)
 		return size;
@@ -82,12 +82,11 @@ si64 CZipOutputStream::write(const ui8 * data, si64 size)
 
 ///CZipSaver
 CZipSaver::CZipSaver(std::shared_ptr<CIOApi> api, const boost::filesystem::path & path):
-	ioApi(api),
+	ioApi(std::move(api)),
 	zipApi(ioApi->getApiStructure()),
-	handle(nullptr),
+	handle(zipOpen2_64(path.c_str(), APPEND_STATUS_CREATE, nullptr, &zipApi)),
 	activeStream(nullptr)
 {
-	handle = zipOpen2_64((const void *) & path, APPEND_STATUS_CREATE, nullptr, &zipApi);
 
 	if (handle == nullptr)
 		throw std::runtime_error("CZipSaver: Failed to create archive");

+ 1 - 1
lib/filesystem/FileStream.cpp

@@ -166,7 +166,7 @@ std::streamoff FileBuf::seek(std::streamoff off, std::ios_base::seekdir way)
 			throw std::ios_base::failure("bad seek direction");
 		}
 	}();
-	if(std::fseek(GETFILE, (long)off, src))
+	if(std::fseek(GETFILE, static_cast<long>(off), src))
 		throw std::ios_base::failure("bad seek offset");
 
 	return static_cast<std::streamsize>(std::ftell(GETFILE));

+ 4 - 4
lib/filesystem/FileStream.h

@@ -17,11 +17,11 @@ VCMI_LIB_NAMESPACE_BEGIN
 class DLL_LINKAGE FileBuf
 {
 public:
-	typedef char char_type;
-	typedef struct category_ :
+	using char_type = char;
+	using category = struct category_ :
 		boost::iostreams::seekable_device_tag,
 		boost::iostreams::closable_tag
-		{} category;
+		{};
 
 	FileBuf(const boost::filesystem::path& filename, std::ios_base::openmode mode);
 
@@ -37,7 +37,7 @@ private:
 VCMI_LIB_NAMESPACE_END
 
 struct zlib_filefunc64_def_s;
-typedef zlib_filefunc64_def_s zlib_filefunc64_def;
+using zlib_filefunc64_def = zlib_filefunc64_def_s;
 
 #ifdef VCMI_DLL
 #ifdef _MSC_VER

+ 14 - 14
lib/filesystem/Filesystem.cpp

@@ -29,7 +29,7 @@ CResourceHandler CResourceHandler::globalResourceHandler;
 
 CFilesystemGenerator::CFilesystemGenerator(std::string prefix, bool extractArchives):
 	filesystem(new CFilesystemList()),
-	prefix(prefix),
+	prefix(std::move(prefix)),
 	extractArchives(extractArchives)
 {
 }
@@ -48,9 +48,9 @@ CFilesystemGenerator::TLoadFunctorMap CFilesystemGenerator::genFunctorMap()
 
 void CFilesystemGenerator::loadConfig(const JsonNode & config)
 {
-	for(auto & mountPoint : config.Struct())
+	for(const auto & mountPoint : config.Struct())
 	{
-		for(auto & entry : mountPoint.second.Vector())
+		for(const auto & entry : mountPoint.second.Vector())
 		{
 			CStopWatch timer;
 			logGlobal->trace("\t\tLoading resource at %s%s", prefix, entry["path"].String());
@@ -82,7 +82,7 @@ void CFilesystemGenerator::loadDirectory(const std::string &mountPoint, const Js
 	std::string URI = prefix + config["path"].String();
 	int depth = 16;
 	if (!config["depth"].isNull())
-		depth = (int)config["depth"].Float();
+		depth = static_cast<int>(config["depth"].Float());
 
 	ResourceID resID(URI, EResType::DIRECTORY);
 
@@ -117,7 +117,7 @@ void CFilesystemGenerator::loadJsonMap(const std::string &mountPoint, const Json
 	if (filename)
 	{
 		auto configData = CResourceHandler::get("initial")->load(ResourceID(URI, EResType::TEXT))->readAll();
-		const JsonNode configInitial((char*)configData.first.get(), configData.second);
+		const JsonNode configInitial(reinterpret_cast<char *>(configData.first.get()), configData.second);
 		filesystem->addLoader(new CMappedFileLoader(mountPoint, configInitial), false);
 	}
 }
@@ -126,10 +126,10 @@ ISimpleResourceLoader * CResourceHandler::createInitial()
 {
 	//temporary filesystem that will be used to initialize main one.
 	//used to solve several case-sensivity issues like Mp3 vs MP3
-	auto initialLoader = new CFilesystemList();
+	auto * initialLoader = new CFilesystemList();
 
 	//recurse only into specific directories
-	auto recurseInDir = [&](std::string URI, int depth)
+	auto recurseInDir = [&](const std::string & URI, int depth)
 	{
 		ResourceID ID(URI, EResType::DIRECTORY);
 
@@ -138,7 +138,7 @@ ISimpleResourceLoader * CResourceHandler::createInitial()
 			auto filename = loader->getResourceName(ID);
 			if (filename)
 			{
-				auto dir = new CFilesystemLoader(URI + '/', *filename, depth, true);
+				auto * dir = new CFilesystemLoader(URI + '/', *filename, depth, true);
 				initialLoader->addLoader(dir, false);
 			}
 		}
@@ -183,7 +183,7 @@ void CResourceHandler::initialize()
 	knownLoaders["saves"] = new CFilesystemLoader("SAVES/", VCMIDirs::get().userSavePath());
 	knownLoaders["config"] = new CFilesystemLoader("CONFIG/", VCMIDirs::get().userConfigPath());
 
-	auto localFS = new CFilesystemList();
+	auto * localFS = new CFilesystemList();
 	localFS->addLoader(knownLoaders["saves"], true);
 	localFS->addLoader(knownLoaders["config"], true);
 
@@ -197,7 +197,7 @@ ISimpleResourceLoader * CResourceHandler::get()
 	return get("root");
 }
 
-ISimpleResourceLoader * CResourceHandler::get(std::string identifier)
+ISimpleResourceLoader * CResourceHandler::get(const std::string & identifier)
 {
 	return knownLoaders.at(identifier);
 }
@@ -206,7 +206,7 @@ void CResourceHandler::load(const std::string &fsConfigURI, bool extractArchives
 {
 	auto fsConfigData = get("initial")->load(ResourceID(fsConfigURI, EResType::TEXT))->readAll();
 
-	const JsonNode fsConfig((char*)fsConfigData.first.get(), fsConfigData.second);
+	const JsonNode fsConfig(reinterpret_cast<char *>(fsConfigData.first.get()), fsConfigData.second);
 
 	addFilesystem("data", CModHandler::scopeBuiltin(), createFileSystem("", fsConfig["filesystem"], extractArchives));
 }
@@ -227,7 +227,7 @@ void CResourceHandler::addFilesystem(const std::string & parent, const std::stri
 		return;
 	}
 
-	auto list = dynamic_cast<CFilesystemList *>(knownLoaders.at(parent));
+	auto * list = dynamic_cast<CFilesystemList *>(knownLoaders.at(parent));
 	assert(list);
 	list->addLoader(loader, false);
 	knownLoaders[identifier] = loader;
@@ -240,8 +240,8 @@ bool CResourceHandler::removeFilesystem(const std::string & parent, const std::s
 	
 	if(knownLoaders.count(parent) == 0)
 		return false;
-	
-	auto list = dynamic_cast<CFilesystemList *>(knownLoaders.at(parent));
+
+	auto * list = dynamic_cast<CFilesystemList *>(knownLoaders.at(parent));
 	assert(list);
 	list->removeLoader(knownLoaders[identifier]);
 	knownLoaders.erase(identifier);

+ 1 - 1
lib/filesystem/Filesystem.h

@@ -72,7 +72,7 @@ public:
 	 * @return Returns an instance of resource loader.
 	 */
 	static ISimpleResourceLoader * get();
-	static ISimpleResourceLoader * get(std::string identifier);
+	static ISimpleResourceLoader * get(const std::string & identifier);
 
 	/**
 	 * Creates instance of initial resource loader.

+ 43 - 52
lib/filesystem/MinizipExtensions.cpp

@@ -15,63 +15,68 @@
 
 VCMI_LIB_NAMESPACE_BEGIN
 
-template <class _Stream> inline uLong streamRead(voidpf opaque, voidpf stream, void * buf, uLong size)
+template<class Stream>
+inline uLong streamRead(voidpf opaque, voidpf stream, void * buf, uLong size)
 {
 	assert(opaque != nullptr);
 	assert(stream != nullptr);
 
-	_Stream * actualStream = static_cast<_Stream *>(stream);
+	auto * actualStream = static_cast<Stream *>(stream);
 
-	return (uLong)actualStream->read((ui8 *)buf, (uLong)size);
+	return static_cast<uLong>(actualStream->read(static_cast<ui8 *>(buf), size));
 }
 
-template <class _Stream> inline ZPOS64_T streamTell(voidpf opaque, voidpf stream)
+template<class Stream>
+inline ZPOS64_T streamTell(voidpf opaque, voidpf stream)
 {
 	assert(opaque != nullptr);
 	assert(stream != nullptr);
 
-	_Stream * actualStream = static_cast<_Stream *>(stream);
-    return actualStream->tell();
+	auto * actualStream = static_cast<Stream *>(stream);
+	return actualStream->tell();
 }
 
-template <class _Stream> inline long streamSeek(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
+template<class Stream>
+inline long streamSeek(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
 {
 	assert(opaque != nullptr);
 	assert(stream != nullptr);
 
-	_Stream * actualStream = static_cast<_Stream *>(stream);
+	auto * actualStream = static_cast<Stream *>(stream);
 
-    long ret = 0;
-    switch (origin)
-    {
-    case ZLIB_FILEFUNC_SEEK_CUR :
-        if(actualStream->skip(offset) != offset)
-			ret = -1;
-        break;
-    case ZLIB_FILEFUNC_SEEK_END:
-    	{
-    		const si64 pos = actualStream->getSize() - offset;
-    		if(actualStream->seek(pos) != pos)
+	long ret = 0;
+	switch(origin)
+	{
+		case ZLIB_FILEFUNC_SEEK_CUR:
+			if(actualStream->skip(offset) != offset)
+				ret = -1;
+			break;
+		case ZLIB_FILEFUNC_SEEK_END:
+		{
+			const si64 pos = actualStream->getSize() - offset;
+			if(actualStream->seek(pos) != pos)
+				ret = -1;
+		}
+		break;
+		case ZLIB_FILEFUNC_SEEK_SET:
+			if(actualStream->seek(offset) != offset)
 				ret = -1;
-    	}
-        break;
-    case ZLIB_FILEFUNC_SEEK_SET :
-		if(actualStream->seek(offset) != offset)
+			break;
+		default:
 			ret = -1;
-        break;
-    default: ret = -1;
-    }
-    if(ret == -1)
+	}
+	if(ret == -1)
 		logGlobal->error("Stream seek failed");
-    return ret;
+	return ret;
 }
 
-template <class _Stream> inline int streamProxyClose(voidpf opaque, voidpf stream)
+template<class Stream>
+inline int streamProxyClose(voidpf opaque, voidpf stream)
 {
 	assert(opaque != nullptr);
 	assert(stream != nullptr);
 
-	_Stream * actualStream = static_cast<_Stream *>(stream);
+	auto * actualStream = static_cast<Stream *>(stream);
 
 	logGlobal->trace("Proxy stream closed");
 
@@ -81,15 +86,6 @@ template <class _Stream> inline int streamProxyClose(voidpf opaque, voidpf strea
 }
 
 ///CDefaultIOApi
-CDefaultIOApi::CDefaultIOApi()
-{
-
-}
-
-CDefaultIOApi::~CDefaultIOApi()
-{
-
-}
 
 zlib_filefunc64_def CDefaultIOApi::getApiStructure()
 {
@@ -102,11 +98,8 @@ CProxyIOApi::CProxyIOApi(CInputOutputStream * buffer):
 {
 
 }
-
-CProxyIOApi::~CProxyIOApi()
-{
-
-}
+//must be instantiated in .cpp file for access to complete types of all member fields
+CProxyIOApi::~CProxyIOApi() = default;
 
 zlib_filefunc64_def CProxyIOApi::getApiStructure()
 {
@@ -132,7 +125,7 @@ voidpf ZCALLBACK CProxyIOApi::openFileProxy(voidpf opaque, const void * filename
 	if(filename != nullptr)
 		path =  static_cast<const boost::filesystem::path::value_type *>(filename);
 
-	return ((CProxyIOApi *)opaque)->openFile(path, mode);
+	return (static_cast<CProxyIOApi *>(opaque))->openFile(path, mode);
 }
 
 uLong ZCALLBACK CProxyIOApi::readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)
@@ -145,8 +138,8 @@ uLong ZCALLBACK CProxyIOApi::writeFileProxy(voidpf opaque, voidpf stream, const
 	assert(opaque != nullptr);
 	assert(stream != nullptr);
 
-	CInputOutputStream * actualStream = static_cast<CInputOutputStream *>(stream);
-    return (uLong)actualStream->write((const ui8 *)buf, size);
+	auto * actualStream = static_cast<CInputOutputStream *>(stream);
+	return static_cast<uLong>(actualStream->write(static_cast<const ui8 *>(buf), size));
 }
 
 ZPOS64_T ZCALLBACK CProxyIOApi::tellFileProxy(voidpf opaque, voidpf stream)
@@ -184,10 +177,8 @@ CProxyROIOApi::CProxyROIOApi(CInputStream * buffer):
 
 }
 
-CProxyROIOApi::~CProxyROIOApi()
-{
-
-}
+//must be instantiated in .cpp file for access to complete types of all member fields
+CProxyROIOApi::~CProxyROIOApi() = default;
 
 zlib_filefunc64_def CProxyROIOApi::getApiStructure()
 {
@@ -221,7 +212,7 @@ voidpf ZCALLBACK CProxyROIOApi::openFileProxy(voidpf opaque, const void* filenam
 	if(filename != nullptr)
 		path =  static_cast<const boost::filesystem::path::value_type *>(filename);
 
-	return ((CProxyROIOApi *)opaque)->openFile(path, mode);
+	return (static_cast<CProxyROIOApi *>(opaque))->openFile(path, mode);
 }
 
 uLong ZCALLBACK CProxyROIOApi::readFileProxy(voidpf opaque, voidpf stream, void * buf, uLong size)

+ 3 - 6
lib/filesystem/MinizipExtensions.h

@@ -28,7 +28,7 @@ class CMemoryBuffer;
 class DLL_LINKAGE CIOApi
 {
 public:
-	virtual ~CIOApi(){};
+	virtual ~CIOApi() = default;
 
 	virtual zlib_filefunc64_def getApiStructure() = 0;
 };
@@ -38,9 +38,6 @@ public:
 class DLL_LINKAGE CDefaultIOApi: public CIOApi
 {
 public:
-	CDefaultIOApi();
-	~CDefaultIOApi();
-
 	zlib_filefunc64_def getApiStructure() override;
 };
 
@@ -49,7 +46,7 @@ class DLL_LINKAGE CProxyIOApi: public CIOApi
 {
 public:
 	CProxyIOApi(CInputOutputStream * buffer);
-	~CProxyIOApi();
+	~CProxyIOApi() override;
 
 	zlib_filefunc64_def getApiStructure() override;
 private:
@@ -71,7 +68,7 @@ class DLL_LINKAGE CProxyROIOApi: public CIOApi
 {
 public:
 	CProxyROIOApi(CInputStream * buffer);
-	~CProxyROIOApi();
+	~CProxyROIOApi() override;
 
 	zlib_filefunc64_def getApiStructure() override;
 private:

+ 2 - 1
lib/logging/CBasicLogConfigurator.cpp

@@ -37,7 +37,7 @@ void CBasicLogConfigurator::configure()
 		const JsonNode & loggers = loggingNode["loggers"];
 		if(!loggers.isNull())
 		{
-			for(auto & loggerNode : loggers.Vector())
+			for(const auto & loggerNode : loggers.Vector())
 			{
 				// Get logger
 				std::string name = loggerNode["domain"].String();
@@ -148,6 +148,7 @@ void CBasicLogConfigurator::deconfigure()
 	auto l = CLogger::getGlobalLogger();
 	if(l != nullptr)
 		l->clearTargets();
+	appendToLogFile = true;
 }
 
 VCMI_LIB_NAMESPACE_END

+ 1 - 0
lib/logging/CBasicLogConfigurator.h

@@ -35,6 +35,7 @@ public:
 	/// Removes all targets from the global logger.
 	void deconfigure();
 
+
 private:
 	// Gets ELogLevel enum from string. (Should be moved to CLogger as a separate function?)
 	// Throws: std::runtime_error

+ 8 - 21
lib/logging/CLogger.cpp

@@ -75,7 +75,7 @@ CLoggerDomain CLoggerDomain::getParent() const
 	if(isGlobalDomain())
 		return *this;
 
-	const size_t pos = name.find_last_of(".");
+	const size_t pos = name.find_last_of('.');
 	if(pos != std::string::npos)
 		return CLoggerDomain(name.substr(0, pos));
 	return CLoggerDomain(DOMAIN_GLOBAL);
@@ -189,7 +189,7 @@ void CLogger::callTargets(const LogRecord & record) const
 {
 	TLockGuard _(mx);
 	for(const CLogger * logger = this; logger != nullptr; logger = logger->parent)
-		for(auto & target : logger->targets)
+		for(const auto & target : logger->targets)
 			target->write(record);
 }
 
@@ -235,7 +235,8 @@ CLogger * CLogManager::getLogger(const CLoggerDomain & domain)
 std::vector<std::string> CLogManager::getRegisteredDomains() const
 {
 	std::vector<std::string> domains;
-	for (auto& pair : loggers)
+	domains.reserve(loggers.size());
+	for(const auto & pair : loggers)
 	{
 		domains.push_back(pair.second->getDomain().getName());
 	}
@@ -247,25 +248,11 @@ CLogFormatter::CLogFormatter()
 {
 }
 
-CLogFormatter::CLogFormatter(const std::string & pattern)
-	: pattern(pattern)
+CLogFormatter::CLogFormatter(std::string pattern):
+	pattern(std::move(pattern))
 {
 }
 
-CLogFormatter::CLogFormatter(const CLogFormatter & c) : pattern(c.pattern) { }
-CLogFormatter::CLogFormatter(CLogFormatter && m) : pattern(std::move(m.pattern)) { }
-
-CLogFormatter & CLogFormatter::operator=(const CLogFormatter & c)
-{
-	pattern = c.pattern;
-	return *this;
-}
-CLogFormatter & CLogFormatter::operator=(CLogFormatter && m)
-{
-	pattern = std::move(m.pattern);
-	return *this;
-}
-
 std::string CLogFormatter::format(const LogRecord & record) const
 {
 	std::string message = pattern;
@@ -437,8 +424,8 @@ void CLogConsoleTarget::setFormatter(const CLogFormatter & formatter) { this->fo
 const CColorMapping & CLogConsoleTarget::getColorMapping() const { return colorMapping; }
 void CLogConsoleTarget::setColorMapping(const CColorMapping & colorMapping) { this->colorMapping = colorMapping; }
 
-CLogFileTarget::CLogFileTarget(boost::filesystem::path filePath, bool append)
-	: file(std::move(filePath), append ? std::ios_base::app : std::ios_base::out)
+CLogFileTarget::CLogFileTarget(const boost::filesystem::path & filePath, bool append):
+	file(filePath, append ? std::ios_base::app : std::ios_base::out)
 {
 //	formatter.setPattern("%d %l %n [%t] - %m");
 	formatter.setPattern("%l %n [%t] - %m");

+ 2 - 7
lib/logging/CLogger.h

@@ -134,13 +134,8 @@ class DLL_LINKAGE CLogFormatter
 {
 public:
 	CLogFormatter();
-	CLogFormatter(const CLogFormatter & copy);
-	CLogFormatter(CLogFormatter && move);
 
-	CLogFormatter(const std::string & pattern);
-
-	CLogFormatter & operator=(const CLogFormatter & copy);
-	CLogFormatter & operator=(CLogFormatter && move);
+	CLogFormatter(std::string pattern);
 
 	void setPattern(const std::string & pattern);
 	void setPattern(std::string && pattern);
@@ -216,7 +211,7 @@ class DLL_LINKAGE CLogFileTarget : public ILogTarget
 public:
 	/// Constructs a CLogFileTarget and opens the file designated by filePath. If the append parameter is true, the file
 	/// will be appended to. Otherwise the file designated by filePath will be truncated before being opened.
-	explicit CLogFileTarget(boost::filesystem::path filePath, bool append = true);
+	explicit CLogFileTarget(const boost::filesystem::path & filePath, bool append = true);
 	~CLogFileTarget();
 
 	const CLogFormatter & getFormatter() const;