Skip to content

Commit

Permalink
Initial. Set up Cmake for HexCalcLib. Start writing library
Browse files Browse the repository at this point in the history
  • Loading branch information
skapix committed Jul 22, 2017
0 parents commit b66e07a
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea
build*
*build
cmake-build*
3 changes: 3 additions & 0 deletions .gitmodules
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
8 changes: 8 additions & 0 deletions CMakeLists.txt
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)
53 changes: 53 additions & 0 deletions lib/CMakeLists.txt
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})
1 change: 1 addition & 0 deletions lib/GSL
Submodule GSL added at be43c7
1 change: 1 addition & 0 deletions lib/include/hexCalc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#pragma once
60 changes: 60 additions & 0 deletions lib/source/HexCalcLib.cpp
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, "**"),
};


3 changes: 3 additions & 0 deletions readme.md
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

0 comments on commit b66e07a

Please sign in to comment.