diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..690a1e6 --- /dev/null +++ b/.clang-format @@ -0,0 +1,3 @@ +Language: Cpp +BasedOnStyle: LLVM + diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..e469776 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,39 @@ +Checks: "*, + -abseil-*, + -altera-*, + -android-*, + -fuchsia-*, + -google-*, + -llvm*, + -modernize-use-trailing-return-type, + -zircon-*, + -readability-else-after-return, + -readability-static-accessed-through-instance, + -readability-avoid-const-params-in-decls, + -cppcoreguidelines-non-private-member-variables-in-classes, + -misc-non-private-member-variables-in-classes, +" +WarningsAsErrors: '' +HeaderFilterRegex: '' +FormatStyle: none +CheckOptions: + - { key: readability-identifier-naming.NamespaceCase, value: lower_case } + - { key: readability-identifier-naming.ClassCase, value: CamelCase } + - { key: readability-identifier-naming.StructCase, value: CamelCase } + - { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase } + - { key: readability-identifier-naming.FunctionCase, value: camelBack } + - { key: readability-identifier-naming.VariableCase, value: lower_case } + - { key: readability-identifier-naming.PrivateMemberSuffix, value: _ } + - { key: readability-identifier-naming.ProtectedMemberSuffix, value: _ } + - { key: readability-identifier-naming.MacroDefinitionCase, value: UPPER_CASE } + - { key: readability-identifier-naming.EnumConstantCase, value: CamelCase } + - { key: readability-identifier-naming.EnumConstantPrefix, value: k } + - { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase } + - { key: readability-identifier-naming.ConstexprVariablePrefix, value: k } + - { key: readability-identifier-naming.GlobalConstantCase, value: CamelCase } + - { key: readability-identifier-naming.GlobalConstantPrefix, value: k } + - { key: readability-identifier-naming.MemberConstantCase, value: CamelCase } + - { key: readability-identifier-naming.MemberConstantPrefix, value: k } + - { key: readability-identifier-naming.StaticConstantCase, value: CamelCase } + - { key: readability-identifier-naming.StaticConstantPrefix, value: k } + diff --git a/.gitignore b/.gitignore index 378eac2..9785597 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt index c0e634b..c8b224f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.30) project(yadro-task VERSION 0.1) set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_FLAGS "-Wall") file(GLOB SOURCES "src/*.cpp") diff --git a/include/filetape.h b/include/filetape.h index 3c7bd00..5b2f916 100644 --- a/include/filetape.h +++ b/include/filetape.h @@ -7,56 +7,64 @@ #include /** -* Mock tape implementation that uses text files as data source. -* -* Simulates tape operations by artificially pausing the execution of some methods -* using time intervals, specified in command line arguments or a configuration file. -* Each cell is represented as a seperate line in a file, cell data is stored as plain text. -*/ + * Mock tape implementation that uses text files as data source. + * + * Simulates tape operations by artificially pausing the execution of some + * methods using time intervals, specified in command line arguments or a + * configuration file. Each cell is represented as a seperate line in a file, + * cell data is stored as plain text. + */ class FileTape : public Tape { private: - std::fstream file; + std::fstream file_; + public: - /** - * Initialize a new instance of FileTape that will open a file with the specified name. - * File must be read and write accessible. - * - * @param file_name Name of a file to be opened. - */ - FileTape(std::string file_name); + ~FileTape() override; + FileTape &operator=(const FileTape &) = delete; + FileTape(const FileTape &) = delete; + FileTape(FileTape &&) = delete; + FileTape &operator=(FileTape &&) = delete; - /** - * Advances the underlying fstream to a new line. - * - * @return false if EOF is reached, otherwise true. - */ - bool seekForward() override; + /** + * Initialize a new instance of FileTape that will open a file with the + * specified name. File must be read and write accessible. + * + * @param file_name Name of a file to be opened. + */ + explicit FileTape(const std::string &fileName); - /** - * Rewinds the underlying fstream to a previous line. - * - * @return false if called from the first line of a file, otherwise true. - */ - bool seekBackwards() override; + /** + * Advances the underlying fstream to a new line. + * + * @return false if EOF is reached, otherwise true. + */ + bool seekForward() override; - /** - * Reads and parses data from the current line. - * - * @return number from the line, or 0 if data can not be parsed. - */ - int32_t read() override; + /** + * Rewinds the underlying fstream to a previous line. + * + * @return false if called from the first line of a file, otherwise true. + */ + bool seekBackwards() override; - /** - * Writes data to the current line. - * - * @param data Number, that should be written to the current line. - */ - void write(int32_t data) override; + /** + * Reads and parses data from the current line. + * + * @return number from the line, or 0 if data can not be parsed. + */ + int32_t read() override; - /** - * Closes the underlying fstream - */ - ~FileTape() override; + /** + * Writes data to the current line. + * + * @param data Number, that should be written to the current line. + */ + void write(int32_t data) override; +}; + +struct FileTapeSettings { + unsigned int readDelayMs, writeDelayMs; + unsigned int seekForwardDelayMs, seekBackwardsDelayMs; }; #endif diff --git a/include/tape.h b/include/tape.h index 05aee3d..55b7133 100644 --- a/include/tape.h +++ b/include/tape.h @@ -4,47 +4,52 @@ #include /** -* Abstract class representing a magnetic tape. -* -* Tape is a storage medium consisting of N cells, where each cell contains a 32-bit signed integer. -* Data can be read or written into one cell at a time. Tape can be moved -* one cell forward or backwards in order to change the targeted cell. -* Tape performs every operation sequentially. The amount of data stored on a single tape -* could exceed the amount of available RAM. Moving tape forward or backwards -* is a very time-consuming operation. -*/ + * Abstract class representing a magnetic tape. + * + * Tape is a storage medium consisting of N cells, where each cell contains a + * 32-bit signed integer. Data can be read or written into one cell at a time. + * Tape can be moved one cell forward or backwards in order to change the + * targeted cell. Tape performs every operation sequentially. The amount of data + * stored on a single tape could exceed the amount of available RAM. Moving tape + * forward or backwards is a very time-consuming operation. + */ class Tape { public: - /** - * Advances the tape one cell forward. - * - * @return false if the next cell doesn't exist (reached end of tape), otherwise true. - */ - virtual bool seekForward() = 0; + Tape(const Tape &) = default; + Tape(Tape &&) = default; + Tape &operator=(const Tape &) = default; + Tape &operator=(Tape &&) = default; + virtual ~Tape() = default; - /** - * Rewinds the tape one cell backwards. - * - * @return false if the previous cell doesn't exist (reached beginning of tape), otherwise true. - */ - virtual bool seekBackwards() = 0; + /** + * Advances the tape one cell forward. + * + * @return false if the next cell doesn't exist (reached end of tape), + * otherwise true. + */ + virtual bool seekForward() = 0; - /** - * Reads data from the current cell. - * - * @return number, that is stored on the current cell. - */ - virtual int32_t read() = 0; + /** + * Rewinds the tape one cell backwards. + * + * @return false if the previous cell doesn't exist (reached beginning of + * tape), otherwise true. + */ + virtual bool seekBackwards() = 0; - /** - * Writes data to the current cell. - * - * @param data Number, that should be written to the current cell. - */ - virtual void write(int32_t data) = 0; + /** + * Reads data from the current cell. + * + * @return number, that is stored on the current cell. + */ + virtual int32_t read() = 0; - // default virtual destructor to prevent memory leaks in implementing classes - virtual ~Tape() = default; + /** + * Writes data to the current cell. + * + * @param data Number, that should be written to the current cell. + */ + virtual void write(int32_t data) = 0; }; #endif diff --git a/src/filetape.cpp b/src/filetape.cpp index de478d7..4ffc2fe 100644 --- a/src/filetape.cpp +++ b/src/filetape.cpp @@ -3,26 +3,16 @@ #include #include -FileTape::FileTape(std::string file_name) { - this->file = std::fstream(file_name); +FileTape::FileTape(const std::string &fileName) { + this->file_ = std::fstream(fileName); } -bool FileTape::seekForward() { - return true; -} +bool FileTape::seekForward() { return true; } -bool FileTape::seekBackwards() { - return true; -} +bool FileTape::seekBackwards() { return true; } -int32_t FileTape::read() { - return 0; -} +int32_t FileTape::read() { return 0; } -void FileTape::write(int32_t data) { - -} +void FileTape::write(int32_t data) {} -FileTape::~FileTape() { - this->file.close(); -} +FileTape::~FileTape() { this->file_.close(); } diff --git a/src/main.cpp b/src/main.cpp index 09d2f5d..ac10e2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,9 @@ #include "filetape.h" -#include +#include +#include -int main(int argc, char *argv[]) { - std::unique_ptr tape(new FileTape("test")); - return 0; +int main(int /*argc*/, char * /*argv*/[]) { + FileTape tape("waw"); + std::cout << "Hello, World!" << std::endl; + return 0; }