-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial. Set up Cmake for HexCalcLib. Start writing library
- Loading branch information
0 parents
commit b66e07a
Showing
8 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
build* | ||
*build | ||
cmake-build* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "lib/GSL"] | ||
path = lib/GSL | ||
url = https://github.com/Microsoft/GSL.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
project(HexCalc) | ||
|
||
#add_executable(HexCalc main.cpp) | ||
#target_link_libraries(HexCalc) | ||
|
||
add_subdirectory(lib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
project(HexCalcLib) | ||
set(GSL_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}) | ||
set(GSL_TEST_FILE ${GSL_TEST_DIR}/gsl-test.cpp) | ||
|
||
|
||
#Try find GSL project | ||
set(GSL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/GSL/include") | ||
set(INCLUDE_DIRECTORIES "${INCLUDE_DIRECTORIES} ${CMAKE_CURRENT_SOURCE_DIR}/GSL/include") | ||
file(WRITE ${GSL_TEST_FILE} | ||
"#include <gsl/gsl> | ||
#include <gsl/span> | ||
int main() { | ||
gsl::cstring_span<> S = \"Hello, GSL\"; | ||
return 0; | ||
} | ||
" | ||
) | ||
try_compile(GSL_COMPILED ${GSL_TEST_DIR} SOURCES ${GSL_TEST_FILE} | ||
COMPILE_DEFINITIONS -I${GSL_INCLUDE_DIR}) | ||
# | ||
# Project has a GSL dependency. if HexCalcLib can not be compiled => | ||
# we should download project from git repository | ||
if (NOT GSL_COMPILED) | ||
message(STATUS "GSL was not found in system. Start downloading it.") | ||
message(STATUS "If something goes wrong, update submodule by yourselves with commands:\ | ||
\n\t\t\tgit init\ | ||
\n\t\t\tgit update") | ||
find_program(GIT_COMMAND NAMES git) | ||
if (NOT GIT_COMMAND) | ||
message(FATAL_ERROR "Could not find git command. Install it and retry") | ||
endif() | ||
message(STATUS Git found: ${GIT_COMMAND}) | ||
|
||
execute_process(COMMAND "${GIT_COMMAND}" submodule init RESULT_VARIABLE GSL_INITED) | ||
if (NOT GSL_INITED EQUAL 0) | ||
message(FATAL_ERROR "Can't initialize submodule GSL in lib directory") | ||
endif() | ||
|
||
execute_process(COMMAND "${GIT_COMMAND}" submodule update RESULT_VARIABLE GSL_UPDATED) | ||
if (NOT GSL_UPDATED EQUAL 0) | ||
message(FATAL_ERROR "Can't update submodule GSL in lib directory") | ||
endif() | ||
|
||
message(STATUS "GSL was successfully downloaded") | ||
endif(NOT GSL_COMPILED) | ||
|
||
set(sources source/HexCalcLib.cpp) | ||
|
||
add_library(HexCalcLib ${sources}) | ||
target_include_directories(HexCalcLib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
target_include_directories(HexCalcLib PRIVATE ${GSL_INCLUDE_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#pragma once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "hexCalc.h" | ||
#include <string> | ||
|
||
using namespace std; | ||
|
||
// Decided not to use hard-weighted libraries like | ||
struct StringView | ||
{ | ||
|
||
}; | ||
|
||
|
||
enum class Associativity | ||
{ | ||
Left, | ||
Right | ||
}; | ||
|
||
// TODO: add ~ | ||
|
||
class TokenOperation | ||
{ | ||
public: | ||
TokenOperation(Associativity associativity, const int precedence, const string &representation) | ||
: associativity(associativity) | ||
, precedence(precedence) | ||
, representation(representation) | ||
{} | ||
|
||
Associativity getAssociativity() const { return associativity;} | ||
int getPrecedence() const { return precedence; } | ||
const string &getRepresentation() const { return representation; } | ||
|
||
private: | ||
Associativity associativity; | ||
int precedence; | ||
const string representation; | ||
}; | ||
|
||
// TODO: watch c++ precedence | ||
// TODO: add unary operators ~, - | ||
|
||
// Binary operations | ||
const TokenOperation operations[] | ||
{ | ||
TokenOperation(Associativity::Left, 20, "+"), | ||
TokenOperation(Associativity::Left, 20, "-"), | ||
TokenOperation(Associativity::Left, 30, "*"), | ||
TokenOperation(Associativity::Left, 30, "/"), | ||
TokenOperation(Associativity::Left, 30, "%"), | ||
TokenOperation(Associativity::Left, 8, "|"), | ||
TokenOperation(Associativity::Left, 9, "^"), | ||
TokenOperation(Associativity::Left, 10, "&"), | ||
TokenOperation(Associativity::Left, 15, "<<"), | ||
TokenOperation(Associativity::Left, 15, ">>"), | ||
TokenOperation(Associativity::Right, 99, "e"), | ||
TokenOperation(Associativity::Right, 40, "**"), | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Calculator with Hex and Binary support | ||
|
||
Project was inspired by sencalc. This calculator is cross-platform and has some extra features to its predecessor |