#pragma once #include "FractoriumPch.h" /// /// EmberFile class. /// /// /// Class for representing an ember Xml file in memory. /// It contains a filename and a vector of embers. /// It also provides static helper functions for creating /// default names for the file and the embers in it. /// template class EmberFile { public: /// /// Empty constructor that does nothing. /// EmberFile() { } /// /// Default copy constructor. /// /// The EmberFile object to copy EmberFile(const EmberFile& emberFile) { EmberFile::operator=(emberFile); } /// /// Copy constructor to copy an EmberFile object of type U. /// /// The EmberFile object to copy template EmberFile(const EmberFile& emberFile) { EmberFile::operator=(emberFile); } /// /// Default assignment operator. /// /// The EmberFile object to copy EmberFile& operator = (const EmberFile& emberFile) { if (this != &emberFile) EmberFile::operator=(emberFile); return *this; } /// /// Assignment operator to assign a EmberFile object of type U. /// /// The EmberFile object to copy. /// Reference to updated self template EmberFile& operator = (const EmberFile& emberFile) { m_Filename = emberFile.m_Filename; CopyVec(m_Embers, emberFile.m_Embers); return *this; } /// /// Clear the file name and the vector of embers. /// void Clear() { m_Filename.clear(); m_Embers.clear(); } /// /// Ensure all ember names are unique. /// void MakeNamesUnique() { int x = 0; for (size_t i = 0; i < m_Embers.size(); i++) { for (size_t j = 0; j < m_Embers.size(); j++) { if (i != j && m_Embers[i].m_Name == m_Embers[j].m_Name) { m_Embers[j].m_Name = m_Embers[j].m_Name + "_" + QString::number(++x).toStdString(); j = 0; } } } } /// /// Return the default filename based on the current date/time. /// /// The default filename static QString DefaultFilename() { return "Flame_" + QDateTime(QDateTime::currentDateTime()).toString("yyyy-MM-dd-hhmmss"); } /// /// Ensures a given input filename is unique by appending a count to the end. /// /// The passed in name if it was unique, else a uniquely made name. static QString UniqueFilename(QString& filename) { if (!QFile::exists(filename)) return filename; int counter = 2; QString newPath; QFileInfo original(filename); QString path = original.absolutePath() + QDir::separator(); QString base = original.completeBaseName(); QString extension = original.suffix(); do { newPath = path + base + "_" + QString::number(counter++) + "." + extension; } while (QFile::exists(newPath)); return newPath; } /// /// Return the default ember name based on the current date/time and /// the ember's index in the file. /// /// The index in the file of the ember /// The default ember name static QString DefaultEmberName(unsigned int i) { return DefaultFilename() + "-" + QString::number(i); } QString m_Filename; vector> m_Embers; };