Skip to content

Commit

Permalink
Calculator - Removed warnings
Browse files Browse the repository at this point in the history
Changed version to 1.3.2 Beta 2
Main - Changed how the config directory is made if not found
  • Loading branch information
EmmmaTech committed Apr 1, 2021
1 parent ec490e0 commit 1c85d4e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ include $(DEVKITPRO)/libnx/switch_rules
# - <libnx folder>/default_icon.jpg
#---------------------------------------------------------------------------------
VERSION := 1.3.2
STABLE := Beta
STABLE := Beta 2

APP_TITLE := Calculator_NX
APP_AUTHOR := EmreTech
Expand Down
70 changes: 21 additions & 49 deletions core/include/calculator.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#ifndef CORE_CALCULATOR_INCLUDED
#define CORE_CALCULATOR_INCLUDED

#include <iostream>
#include <sstream>
Expand All @@ -9,6 +10,7 @@
#include <type_traits>

namespace Calculator {

template <typename T>
struct MathCalculator {

Expand All @@ -19,22 +21,22 @@ namespace Calculator {
}

// Smaller functions for solving problems. Used mostly in the function below
static T Addition(T a, T b) {
T OldAddition(T a, T b) {
T answer{};
answer = a + b;
return answer;
}
static T Subtraction(T a, T b) {
T OldSubtraction(T a, T b) {
T answer{};
answer = a - b;
return answer;
}
static T Mutiplication(T a, T b) {
T OldMutiplication(T a, T b) {
T answer{};
answer = a * b;
return answer;
}
static T Division(T a, T b) {
T OldDivision(T a, T b) {
T answer{};
answer = a / b;
return answer;
Expand All @@ -43,22 +45,22 @@ namespace Calculator {
// Older method that solves only 2 numbers at a time
T CalculateInt(std::string Operator, T a, T b) {
// Find out what operator the user is using, then solve
if (Operator == "+" || Operator == "addition") return this->Addition(a, b);
if (Operator == "-" || Operator == "subtraction") return this->Subtraction(a, b);
if (Operator == "*" || Operator == "mutiplication") return this->Mutiplication(a, b);
if (Operator == "/" || Operator == "division") return this->Division(a, b);
if (Operator == "+" || Operator == "addition") return this->OldAddition(a, b);
if (Operator == "-" || Operator == "subtraction") return this->OldSubtraction(a, b);
if (Operator == "*" || Operator == "mutiplication") return this->OldMutiplication(a, b);
if (Operator == "/" || Operator == "division") return this->OldDivision(a, b);

// Returns the answer for another variable
return 0;
}

// Alternative method using std::vectors, newer one is recommended
T CalculateMoreInt(std::string_view Operator) {
/*T CalculateMoreInt(const std::string& Operator) {
T answer = VectorCalculator[0];
VectorCalculator.erase(VectorCalculator.begin());
while (!VectorCalculator.empty()) {
switch (turnStringToIntOperator(Operator)) {
switch (Calculator::Convert::turnStringToIntOperator(Operator)) {
case 1:
answer += VectorCalculator[0];
break;
Expand All @@ -83,23 +85,12 @@ namespace Calculator {
}
return answer;
}
} TODO: Restore*/

bool contains_number(std::string str) {
return (str.find_first_of("0123456789") != std::string::npos);
}

static int turnStringToIntOperator (std::string_view string) {
if (string == "+" || string == "-" || string == "*" || string == "/") {
if (string == "+") return 1;
if (string == "-") return 2;
if (string == "*") return 3;
if (string == "/") return 4;
} else return 0;

return 0;
}

void setVector(T newInt){
VectorCalculator.emplace_back(newInt);
}
Expand All @@ -108,34 +99,15 @@ namespace Calculator {
std::vector<T> VectorCalculator;
};

// New methods involving Variadic Templates
static float Addition();

static float Subtraction();

static float Mutiplication();

static float Division();


template <typename T, typename... Types>
static float Addition(T var, Types... rest);

template <typename T, typename... Types>
static float Subtraction(T var, Types... rest);

template <typename T, typename... Types>
static float Mutiplication(T var, Types... rest);

template <typename T, typename... Types>
static float Division(T var, Types... rest);

static int turnStringToIntOperator (std::string_view string);
namespace Convert {
int turnStringToIntOperator (const std::string& string);
}

// Newer method for solving "infinite" amount of numbers, still involves std::vector
// Instead of deleting the first number in the std::vector, this approach loops through all the elements in the std::vector
// This in the end is easier to use
float solve(std::vector<float>& vec, std::string_view operation);
float solve(std::vector<float>& vec, const std::string& operation);

float solve(std::string numbers, std::string_view operation);
}
float solve(std::string numbers, const std::string& operation);
}
#endif // #ifndef CORE_CALCULATOR_INCLUDED
2 changes: 1 addition & 1 deletion core/include/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
#define NRO_DOWNLOAD_PATH "/config/Calculator_NX/download/Calculator_NX.nro"

#define API_URL "https://api.github.com/repos/EmreTech/Calculator_NX/releases/latest"
#define APP_VERSION "v1.3.2-beta"
#define APP_VERSION "v1.3.2-beta2"
5 changes: 2 additions & 3 deletions core/include/download.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
#include "constants.hpp"

#define API_AGENT "EmreTech"
using json = nlohmann::json;

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
CURLcode downloadFile(const char *url, const char *filename);
std::string getLatestTag(std::string url);
std::string getLatestDownload(std::string url);
std::string getLatestTag(const std::string url);
std::string getLatestDownload(const std::string url);
54 changes: 25 additions & 29 deletions core/source/calculator.cpp
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
#include "calculator.hpp"
#include <calculator.hpp>

namespace Calculator {
// New methods involving Variadic Templates
static float Addition() {

// New methods involving Variadic Templates
float Addition() {
return 0;
}

static float Subtraction() {
float Subtraction() {
return 0;
}

static float Mutiplication() {
float Mutiplication() {
return 1;
}

static float Division() {
float Division() {
return 1;
}


template <typename T, typename... Types>
static float Addition(T var, Types... rest) {
float Addition(T var, Types... rest) {
return var + Addition(rest...);
}

template <typename T, typename... Types>
static float Subtraction(T var, Types... rest) {
float Subtraction(T var, Types... rest) {
return var - Subtraction(rest...);
}

template <typename T, typename... Types>
static float Mutiplication(T var, Types... rest) {
float Mutiplication(T var, Types... rest) {
return var * Mutiplication(rest...);
}

template <typename T, typename... Types>
static float Division(T var, Types... rest) {
float Division(T var, Types... rest) {
return var / Division(rest...);
}

static int turnStringToIntOperator (std::string_view string) {
if (string == "+" || string == "-" || string == "*" || string == "/") {
if (string == "+") return 1;
if (string == "-") return 2;
if (string == "*") return 3;
if (string == "/") return 4;
} else return 0;
namespace Convert {
int turnStringToIntOperator (const std::string& string) {
if (string == "+" || string == "-" || string == "*" || string == "/") {
if (string == "+") return 1;
if (string == "-") return 2;
if (string == "*") return 3;
if (string == "/") return 4;
} else return 0;

return 0;
return 0;
}
}

// Newer method for solving "infinite" amount of numbers, still involves std::vector
// Instead of deleting the first number in the std::vector, this approach loops through all the elements in the std::vector
// This in the end is easier to use
float solve(std::vector<float>& vec, std::string_view operation) {
float solve(std::vector<float>& vec, const std::string& operation) {
float result = vec[0];

for (std::vector<float>::size_type i{ 1 }; i < vec.size(); i++) {
auto current_num = vec[i];

switch (turnStringToIntOperator(operation)) {
switch (Convert::turnStringToIntOperator(operation)) {
case 1: {
result += Addition(current_num);
break;
Expand All @@ -82,7 +78,7 @@ namespace Calculator {
return result;
}

float solve(std::string numbers, std::string_view operation) {
float solve(std::string numbers, const std::string& operation) {
std::istringstream iss(numbers);
std::string current_str_num;

Expand All @@ -95,7 +91,7 @@ namespace Calculator {
float answer = num_deque[0];

for (size_t i{ 1 }; i < num_deque.size(); i++) {
switch (turnStringToIntOperator(operation)) {
switch (Convert::turnStringToIntOperator(operation)) {
case 1: {
answer = Addition(answer, num_deque[i]);
break;
Expand Down
12 changes: 6 additions & 6 deletions core/source/download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ CURLcode downloadFile(const char *url, const char *filename) {
return res;
}

std::string getLatestTag(std::string url) {
CURLcode code = downloadFile(url.c_str(), JSON_DOWNLOAD_PATH);
std::string getLatestTag(const std::string url) {
downloadFile(url.c_str(), JSON_DOWNLOAD_PATH);

json api_data;
nlohmann::json api_data;
std::ifstream api_file(JSON_DOWNLOAD_PATH);

api_file >> api_data;
Expand All @@ -69,10 +69,10 @@ std::string getLatestTag(std::string url) {
return api_data["tag_name"];
}

std::string getLatestDownload(std::string url) {
CURLcode code = downloadFile(url.c_str(), JSON_DOWNLOAD_PATH);
std::string getLatestDownload(const std::string url) {
downloadFile(url.c_str(), JSON_DOWNLOAD_PATH);

json api_data;
nlohmann::json api_data;
std::ifstream api_file(JSON_DOWNLOAD_PATH);

api_file >> api_data;
Expand Down
2 changes: 1 addition & 1 deletion gui/include/updateActivity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

#include <borealis.hpp>

struct updateActivity : public brls::Activity {
struct UpdateActivity : public brls::Activity {
CONTENT_FROM_XML_RES("activity/update.xml");
};
8 changes: 3 additions & 5 deletions gui/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
*/

#include <string>
#include <filesystem>
#include <switch.h>
#include <borealis.hpp>
#include "calculatorTab.hpp"
#include "mainActivity.hpp"
#include "aboutTab.hpp"
#include "updateActivity.hpp"
#include "updaterTab.hpp"
#include <filesystem>
#include <fstream>
#include "constants.hpp"
#include "download.hpp"

Expand All @@ -40,8 +39,7 @@ using namespace brls::literals;
int main(int argc, char* argv[]) {
bool versionsSame;

if (!std::filesystem::exists(CONFIG_PATH)) std::filesystem::create_directory(CONFIG_PATH);
if (!std::filesystem::exists(DOWNLOAD_PATH)) std::filesystem::create_directory(DOWNLOAD_PATH);
if (!std::filesystem::exists(DOWNLOAD_PATH)) std::filesystem::create_directories(DOWNLOAD_PATH);

socketInitializeDefault();

Expand Down Expand Up @@ -74,7 +72,7 @@ int main(int argc, char* argv[]) {
if (versionsSame)
brls::Application::pushActivity(new MainActivity());
else
brls::Application::pushActivity(new updateActivity());
brls::Application::pushActivity(new UpdateActivity());

// Main application loop
while (brls::Application::mainLoop());
Expand Down

0 comments on commit 1c85d4e

Please sign in to comment.