Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake . --no-pure-eval
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
.cache/
compile_commands.json
result
result
.pre-commit-config.yaml
.devenv
.direnv
.gdb_history
.qtcreator
31 changes: 16 additions & 15 deletions VirtualTuringMachine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
cmake_minimum_required(VERSION 3.16)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Prevent optimizations for begger debugger UX
add_compile_options(-O0)
endif()

if(NOT CMAKE_PREFIX_PATH AND DEFINED ENV{QTDIR})
list(APPEND CMAKE_PREFIX_PATH "$ENV{QTDIR}")
endif()
Expand All @@ -10,7 +15,7 @@ if(APPLE AND NOT CMAKE_PREFIX_PATH)
"/opt/homebrew/opt/qt@5"
"/usr/local/opt/qt@5")
foreach(_qt_path IN LISTS _qt5_mac_candidates)
if(EXISTS "${_qt_path}/lib/cmake/Qt5/Qt5Config.cmake")
if(EXISTS "${_qt_path}/lib/cmake/Qt6/Qt6Config.cmake")
list(APPEND CMAKE_PREFIX_PATH "${_qt_path}")
break()
endif()
Expand All @@ -22,11 +27,10 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core Gui Widgets)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)

if(APPLE)
get_target_property(_qt_core_location Qt5::Core LOCATION)
get_target_property(_qt_core_location Qt6::Core LOCATION)
if(_qt_core_location)
get_filename_component(_qt_lib_dir "${_qt_core_location}" DIRECTORY)
execute_process(
Expand Down Expand Up @@ -54,7 +58,7 @@ file(
GLOB_RECURSE VTM_SOURCES
LIST_DIRECTORIES FALSE
*.cpp)
list(FILTER VTM_SOURCES EXCLUDE REGEX "/main\\.cpp$")
list(FILTER VTM_SOURCES EXCLUDE REGEX "/(main|headless_main)\\.cpp$")

add_library(vtm_core STATIC ${VTM_SOURCES} resources.qrc)
target_include_directories(vtm_core PUBLIC ${ADDITIONAL_DIRS})
Expand All @@ -67,18 +71,12 @@ if(MSVC)
target_compile_options(vtm_core PRIVATE /utf-8)
endif()

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(${PROJECT_NAME} main.cpp MANUAL_FINALIZATION)
else()
if(ANDROID)
add_library(${PROJECT_NAME} SHARED main.cpp)
else()
add_executable(${PROJECT_NAME} main.cpp isCtrlPressed.h)
endif()
endif()

qt_add_executable(${PROJECT_NAME} main.cpp MANUAL_FINALIZATION)
target_link_libraries(${PROJECT_NAME} PRIVATE vtm_core)

add_executable(${PROJECT_NAME}-headless headless_main.cpp)
target_link_libraries(${PROJECT_NAME}-headless PRIVATE vtm_core)

if(MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE /utf-8)
endif()
Expand All @@ -96,3 +94,6 @@ endif()
if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(${PROJECT_NAME})
endif()

install(TARGETS ${PROJECT_NAME} vtm_core)
install(TARGETS ${PROJECT_NAME}-headless)
103 changes: 39 additions & 64 deletions VirtualTuringMachine/VMTAlphabit.cpp
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,94 +1,69 @@


#include "VMTAlphabit.h"

#include <QDebug>

VMTAlphabit::~VMTAlphabit(){
qDebug() << "VMTAlphabit::~VMTAlphabit";
}
VMTAlphabit::~VMTAlphabit() { qDebug() << "VMTAlphabit::~VMTAlphabit"; }

VMTAlphabit::VMTAlphabit(){
VMTAlphabit::VMTAlphabit() {}

}

bool VMTAlphabit::operator !=(const VMTAlphabit &other){
if(_signs.length()!=other._signs.length()) return false;
else
{
for(int i=0;i<_signs.length();i++){
bool found = false;
for(int j=0;(j<other._signs.length())&&(!found);j++){
if(_signs[i]==other._signs[j]) found=true;
}
if(!found) return false;
}

return true;
}
}
bool VMTAlphabit::operator!=(const VMTAlphabit& other) {
if (_signs.length() != other._signs.length())
return false;
else {
for (int i = 0; i < _signs.length(); i++) {
bool found = false;
for (int j = 0; (j < other._signs.length()) && (!found); j++) {
if (_signs[i] == other._signs[j]) found = true;
}
if (!found) return false;
}

VMTAlphabit::VMTAlphabit(const VMTAlphabit& other){
_signs = other._signs;
return true;
}
}

void VMTAlphabit::ReplaceString(const QString& other){
_signs = other;
}
VMTAlphabit::VMTAlphabit(const VMTAlphabit& other) { _signs = other._signs; }

void VMTAlphabit::AddSign(char sign){
_signs.append(QChar(sign));
}
void VMTAlphabit::ReplaceString(const QString& other) { _signs = other; }

void VMTAlphabit::AddSign(char sign) { _signs.append(QChar(sign)); }

char VMTAlphabit::GetLambda(){
if(_signs.size()>0) return _signs[0].toLatin1();
return 0;
char VMTAlphabit::GetLambda() {
if (_signs.size() > 0) return _signs[0].toLatin1();
return 0;
}


char VMTAlphabit::GetSignAt(int index){
if(index>=0){
if(index<_signs.size())
return _signs[index].toLatin1();
char VMTAlphabit::GetSignAt(int index) {
if (index >= 0) {
if (index < _signs.size()) return _signs[index].toLatin1();
}
return 0;
return 0;
}


int VMTAlphabit::GetSignsCount(){

return _signs.size();
}
int VMTAlphabit::GetSignsCount() { return _signs.size(); }

#include <set>
bool VMTAlphabit::IsEqual(const VMTAlphabit &other){

if(_signs.size() != other._signs.size()) return false;
bool VMTAlphabit::IsEqual(const VMTAlphabit& other) {
if (_signs.size() != other._signs.size()) return false;
std::set<QChar> other_set;
for(int i = 0; i < static_cast<int>(other._signs.size()); ++i) other_set.insert(other._signs[i]);
for (int i = 0; i < static_cast<int>(other._signs.size()); ++i)
other_set.insert(other._signs[i]);

for(int i = 0; i < static_cast<int>(_signs.size()); ++i)
if(other_set.find(_signs[i])==other_set.end()) return false;
for (int i = 0; i < static_cast<int>(_signs.size()); ++i)
if (other_set.find(_signs[i]) == other_set.end()) return false;

return true;
}

bool VMTAlphabit::IsLambda(char sign) { return (sign == GetLambda()); }

bool VMTAlphabit::IsLambda(char sign){

return (sign==GetLambda());
}


bool VMTAlphabit::IsSign(char sign){
for(int i = 0; i < static_cast<int>(_signs.size()); ++i){
if(_signs[i].toLatin1()==sign) return true;
bool VMTAlphabit::IsSign(char sign) {
for (int i = 0; i < static_cast<int>(_signs.size()); ++i) {
if (_signs[i].toLatin1() == sign) return true;
}
return false;
return false;
}



const QString& VMTAlphabit::ToString(){
return _signs;
}
const QString& VMTAlphabit::ToString() { return _signs; }
22 changes: 10 additions & 12 deletions VirtualTuringMachine/VMTAlphabit.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@

#include <QString>

class VMTAlphabit
{
private:
class VMTAlphabit {
private:
QString _signs;
public:
VMTAlphabit();

public:
VMTAlphabit();
VMTAlphabit(const VMTAlphabit& other);
void AddSign(char sign);


char GetLambda();
char GetSignAt(int index);
int GetSignsCount();
bool IsEqual(const VMTAlphabit &other);
bool IsLambda(char sign);
bool IsEqual(const VMTAlphabit& other);
bool IsLambda(char sign);
bool IsSign(char sign);

void ReplaceString(const QString& other);
const QString& ToString();
const QString& ToString();

bool operator !=(const VMTAlphabit &other);
bool operator!=(const VMTAlphabit& other);
virtual ~VMTAlphabit();

};
#endif // !defined(EA_F87A7617_E180_442b_A3D0_541F8C64FC9B__INCLUDED_)
#endif // !defined(EA_F87A7617_E180_442b_A3D0_541F8C64FC9B__INCLUDED_)
Loading
Loading