Added clang-format and clang-tidy

This commit is contained in:
Egor 2024-10-21 11:03:12 +03:00
parent a80da53d0c
commit 363778019e
8 changed files with 146 additions and 99 deletions

3
.clang-format Normal file
View file

@ -0,0 +1,3 @@
Language: Cpp
BasedOnStyle: LLVM

39
.clang-tidy Normal file
View file

@ -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 }

1
.gitignore vendored
View file

@ -1 +1,2 @@
build
.cache

View file

@ -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")

View file

@ -7,56 +7,64 @@
#include <string>
/**
* 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

View file

@ -4,47 +4,52 @@
#include <cstdint>
/**
* 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

View file

@ -3,26 +3,16 @@
#include <fstream>
#include <string>
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(); }

View file

@ -1,7 +1,9 @@
#include "filetape.h"
#include <memory>
#include <iostream>
#include <ostream>
int main(int argc, char *argv[]) {
std::unique_ptr<Tape> tape(new FileTape("test"));
return 0;
int main(int /*argc*/, char * /*argv*/[]) {
FileTape tape("waw");
std::cout << "Hello, World!" << std::endl;
return 0;
}