Added clang-format and clang-tidy
This commit is contained in:
parent
a80da53d0c
commit
363778019e
8 changed files with 146 additions and 99 deletions
3
.clang-format
Normal file
3
.clang-format
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
Language: Cpp
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
|
39
.clang-tidy
Normal file
39
.clang-tidy
Normal 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
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
build
|
build
|
||||||
|
.cache
|
||||||
|
|
|
@ -3,7 +3,6 @@ cmake_minimum_required(VERSION 3.30)
|
||||||
project(yadro-task VERSION 0.1)
|
project(yadro-task VERSION 0.1)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
set(CMAKE_CXX_FLAGS "-Wall")
|
|
||||||
|
|
||||||
file(GLOB SOURCES "src/*.cpp")
|
file(GLOB SOURCES "src/*.cpp")
|
||||||
|
|
||||||
|
|
|
@ -7,23 +7,31 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock tape implementation that uses text files as data source.
|
* Mock tape implementation that uses text files as data source.
|
||||||
*
|
*
|
||||||
* Simulates tape operations by artificially pausing the execution of some methods
|
* Simulates tape operations by artificially pausing the execution of some
|
||||||
* using time intervals, specified in command line arguments or a configuration file.
|
* methods using time intervals, specified in command line arguments or a
|
||||||
* Each cell is represented as a seperate line in a file, cell data is stored as plain text.
|
* configuration file. Each cell is represented as a seperate line in a file,
|
||||||
*/
|
* cell data is stored as plain text.
|
||||||
|
*/
|
||||||
class FileTape : public Tape {
|
class FileTape : public Tape {
|
||||||
private:
|
private:
|
||||||
std::fstream file;
|
std::fstream file_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~FileTape() override;
|
||||||
|
FileTape &operator=(const FileTape &) = delete;
|
||||||
|
FileTape(const FileTape &) = delete;
|
||||||
|
FileTape(FileTape &&) = delete;
|
||||||
|
FileTape &operator=(FileTape &&) = delete;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a new instance of FileTape that will open a file with the specified name.
|
* Initialize a new instance of FileTape that will open a file with the
|
||||||
* File must be read and write accessible.
|
* specified name. File must be read and write accessible.
|
||||||
*
|
*
|
||||||
* @param file_name Name of a file to be opened.
|
* @param file_name Name of a file to be opened.
|
||||||
*/
|
*/
|
||||||
FileTape(std::string file_name);
|
explicit FileTape(const std::string &fileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Advances the underlying fstream to a new line.
|
* Advances the underlying fstream to a new line.
|
||||||
|
@ -52,11 +60,11 @@ public:
|
||||||
* @param data Number, that should be written to the current line.
|
* @param data Number, that should be written to the current line.
|
||||||
*/
|
*/
|
||||||
void write(int32_t data) override;
|
void write(int32_t data) override;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
struct FileTapeSettings {
|
||||||
* Closes the underlying fstream
|
unsigned int readDelayMs, writeDelayMs;
|
||||||
*/
|
unsigned int seekForwardDelayMs, seekBackwardsDelayMs;
|
||||||
~FileTape() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,28 +4,36 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class representing a magnetic tape.
|
* Abstract class representing a magnetic tape.
|
||||||
*
|
*
|
||||||
* Tape is a storage medium consisting of N cells, where each cell contains a 32-bit signed integer.
|
* Tape is a storage medium consisting of N cells, where each cell contains a
|
||||||
* Data can be read or written into one cell at a time. Tape can be moved
|
* 32-bit signed integer. Data can be read or written into one cell at a time.
|
||||||
* one cell forward or backwards in order to change the targeted cell.
|
* Tape can be moved one cell forward or backwards in order to change the
|
||||||
* Tape performs every operation sequentially. The amount of data stored on a single tape
|
* targeted cell. Tape performs every operation sequentially. The amount of data
|
||||||
* could exceed the amount of available RAM. Moving tape forward or backwards
|
* stored on a single tape could exceed the amount of available RAM. Moving tape
|
||||||
* is a very time-consuming operation.
|
* forward or backwards is a very time-consuming operation.
|
||||||
*/
|
*/
|
||||||
class Tape {
|
class Tape {
|
||||||
public:
|
public:
|
||||||
|
Tape(const Tape &) = default;
|
||||||
|
Tape(Tape &&) = default;
|
||||||
|
Tape &operator=(const Tape &) = default;
|
||||||
|
Tape &operator=(Tape &&) = default;
|
||||||
|
virtual ~Tape() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Advances the tape one cell forward.
|
* Advances the tape one cell forward.
|
||||||
*
|
*
|
||||||
* @return false if the next cell doesn't exist (reached end of tape), otherwise true.
|
* @return false if the next cell doesn't exist (reached end of tape),
|
||||||
|
* otherwise true.
|
||||||
*/
|
*/
|
||||||
virtual bool seekForward() = 0;
|
virtual bool seekForward() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewinds the tape one cell backwards.
|
* Rewinds the tape one cell backwards.
|
||||||
*
|
*
|
||||||
* @return false if the previous cell doesn't exist (reached beginning of tape), otherwise true.
|
* @return false if the previous cell doesn't exist (reached beginning of
|
||||||
|
* tape), otherwise true.
|
||||||
*/
|
*/
|
||||||
virtual bool seekBackwards() = 0;
|
virtual bool seekBackwards() = 0;
|
||||||
|
|
||||||
|
@ -42,9 +50,6 @@ public:
|
||||||
* @param data Number, that should be written to the current cell.
|
* @param data Number, that should be written to the current cell.
|
||||||
*/
|
*/
|
||||||
virtual void write(int32_t data) = 0;
|
virtual void write(int32_t data) = 0;
|
||||||
|
|
||||||
// default virtual destructor to prevent memory leaks in implementing classes
|
|
||||||
virtual ~Tape() = default;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -3,26 +3,16 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
FileTape::FileTape(std::string file_name) {
|
FileTape::FileTape(const std::string &fileName) {
|
||||||
this->file = std::fstream(file_name);
|
this->file_ = std::fstream(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileTape::seekForward() {
|
bool FileTape::seekForward() { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool FileTape::seekBackwards() {
|
bool FileTape::seekBackwards() { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t FileTape::read() {
|
int32_t FileTape::read() { return 0; }
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FileTape::write(int32_t data) {
|
void FileTape::write(int32_t data) {}
|
||||||
|
|
||||||
}
|
FileTape::~FileTape() { this->file_.close(); }
|
||||||
|
|
||||||
FileTape::~FileTape() {
|
|
||||||
this->file.close();
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#include "filetape.h"
|
#include "filetape.h"
|
||||||
#include <memory>
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int /*argc*/, char * /*argv*/[]) {
|
||||||
std::unique_ptr<Tape> tape(new FileTape("test"));
|
FileTape tape("waw");
|
||||||
|
std::cout << "Hello, World!" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue