mirror of
https://github.com/kuhyx/toDo.git
synced 2026-07-04 12:03:05 +02:00
Adding all of project base files
This commit is contained in:
parent
e86cb56980
commit
c53d9c63bf
73
allFunctions.hpp
Normal file
73
allFunctions.hpp
Normal file
@ -0,0 +1,73 @@
|
||||
#ifndef ALL_FUNCTIONS_HPP
|
||||
#define ALL_FUNCTIONS_HPP
|
||||
|
||||
#include <string>
|
||||
#include "dataStructures.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
//basic.cpp
|
||||
int charToInt(const char c);
|
||||
void print(const std::string s);
|
||||
bool charIsNumber(const char c);
|
||||
int getDaysFromMonth(const monthChecker month);
|
||||
void printOneStringColor(const std::vector <Task> vector, const int oneTask);
|
||||
void printDate(const Date date);
|
||||
void printErrorStringContainsNotNumber(const std::string s);
|
||||
void printNumberTooLow(const int number, const int min);
|
||||
void printNumberTooHigh(const int number, const int max);
|
||||
void printNotValidStringLength(const std::string s, const int desiredLength);
|
||||
void printInvalidCharacter(const char c, const char desiredCharacter);
|
||||
bool numberTooLow(const int number, const int min);
|
||||
bool numberTooHigh(const int number, const int max);
|
||||
void printStringVector(const std::vector <std::string> vector);
|
||||
|
||||
//check.cpp
|
||||
bool checkLongerMonth(const int month);
|
||||
bool checkMenu(const std::string input);
|
||||
bool checkTitle(const std::string title);
|
||||
bool checkTime(const std::string time);
|
||||
bool checkLeap(const int year);
|
||||
bool checkDate(const std::string date);
|
||||
bool taskForToday(const Date dateFromFile);
|
||||
bool checkRepeat(const std::string input);
|
||||
bool checkWhenRepeat(const std::string whenRepeat);
|
||||
|
||||
//file.cpp
|
||||
void fileAddTask(const Task taskToAdd);
|
||||
std::vector <std::string> readList();
|
||||
std::vector <std::string> getTitles(const std::vector <std::string> fileLines);
|
||||
std::vector <std::string> getTimes(const std::vector <std::string> fileLines);
|
||||
std::vector <std::string> getDates(const std::vector <std::string> fileLines);
|
||||
void fileReadToday();
|
||||
std::vector <std::string> removeCompleted(const std::vector <std::string> fileList,
|
||||
const std::vector <Task> tasksToday);
|
||||
|
||||
void outputFile(const std::vector <std::string> fileLines);
|
||||
|
||||
//getters.cpp
|
||||
std::vector <Date> getDate(const std::vector <Task> dividedTasks);
|
||||
std::vector <Task> getDividedTasks(const std::vector <std::string> fileLines);
|
||||
std::vector <Task> getTasksToday(const std::vector <Task> dividedTasks);
|
||||
|
||||
//void fileAddRepeatingTask(const repeatTask taskToAdd);
|
||||
|
||||
//input.cpp
|
||||
std::string inputTaskOneLine(const int whatToCheck);
|
||||
Task inputTask();
|
||||
int inputMenu();
|
||||
void continueProgram(const int &userChoice);
|
||||
bool menuLoop();
|
||||
|
||||
//output.cpp
|
||||
void checkToday();
|
||||
|
||||
//valid.cpp
|
||||
bool validString(const std::string s);
|
||||
bool validNumberInput(const std::string input, const int min, const int max);
|
||||
bool validStringLength(const std::string s, const int desiredLength);
|
||||
bool validCharacter(const char inputC, const char desiredC);
|
||||
bool validAddTaskInput(const std::string input, const int inputType);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
209
basic.cpp
Normal file
209
basic.cpp
Normal file
@ -0,0 +1,209 @@
|
||||
#ifndef BASIC_CPP
|
||||
#define BASIC_CPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <windows.h>
|
||||
#include "dataStructures.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
void print(const std::string s) { std::cout << s << std::endl; }
|
||||
int charToInt(const char c) { return c - '0'; }
|
||||
|
||||
void e() { print("Poor man breakboint"); }
|
||||
|
||||
bool charIsNumber(const char c) { return c >= '0' && c <= '9'; }
|
||||
|
||||
|
||||
void printErrorStringContainsNotNumber(const std::string s)
|
||||
{
|
||||
std::cout << "string: \"" << s
|
||||
<< "\" contains character different than number " << std::endl;
|
||||
}
|
||||
|
||||
void printNumberTooLow(const int number, const int min)
|
||||
{
|
||||
std::cout << "number: " << number
|
||||
<< " is too low. Minimal number is: " << min << std::endl;
|
||||
}
|
||||
|
||||
void printNumberTooHigh(const int number, const int max)
|
||||
{
|
||||
std::cout << "number: " << number
|
||||
<< " is too high. Maximal number is: " << max << std::endl;
|
||||
}
|
||||
|
||||
void printNotValidStringLength(const std::string s, const int desiredLength)
|
||||
{
|
||||
std::cout << "String: \"" << s << "\" is too short/too long, it is: "
|
||||
<< s.length() << " characters long but should be: " << desiredLength
|
||||
<< " characters long " << std::endl;
|
||||
}
|
||||
|
||||
void printInvalidCharacter(const char c, const char desiredCharacter)
|
||||
{
|
||||
std::cout << "[ " << c << " ] Is invalid character, expected: [ "
|
||||
<< desiredCharacter << " ]" << std::endl;
|
||||
}
|
||||
|
||||
void printContainsIllegalCharacter( const std::string s,
|
||||
const char illegalCharacter )
|
||||
{
|
||||
std::cout << "String: " << s << " consists of illegal sign: ["
|
||||
<< illegalCharacter << "]!" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
bool numberTooLow(const int number, const int min)
|
||||
{
|
||||
if(number < min)
|
||||
{
|
||||
printNumberTooLow(number, min);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool numberTooHigh(const int number, const int max)
|
||||
{
|
||||
if(number > max)
|
||||
{
|
||||
printNumberTooHigh(number, max);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool containsIllegalCharacter(const std::string s, const char illegalCharacter)
|
||||
{
|
||||
if( s.find(illegalCharacter) != std::string::npos)
|
||||
{
|
||||
printContainsIllegalCharacter(s, illegalCharacter);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void printTaskVector(const std::vector <Task> vector)
|
||||
{
|
||||
print("Printing titles");
|
||||
for(unsigned int i = 0; i < vector.size(); i++) print(vector.at(i).title);
|
||||
//print("Printing times");
|
||||
//for(unsigned int i = 0; i < vector.size(); i++) print(vector.at(i).time);
|
||||
print("Printing dates");
|
||||
for(unsigned int i = 0; i < vector.size(); i++) print(vector.at(i).date);
|
||||
}
|
||||
|
||||
/*
|
||||
void printTimeVector(const std::vector <Time> vector)
|
||||
{
|
||||
print("Printing hours");
|
||||
for(unsigned int i = 0; i < vector.size(); i++)
|
||||
{
|
||||
std::cout << vector.at(i).hour << std::endl;
|
||||
}
|
||||
print("Printing minutes");
|
||||
for(unsigned int i = 0; i < vector.size(); i++)
|
||||
{
|
||||
std::cout << vector.at(i).minute << std::endl;
|
||||
}
|
||||
}*/
|
||||
|
||||
void printDate(const Date date)
|
||||
{
|
||||
print("Printing Day");
|
||||
std::cout << date.day << std::endl;
|
||||
print("Printing Month");
|
||||
std::cout << date.month << std::endl;
|
||||
print("Printing Year");
|
||||
std::cout << date.year << std::endl;
|
||||
}
|
||||
|
||||
void printDateVector(const std::vector <Date> vector)
|
||||
{
|
||||
print("Printing Days");
|
||||
for(unsigned int i = 0; i < vector.size(); i++)
|
||||
{
|
||||
std::cout << vector.at(i).day << std::endl;
|
||||
}
|
||||
print("Printing Months");
|
||||
for(unsigned int i = 0; i < vector.size(); i++)
|
||||
{
|
||||
std::cout << vector.at(i).month << std::endl;
|
||||
}
|
||||
print("Printing Years");
|
||||
for(unsigned int i = 0; i < vector.size(); i++)
|
||||
{
|
||||
std::cout << vector.at(i).year << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void printStringVector(const std::vector <std::string> vector)
|
||||
{
|
||||
for(unsigned int i = 0; i < vector.size(); i++) print(vector.at(i));
|
||||
}
|
||||
|
||||
void printTaskInfo(const Task task)
|
||||
{
|
||||
std::cout << task.number << ". " << task.title << "; " << task.date
|
||||
<< "; " << task.whenRepeat << "; " << (task.completed ? "[X]" : "[]")
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void printHighlightedTask(const std::vector <Task> vector, const int i)
|
||||
{
|
||||
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTextAttribute(hConsole, HIGHLIGHTED_COLOR);
|
||||
printTaskInfo(vector.at(i));
|
||||
SetConsoleTextAttribute(hConsole, NORMAL_COLOR);
|
||||
}
|
||||
|
||||
void printOneStringColor(const std::vector <Task> vector, const int oneTask)
|
||||
{
|
||||
int sizeOfVector = vector.size();
|
||||
for(int i = 0; i < sizeOfVector; i++)
|
||||
{
|
||||
if(vector.at(i).show == 1)
|
||||
{
|
||||
if(i == oneTask) printHighlightedTask(vector, i);
|
||||
else printTaskInfo(vector.at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string normalDateToStringMonth(const Date realDate)
|
||||
{
|
||||
std::string month;
|
||||
if(realDate.month < 10) month = "0" + std::to_string(realDate.month) + CHARACTER_BETWEEN_DATE;
|
||||
else month = std::to_string(realDate.month) + CHARACTER_BETWEEN_DATE;
|
||||
return month;
|
||||
}
|
||||
|
||||
std::string normalDateToStringDay(const Date realDate)
|
||||
{
|
||||
std::string day;
|
||||
if(realDate.day < 10) day = "0" + std::to_string(realDate.day) + CHARACTER_BETWEEN_DATE;
|
||||
else day = std::to_string(realDate.day) + CHARACTER_BETWEEN_DATE;
|
||||
return day;
|
||||
}
|
||||
|
||||
std::string normalDateToString(const Date realDate)
|
||||
{
|
||||
|
||||
std::string day = normalDateToStringDay(realDate);
|
||||
std::string month = normalDateToStringMonth(realDate);
|
||||
std::string year = std::to_string(realDate.year);
|
||||
std::string stringToReturn = day + month + year;
|
||||
return stringToReturn;
|
||||
}
|
||||
|
||||
std::string taskToString(const Task task)
|
||||
{
|
||||
std::string outputString = task.title + CHARACTER_BETWEEN_SECTIONTS + " "
|
||||
+ task.date + CHARACTER_BETWEEN_SECTIONTS + " "
|
||||
+ std::to_string(task.whenRepeat);
|
||||
return outputString;
|
||||
}
|
||||
|
||||
#endif
|
||||
180
check.cpp
Normal file
180
check.cpp
Normal file
@ -0,0 +1,180 @@
|
||||
#ifndef CHECK_CPP
|
||||
#define CHECK_CPP
|
||||
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
#include "dataStructures.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "allFunctions.hpp"
|
||||
|
||||
bool checkLongerMonth(const int month)
|
||||
{
|
||||
for(unsigned int i = 0; i < LONGER_MONTHS.size(); i++)
|
||||
{
|
||||
if(month == LONGER_MONTHS.at(i)) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool checkTitle(const std::string title)
|
||||
{
|
||||
if(containsIllegalCharacter(title, CHARACTER_BETWEEN_SECTIONTS)) return 0;
|
||||
if(title.empty())
|
||||
{
|
||||
print("Title is empty!");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
bool checkTime(const std::string time)
|
||||
{
|
||||
if(!validStringLength(time, TIME_LENGTH)) return 0;
|
||||
|
||||
std::string hourS = time.substr(FIRST_HOUR_NUMBER, 2);
|
||||
if(!validNumberInput(hourS, 0, HOURS_IN_DAY)) return 0;
|
||||
|
||||
if(!validCharacter(time.at(COLON_NUMBER), CHARACTER_BETWEEN_TIME)) return 0;
|
||||
|
||||
std::string minutesS = time.substr(FIRST_MINUTE_NUMBER, 2);
|
||||
if(!validNumberInput(minutesS, 0, MINUTES_IN_HOUR)) return 0;
|
||||
return 1;
|
||||
} */
|
||||
|
||||
|
||||
bool checkLeap(const int year)
|
||||
{
|
||||
return (!(year % 4) && year % 100) || !(year % 400);
|
||||
}
|
||||
|
||||
bool checkMenu(const std::string input)
|
||||
{
|
||||
if(!validStringLength(input, CHOICE_LENGTH)) return 0;
|
||||
if(!charIsNumber(input.at(0))) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool checkRepeat(const std::string input)
|
||||
{
|
||||
if(!validStringLength(input, CHOICE_LENGTH)) return 0;
|
||||
if(!charIsNumber(input.at(0))) return 0;
|
||||
if(!validNumberInput(input, 0, WHEN_REPEAT_MAX)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool taskDaySameAsToday(const Date dateFromFile, const Date currentDate)
|
||||
{
|
||||
return dateFromFile.day == currentDate.day
|
||||
&& dateFromFile.month == currentDate.month
|
||||
&& dateFromFile.year == currentDate.year;
|
||||
}
|
||||
|
||||
Date getCurrentDate(const tm local_tm)
|
||||
{
|
||||
Date currentDate;
|
||||
currentDate.year = local_tm.tm_year + STARTING_CHRONO_YEAR;
|
||||
currentDate.month = local_tm.tm_mon + 1; // First month is represented as "0"?
|
||||
currentDate.day = local_tm.tm_mday;
|
||||
return currentDate;
|
||||
}
|
||||
|
||||
tm getTmNow()
|
||||
{
|
||||
using namespace std;
|
||||
using namespace std::chrono;
|
||||
typedef duration<int, ratio_multiply<hours::period, ratio<HOURS_IN_DAY> >::type> days;
|
||||
system_clock::time_point now = system_clock::now();
|
||||
system_clock::duration tp = now.time_since_epoch();
|
||||
tp -= duration_cast<days>(tp);
|
||||
tp -= duration_cast<hours>(tp);
|
||||
tp -= duration_cast<minutes>(tp);
|
||||
tp -= duration_cast<seconds>(tp);
|
||||
time_t tt = system_clock::to_time_t(now);
|
||||
//tm utc_tm = *gmtime(&tt);
|
||||
return *localtime(&tt);
|
||||
}
|
||||
|
||||
// Copied from: https://stackoverflow.com/a/15958113
|
||||
bool taskForToday(const Date dateFromFile) // TO;DO: Figure out how it works
|
||||
{
|
||||
Date currentDate = getCurrentDate(getTmNow());
|
||||
if(taskDaySameAsToday(dateFromFile, currentDate)) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
bool validYear(const std::string date)
|
||||
{
|
||||
std::string yearS = date.substr(FIRST_YEAR_NUMBER, YEAR_LENGTH);
|
||||
if(!validNumberInput(yearS, MIN_YEAR, MAX_YEAR)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool validMonth(const std::string date)
|
||||
{
|
||||
std::string monthS = date.substr(FIRST_MONTH_NUMBER, 2);
|
||||
if(!validNumberInput(monthS, MIN_MONTH, MAX_MONTH)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int stringDateToYear(const std::string date)
|
||||
{
|
||||
return std::stoi(date.substr(FIRST_YEAR_NUMBER, YEAR_LENGTH));
|
||||
}
|
||||
|
||||
int stringDateToMonth(const std::string date)
|
||||
{
|
||||
return std::stoi(date.substr(FIRST_MONTH_NUMBER, MONTH_LENGTH));
|
||||
}
|
||||
|
||||
monthChecker monthProperties(const int monthNumber, const int year)
|
||||
{
|
||||
monthChecker month;
|
||||
month.isLeap = checkLeap(year);
|
||||
month.isFebruary = (monthNumber == FEBRUARY);
|
||||
month.isLongMonth = 0;
|
||||
if(!month.isFebruary) month.isLongMonth = checkLongerMonth(monthNumber);
|
||||
return month;
|
||||
}
|
||||
|
||||
bool validDays(const monthChecker month, const std::string date)
|
||||
{
|
||||
int daysInMonth = getDaysFromMonth(month);
|
||||
std::string dayS = date.substr(FIRST_DAY_NUMBER, DAY_LENGTH);
|
||||
if(!validNumberInput(dayS, 0, daysInMonth)) return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
bool validDays(const std::string date)
|
||||
{
|
||||
int yearInt = stringDateToYear(date);
|
||||
int monthInt = stringDateToMonth(date);
|
||||
monthChecker month = monthProperties(monthInt, yearInt);
|
||||
return validDays(month, date);
|
||||
}
|
||||
|
||||
bool checkDate(const std::string date)
|
||||
{
|
||||
if(!validStringLength(date, DATE_LENGTH)) return 0;
|
||||
if(!validYear(date)) return 0;
|
||||
if(!validMonth(date)) return 0;
|
||||
if(!validDays(date)) return 0;
|
||||
|
||||
char firstSlash = date.at(FIRST_DATE_SLASH);
|
||||
char secondSlash = date.at(SECOND_DATE_SLASH);
|
||||
if(!validCharacter(firstSlash, CHARACTER_BETWEEN_DATE)) return 0;
|
||||
if(!validCharacter(secondSlash, CHARACTER_BETWEEN_DATE)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool checkWhenRepeat(const std::string whenRepeat)
|
||||
{
|
||||
if(!validStringLength(whenRepeat, WHEN_REPEAT_LENGTH)) return 0;
|
||||
if(!validNumberInput(whenRepeat, WHEN_REPEAT_MIN, WHEN_REPEAT_MAX)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
126
constants.hpp
Normal file
126
constants.hpp
Normal file
@ -0,0 +1,126 @@
|
||||
#ifndef CONSTANTS_HPP
|
||||
#define CONSTANTS_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "dataStructures.hpp"
|
||||
|
||||
// user menu choices
|
||||
const int CHOICE_LENGTH = 1;
|
||||
const int MAX_CHOICE = 2;
|
||||
const int QUIT = 0;
|
||||
const int CHECK_TODAY = 1;
|
||||
const int ADD_TASK = 2;
|
||||
|
||||
// Constants for user choosing how often he wants to repeat
|
||||
const int NEVER_REPEAT = 0;
|
||||
const int EVERY_DAY = 1;
|
||||
const int EVERY_WEEK = 2;
|
||||
const int EVERY_MONTH = 3;
|
||||
const int EVERY_YEAR = 4;
|
||||
const int WHEN_REPEAT_MIN = 0;
|
||||
const int WHEN_REPEAT_MAX = 4;
|
||||
const int WHEN_REPEAT_LENGTH = WHEN_REPEAT_MAX >= 10 ? 2 : 1;
|
||||
|
||||
const int HOURS_IN_DAY = 24; // THIS ONE _IS_ USED
|
||||
// Constants for checking time input, CURRENTLY UNUSED
|
||||
const int TIME_LENGTH = 5;
|
||||
const int MINUTES_IN_HOUR = 59;
|
||||
const int FIRST_HOUR_NUMBER = 0;
|
||||
const int SECOND_HOUR_NUMBER = 1;
|
||||
const int COLON_NUMBER = 2;
|
||||
const int FIRST_MINUTE_NUMBER = 3;
|
||||
const int SECOND_MINUTE_NUMBER = 4;
|
||||
|
||||
// Constants for checking Date
|
||||
const int STARTING_CHRONO_YEAR = 1900;
|
||||
const int YEAR_LENGTH = 4;
|
||||
const int MONTH_LENGTH = 2;
|
||||
const int DAY_LENGTH = 2;
|
||||
const int EXTRA_DATE_CHARACTERS = 2;
|
||||
const int MONTH_START = DAY_LENGTH + 1;
|
||||
const int YEAR_START = DAY_LENGTH + MONTH_LENGTH + EXTRA_DATE_CHARACTERS;
|
||||
const int DATE_LENGTH = YEAR_LENGTH + MONTH_LENGTH + DAY_LENGTH + EXTRA_DATE_CHARACTERS;
|
||||
const int MIN_YEAR = 2020;
|
||||
const int MAX_YEAR = 2099;
|
||||
const int MIN_MONTH = 1;
|
||||
const int MAX_MONTH = 12;
|
||||
const int DAYS_IN_LONG_MONTH = 31;
|
||||
const int DAYS_IN_SHORT_MONTH = 30;
|
||||
const int DAYS_FEBRUARY_LEAP = 29;
|
||||
const int DAYS_FEBRUARY_NOT_LEAP = 28;
|
||||
const int FIRST_DAY_NUMBER = 0;
|
||||
const int FIRST_DATE_SLASH = 2;
|
||||
const int FIRST_MONTH_NUMBER = 3;
|
||||
const int SECOND_DATE_SLASH = 5;
|
||||
const int FIRST_YEAR_NUMBER = 6;
|
||||
const int DAYS_IN_WEEK = 7;
|
||||
// constants for validAddTaskInput() from valid.cpp
|
||||
const int CHECK_TITLE = 0;
|
||||
|
||||
//const int CHECK_TIME = 1;
|
||||
const int CHECK_DATE = 2;
|
||||
const int CHECK_WHEN_REPEAT = 3;
|
||||
|
||||
// some Tasks constants ¯\_(ツ)_/¯
|
||||
const int SPACE_BETWEEN_TASK_PARTS = 2;
|
||||
const int MIN_TASKS = 0;
|
||||
|
||||
|
||||
// "UI" colors
|
||||
const int YELLOW_ON_BLACK = 14;
|
||||
const int WHITE_ON_BLACK = 15;
|
||||
const int BLACK_ON_WHITE = 240;
|
||||
const int HIGHLIGHTED_COLOR = BLACK_ON_WHITE;
|
||||
const int NORMAL_COLOR = WHITE_ON_BLACK;
|
||||
|
||||
//months
|
||||
const int JANUARY = 1;
|
||||
const int FEBRUARY = 2;
|
||||
const int MARCH = 3;
|
||||
const int APRIL = 4;
|
||||
const int MAY = 5;
|
||||
const int JUNE = 6;
|
||||
const int JULY = 7;
|
||||
const int AUGUST = 8;
|
||||
const int SEPTEMBER = 9;
|
||||
const int OCTOBER = 10;
|
||||
const int NOVEMBER = 11;
|
||||
const int DECEMBER = 12;
|
||||
|
||||
//currently unused
|
||||
//const int ADD_REPEATING_TASK = 3;
|
||||
|
||||
//Way tasks look in task files
|
||||
const char CHARACTER_BETWEEN_SECTIONTS = ';';
|
||||
const char CHARACTER_BETWEEN_TIME = ':';
|
||||
const char CHARACTER_BETWEEN_DATE = '/';
|
||||
|
||||
//User menu inputs
|
||||
const char SPACE = 32;
|
||||
const char ESCAPE = 27;
|
||||
const char KEY_UP = 72;
|
||||
const char KEY_DOWN = 80;
|
||||
const char KEY_LEFT = 75;
|
||||
const char KEY_RIGHT = 77;
|
||||
|
||||
|
||||
|
||||
const std::string MENU = "What do you want to do?\n0. Quit\n1. Check Today\n2. Add task";
|
||||
const std::string WHEN_REPEAT_MENU = "When do you want to repeat the task? \n0. NEVER\n1. every day\n2. Weekly\n3. Monthly\n4. Yearly";
|
||||
const std::string CHECK_TODAY_INFO = "Tasks for today: ESCAPE to exit, SPACE to complete";
|
||||
const std::string FILE_NAME_NORMAL_TASK = "Tasks.txt";
|
||||
const std::string FILE_NAME_REPEATING_TASK = "repeatTasks.txt";
|
||||
const char* CLEAR_SCREEN_WINDOWS = "CLS";
|
||||
|
||||
|
||||
const std::vector <std::string> INPUT_INFO = {"Enter task title: ",
|
||||
"Enter time: using format HH:MM",
|
||||
"Enter date: using format DD/MM/YYYY ",
|
||||
WHEN_REPEAT_MENU};
|
||||
const std::vector <int> LONGER_MONTHS = {JANUARY, MARCH, MAY, JULY, AUGUST,
|
||||
OCTOBER, DECEMBER};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
44
dataStructures.hpp
Normal file
44
dataStructures.hpp
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef DATA_STRUCTURES_HPP
|
||||
#define DATA_STRUCTURES_HPP
|
||||
|
||||
#include <string>
|
||||
#include "constants.hpp"
|
||||
|
||||
/*
|
||||
struct Time{
|
||||
int hour;
|
||||
int minute;
|
||||
};*/
|
||||
|
||||
struct Date{
|
||||
int day;
|
||||
int month;
|
||||
int year;
|
||||
};
|
||||
|
||||
struct Task{
|
||||
std::string title;
|
||||
//std::string time;
|
||||
Date realDate;
|
||||
std::string date;
|
||||
int whenRepeat;
|
||||
bool completed = 0;
|
||||
bool show = 0;
|
||||
int number;
|
||||
};
|
||||
|
||||
/*
|
||||
struct repeatTask{
|
||||
std::string title;
|
||||
int whenRepeat;
|
||||
Date lastCompleted;
|
||||
int number;
|
||||
}; */
|
||||
|
||||
struct monthChecker{
|
||||
bool isFebruary;
|
||||
bool isLongMonth;
|
||||
bool isLeap;
|
||||
};
|
||||
|
||||
#endif
|
||||
92
file.cpp
Normal file
92
file.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
#ifndef FILE_CPP
|
||||
#define FILE_CPP
|
||||
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include "dataStructures.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
void fileAddTask(const Task taskToAdd)
|
||||
{
|
||||
std::fstream taskList;
|
||||
taskList.open(FILE_NAME_NORMAL_TASK, std::ios_base::app);
|
||||
taskList << taskToAdd.title << CHARACTER_BETWEEN_SECTIONTS << " "
|
||||
<< taskToAdd.date << CHARACTER_BETWEEN_SECTIONTS << " "
|
||||
<< taskToAdd.whenRepeat << std::endl;
|
||||
taskList.close();
|
||||
}
|
||||
|
||||
/*
|
||||
void fileAddRepeatingTask(const repeatTask taskToAdd)
|
||||
{
|
||||
std::fstream taskList;
|
||||
taskList.open(FILE_NAME_REPEATING_TASK, std::ios_base::app);
|
||||
taskList << taskToAdd.title << CHARACTER_BETWEEN_SECTIONTS << " "
|
||||
<< taskToAdd.whenRepeat << CHARACTER_BETWEEN_SECTIONTS << " "
|
||||
<< taskToAdd.lastCompleted.day << "/" << taskToAdd.lastCompleted.month
|
||||
<< "/" << taskToAdd.lastCompleted.year << std::endl;
|
||||
taskList.close();
|
||||
}*/
|
||||
|
||||
std::vector <std::string> removeCompleted( const std::vector <std::string> fileList,
|
||||
const std::vector <Task> tasksToday)
|
||||
{
|
||||
std::vector <std::string> tempList = fileList;
|
||||
|
||||
for(unsigned int i = 0; i < tasksToday.size(); i++)
|
||||
{
|
||||
std::vector<std::string>::iterator currLine = tempList.begin() +
|
||||
tasksToday.at(i).number;
|
||||
if(tasksToday.at(i).completed) tempList.erase(currLine);
|
||||
else
|
||||
{
|
||||
std::string lineS = taskToString(tasksToday.at(i));
|
||||
tempList.at(tasksToday.at(i).number) = lineS;
|
||||
|
||||
}
|
||||
}
|
||||
return tempList;
|
||||
}
|
||||
|
||||
void vectorToFile(const std::vector <std::string> strings, std::ofstream &file)
|
||||
{
|
||||
for(unsigned int i = 0; i < strings.size(); i++)
|
||||
{
|
||||
file << strings.at(i) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void outputFile(const std::vector <std::string> fileLines)
|
||||
{
|
||||
std::ofstream taskList;
|
||||
taskList.open(FILE_NAME_NORMAL_TASK);
|
||||
vectorToFile(fileLines, taskList);
|
||||
}
|
||||
|
||||
std::vector <std::string> fileToVector(std::ifstream &file, std::vector <std::string> strings)
|
||||
{
|
||||
std::string line;
|
||||
if(file.is_open())
|
||||
{
|
||||
while(getline(file, line))
|
||||
{
|
||||
strings.push_back(line);
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
std::vector <std::string> readList()
|
||||
{
|
||||
std::ifstream taskList (FILE_NAME_NORMAL_TASK);
|
||||
std::vector <std::string> fileLines;
|
||||
return fileToVector(taskList, fileLines);
|
||||
}
|
||||
|
||||
#endif
|
||||
137
getters.cpp
Normal file
137
getters.cpp
Normal file
@ -0,0 +1,137 @@
|
||||
#ifndef GETTERS_CPP
|
||||
#define GETTERS_CPP
|
||||
|
||||
#include <vector>
|
||||
#include "dataStructures.hpp"
|
||||
|
||||
std::string stringToTaskTitle(const std::string s)
|
||||
{
|
||||
size_t firstCharacter = s.find(CHARACTER_BETWEEN_SECTIONTS);
|
||||
return s.substr(0, firstCharacter);
|
||||
}
|
||||
|
||||
std::string stringToTime(const std::string s)
|
||||
{
|
||||
size_t firstCharacter = s.find(CHARACTER_BETWEEN_SECTIONTS);
|
||||
return s.substr(firstCharacter + SPACE_BETWEEN_TASK_PARTS, TIME_LENGTH);
|
||||
}
|
||||
|
||||
std::string stringToStringDate(const std::string s)
|
||||
{
|
||||
size_t firstCharacter = s.find(CHARACTER_BETWEEN_SECTIONTS);
|
||||
return s.substr(firstCharacter + SPACE_BETWEEN_TASK_PARTS, DATE_LENGTH);
|
||||
}
|
||||
|
||||
Date stringToRealDate(const std::string s)
|
||||
{
|
||||
Date newDate;
|
||||
newDate.day = std::stoi(s.substr(0, DAY_LENGTH));
|
||||
newDate.month = std::stoi(s.substr(MONTH_START, MONTH_LENGTH));
|
||||
newDate.year = std::stoi(s.substr(YEAR_START, YEAR_LENGTH));
|
||||
return newDate;
|
||||
}
|
||||
|
||||
int stringToWhenRepeat(const std::string s)
|
||||
{
|
||||
size_t firstCharacter = s.find(CHARACTER_BETWEEN_SECTIONTS);
|
||||
size_t secondCharacter = s.find(CHARACTER_BETWEEN_SECTIONTS,
|
||||
firstCharacter + SPACE_BETWEEN_TASK_PARTS);
|
||||
return std::stoi(s.substr(secondCharacter + SPACE_BETWEEN_TASK_PARTS, WHEN_REPEAT_LENGTH));
|
||||
}
|
||||
|
||||
Task stringToTask(const std::string s, int ¤tTaskNumber)
|
||||
{
|
||||
Task outputTask;
|
||||
outputTask.title = stringToTaskTitle(s);
|
||||
//dividedTasks.at(i).time = stringToTime(s);
|
||||
outputTask.date = stringToStringDate(s);
|
||||
outputTask.realDate = stringToRealDate(outputTask.date);
|
||||
outputTask.whenRepeat = stringToWhenRepeat(s);
|
||||
outputTask.number = currentTaskNumber;
|
||||
currentTaskNumber++;
|
||||
return outputTask;
|
||||
}
|
||||
|
||||
std::vector <Task> getDividedTasks(const std::vector <std::string> fileLines)
|
||||
{
|
||||
std::vector <Task> dividedTasks(fileLines.size());
|
||||
int currentTaskNumber = 0;
|
||||
for(unsigned int i = 0; i < fileLines.size(); i++)
|
||||
{
|
||||
std::string currentLine = fileLines.at(i);
|
||||
dividedTasks.at(i) = stringToTask(currentLine, currentTaskNumber);
|
||||
}
|
||||
return dividedTasks;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
std::vector <Time> getTime(std::vector <Task> dividedTasks)
|
||||
{
|
||||
std::vector <Time> dividedTimes(dividedTasks.size());
|
||||
for(unsigned int i = 0; i < dividedTasks.size(); i++)
|
||||
{
|
||||
std::string hourS = dividedTasks.at(i).time.substr(0, 2);
|
||||
std::string minuteS = dividedTasks.at(i).time.substr(3, 2);
|
||||
dividedTimes.at(i).hour = std::stoi(hourS);
|
||||
dividedTimes.at(i).minute = std::stoi(minuteS);
|
||||
}
|
||||
return dividedTimes;
|
||||
}*/
|
||||
|
||||
std::vector <Date> getDate(const std::vector <Task> dividedTasks)
|
||||
{
|
||||
std::vector <Date> dividedDates(dividedTasks.size());
|
||||
for(unsigned int i = 0; i < dividedTasks.size(); i++)
|
||||
{
|
||||
dividedDates.at(i) = stringToRealDate(dividedTasks.at(i).date);
|
||||
}
|
||||
return dividedDates;
|
||||
}
|
||||
|
||||
std::vector <std::string> getTitlesFromTask(const std::vector <Task> tasks)
|
||||
{
|
||||
std::vector <std::string> titles;
|
||||
for(unsigned int i = 0; i < tasks.size(); i++)
|
||||
{
|
||||
titles.push_back(tasks.at(i).title);
|
||||
}
|
||||
return titles;
|
||||
}
|
||||
|
||||
int getDaysFromMonth(const monthChecker month)
|
||||
{
|
||||
if(month.isFebruary)
|
||||
{
|
||||
if(!month.isLeap) return DAYS_FEBRUARY_NOT_LEAP;
|
||||
else return DAYS_FEBRUARY_LEAP;
|
||||
}
|
||||
|
||||
if(!month.isLongMonth) return DAYS_IN_SHORT_MONTH;
|
||||
else return DAYS_IN_LONG_MONTH;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getDaysFromNormalDate(const Date realDate)
|
||||
{
|
||||
return getDaysFromMonth(monthProperties(realDate.month, realDate.year));
|
||||
}
|
||||
|
||||
#include "check.cpp"
|
||||
|
||||
std::vector <Task> getTasksToday(const std::vector <Task> dividedTasks)
|
||||
{
|
||||
std::vector <Task> tasksToday;
|
||||
std::vector <Date> dividedDates = getDate(dividedTasks);
|
||||
for(unsigned int i = 0; i < dividedTasks.size(); i++)
|
||||
{
|
||||
if(taskForToday(dividedDates.at(i)))
|
||||
{
|
||||
tasksToday.push_back(dividedTasks.at(i));
|
||||
tasksToday.at(tasksToday.size() - 1).show = 1;
|
||||
}
|
||||
}
|
||||
return tasksToday;
|
||||
}
|
||||
|
||||
#endif
|
||||
105
input.cpp
Normal file
105
input.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef INPUT_CPP
|
||||
#define INPUT_CPP
|
||||
|
||||
#include <iostream>
|
||||
#include "dataStructures.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "allFunctions.hpp"
|
||||
|
||||
std::string inputTaskTitle(const int whatToCheck)
|
||||
{
|
||||
std::string input;
|
||||
system(CLEAR_SCREEN_WINDOWS);
|
||||
do
|
||||
{
|
||||
print(INPUT_INFO.at(whatToCheck));
|
||||
getline(std::cin, input);
|
||||
}while(!validAddTaskInput(input, whatToCheck));
|
||||
return input;
|
||||
}
|
||||
|
||||
Date inputTaskDate(const int whatToCheck)
|
||||
{
|
||||
std::string input;
|
||||
system(CLEAR_SCREEN_WINDOWS);
|
||||
do
|
||||
{
|
||||
print(INPUT_INFO.at(whatToCheck));
|
||||
getline(std::cin, input);
|
||||
}while(!validAddTaskInput(input, whatToCheck));
|
||||
return stringToRealDate(input);
|
||||
}
|
||||
|
||||
int inputTaskWhenRepeat(const int whatToCheck)
|
||||
{
|
||||
std::string input;
|
||||
system(CLEAR_SCREEN_WINDOWS);
|
||||
do
|
||||
{
|
||||
print(INPUT_INFO.at(whatToCheck));
|
||||
getline(std::cin, input);
|
||||
}while(!validAddTaskInput(input, whatToCheck));
|
||||
return std::stoi(input);
|
||||
}
|
||||
|
||||
Task inputTask()
|
||||
{
|
||||
Task fullTask;
|
||||
fullTask.title = inputTaskTitle(CHECK_TITLE);
|
||||
// fullTask.time = inputTaskOneLine(CHECK_TIME);
|
||||
fullTask.realDate = inputTaskDate(CHECK_DATE);
|
||||
fullTask.date = normalDateToString(fullTask.realDate);
|
||||
fullTask.whenRepeat = inputTaskWhenRepeat(CHECK_WHEN_REPEAT);
|
||||
return fullTask;
|
||||
}
|
||||
|
||||
int whenRepeatTask()
|
||||
{
|
||||
std::string choiceS;
|
||||
do{
|
||||
print(WHEN_REPEAT_MENU);
|
||||
getline(std::cin, choiceS);
|
||||
}while(!checkRepeat(choiceS));
|
||||
return charToInt(choiceS.at(0));
|
||||
}
|
||||
|
||||
/*
|
||||
repeatTask inputRepeatingTask()
|
||||
{
|
||||
repeatTask fullTask;
|
||||
fullTask.title = inputTaskOneLine(CHECK_TITLE);
|
||||
fullTask.whenRepeat = whenRepeatTask();
|
||||
fullTask.lastCompleted.day = 1;
|
||||
fullTask.lastCompleted.month = 1;
|
||||
fullTask.lastCompleted.year = 2020;
|
||||
return fullTask;
|
||||
} */
|
||||
|
||||
|
||||
int inputMenu()
|
||||
{
|
||||
std::string choiceS;
|
||||
do{
|
||||
system(CLEAR_SCREEN_WINDOWS);
|
||||
print(MENU);
|
||||
getline(std::cin, choiceS);
|
||||
}while(!checkMenu(choiceS));
|
||||
return charToInt(choiceS.at(0));;
|
||||
}
|
||||
|
||||
void continueProgram(const int &userChoice)
|
||||
{
|
||||
if(userChoice == CHECK_TODAY) checkToday();
|
||||
else if(userChoice == ADD_TASK) fileAddTask(inputTask());
|
||||
else print("No such choice available");
|
||||
}
|
||||
|
||||
bool menuLoop()
|
||||
{
|
||||
int userChoice = inputMenu();
|
||||
if(userChoice == QUIT) return 1;
|
||||
else continueProgram(userChoice);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
32
main.cpp
Normal file
32
main.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef TO_DO_CPP
|
||||
#define TO_DO_CPP
|
||||
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <windows.h>
|
||||
#include <conio.h>
|
||||
#include "dataStructures.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "allfunctions.hpp"
|
||||
#include "basic.cpp"
|
||||
#include "valid.cpp"
|
||||
#include "check.cpp"
|
||||
#include "getters.cpp"
|
||||
#include "file.cpp"
|
||||
#include "output.cpp"
|
||||
#include "input.cpp"
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
bool end = 0;
|
||||
while(!end) { end = menuLoop(); };
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
163
output.cpp
Normal file
163
output.cpp
Normal file
@ -0,0 +1,163 @@
|
||||
#ifndef OUTPUT_CPP
|
||||
#define OUTPUT_CPP
|
||||
#include <conio.h>
|
||||
#include "allFunctions.hpp"
|
||||
#include "datastructures.hpp"
|
||||
|
||||
|
||||
void readTasksToday(const std::vector <Task> dividedTasks)
|
||||
{
|
||||
std::vector <Date> dividedDates = getDate(dividedTasks);
|
||||
for(unsigned int i = 0; i < dividedTasks.size(); i++)
|
||||
{
|
||||
if(taskForToday(dividedDates.at(i))) print(dividedTasks.at(i).title);
|
||||
}
|
||||
}
|
||||
|
||||
void printInfoAndTitlesColor(const std::string userInfo, const std::vector <Task> tasksToday, const int currentTask)
|
||||
{
|
||||
system(CLEAR_SCREEN_WINDOWS);
|
||||
print(userInfo);
|
||||
printOneStringColor(tasksToday, currentTask);
|
||||
}
|
||||
|
||||
std::vector <Task> getTasksTodayFromNothing()
|
||||
{
|
||||
std::vector <std::string> fileList = readList();
|
||||
std::vector <Task> dividedTasks = getDividedTasks(fileList);
|
||||
std::vector <Task> tasksToday = getTasksToday(dividedTasks);
|
||||
return tasksToday;
|
||||
}
|
||||
|
||||
int up(int currentTask, const int maxTasks, const std::vector <Task> tasksToday)
|
||||
{
|
||||
if(currentTask - 1 >= MIN_TASKS) currentTask--;
|
||||
else currentTask = maxTasks;
|
||||
printInfoAndTitlesColor(CHECK_TODAY_INFO, tasksToday, currentTask);
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
int down(int currentTask, const int maxTasks, const std::vector <Task> tasksToday)
|
||||
{
|
||||
if(currentTask + 1 <= maxTasks) currentTask++;
|
||||
else currentTask = MIN_TASKS;
|
||||
printInfoAndTitlesColor(CHECK_TODAY_INFO, tasksToday, currentTask);
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
Task modifyRepeatNever(Task ¤tTask)
|
||||
{
|
||||
currentTask.completed = !currentTask.completed;
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
|
||||
Task modifyRepeatYear(Task ¤tTask)
|
||||
{
|
||||
currentTask.realDate.year++;
|
||||
currentTask.date = normalDateToString(currentTask.realDate);
|
||||
currentTask.show = 0;
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
Task modifyRepeatMonth(Task ¤tTask)
|
||||
{
|
||||
if(currentTask.realDate.month == DECEMBER)
|
||||
{
|
||||
modifyRepeatYear(currentTask);
|
||||
currentTask.realDate.month = JANUARY;
|
||||
}
|
||||
else currentTask.realDate.month++;
|
||||
currentTask.date = normalDateToString(currentTask.realDate);
|
||||
currentTask.show = 0;
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
Task modifyRepeatWeek(Task ¤tTask)
|
||||
{
|
||||
if(currentTask.realDate.day + DAYS_IN_WEEK > getDaysFromNormalDate(currentTask.realDate))
|
||||
{
|
||||
currentTask.realDate.day = DAYS_IN_WEEK - (getDaysFromNormalDate(currentTask.realDate) - currentTask.realDate.day);
|
||||
modifyRepeatMonth(currentTask);
|
||||
currentTask.date = normalDateToString(currentTask.realDate);
|
||||
}else
|
||||
{
|
||||
currentTask.realDate.day += DAYS_IN_WEEK;
|
||||
currentTask.date = normalDateToString(currentTask.realDate);
|
||||
}
|
||||
currentTask.show = 0;
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
Task modifyRepeatDay(Task ¤tTask)
|
||||
{
|
||||
if(currentTask.realDate.day + 1 > getDaysFromNormalDate(currentTask.realDate))
|
||||
{
|
||||
modifyRepeatMonth(currentTask);
|
||||
currentTask.realDate.day = 1;
|
||||
currentTask.date = normalDateToString(currentTask.realDate);
|
||||
}else
|
||||
{
|
||||
currentTask.realDate.day++;
|
||||
currentTask.date = normalDateToString(currentTask.realDate);
|
||||
}
|
||||
currentTask.show = 0;
|
||||
return currentTask;
|
||||
}
|
||||
|
||||
|
||||
Task modifyDate(Task ¤tTask)
|
||||
{
|
||||
if(currentTask.whenRepeat == NEVER_REPEAT) return modifyRepeatNever(currentTask);
|
||||
else if(currentTask.whenRepeat == EVERY_DAY) return modifyRepeatDay(currentTask);
|
||||
else if(currentTask.whenRepeat == EVERY_WEEK) return modifyRepeatWeek(currentTask);
|
||||
else if(currentTask.whenRepeat == EVERY_MONTH) return modifyRepeatMonth(currentTask);
|
||||
else if(currentTask.whenRepeat == EVERY_YEAR) return modifyRepeatYear(currentTask);
|
||||
else return currentTask;
|
||||
}
|
||||
|
||||
std::vector <Task> space(const int currentTask, std::vector <Task> &tasksToday)
|
||||
{
|
||||
if(tasksToday.size() == 0) return tasksToday;
|
||||
modifyDate(tasksToday.at(currentTask));
|
||||
printInfoAndTitlesColor(CHECK_TODAY_INFO, tasksToday, currentTask);
|
||||
return tasksToday;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector <Task> moveThroughTaskList(std::vector <Task> &tasksToday)
|
||||
{
|
||||
int maxTasks = tasksToday.size() - 1;
|
||||
int currentTask = MIN_TASKS;
|
||||
int c = 0;
|
||||
while(c != ESCAPE)
|
||||
{
|
||||
c = 0;
|
||||
switch((c=getch()))
|
||||
{
|
||||
case KEY_UP:
|
||||
currentTask = up(currentTask, maxTasks, tasksToday);
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
currentTask = down(currentTask, maxTasks, tasksToday);
|
||||
break;
|
||||
case SPACE:
|
||||
tasksToday = space(currentTask, tasksToday);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return tasksToday;
|
||||
}
|
||||
|
||||
std::vector <std::string> detectKeys()
|
||||
{
|
||||
std::vector <Task> tasksToday = getTasksTodayFromNothing();
|
||||
printInfoAndTitlesColor(CHECK_TODAY_INFO, tasksToday, MIN_TASKS);
|
||||
tasksToday = moveThroughTaskList(tasksToday);
|
||||
return removeCompleted(readList(), tasksToday);
|
||||
}
|
||||
|
||||
void checkToday() { outputFile(detectKeys()); }
|
||||
|
||||
#endif
|
||||
63
valid.cpp
Normal file
63
valid.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#ifndef VALID_HPP
|
||||
#define VALID_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include "dataStructures.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "allFunctions.hpp"
|
||||
|
||||
bool validString(const std::string s)
|
||||
{
|
||||
for(unsigned int i = 0; i < s.length(); i++)
|
||||
{
|
||||
if(!charIsNumber(s.at(i)))
|
||||
{
|
||||
printErrorStringContainsNotNumber(s);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool validNumberInput(const std::string input, const int min, const int max)
|
||||
{
|
||||
if(!validString(input)) return 0;
|
||||
int inputInt = std::stoi(input);
|
||||
if(numberTooLow(inputInt, min)) return 0;
|
||||
if(numberTooHigh(inputInt, max)) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool validStringLength(const std::string s, const int desiredLength)
|
||||
{
|
||||
int stringLength = s.length();
|
||||
if(stringLength != desiredLength)
|
||||
{
|
||||
printNotValidStringLength(s, desiredLength);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool validCharacter(const char inputC, const char desiredC)
|
||||
{
|
||||
if(inputC != desiredC)
|
||||
{
|
||||
printInvalidCharacter(inputC, desiredC);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool validAddTaskInput(const std::string input, const int inputType)
|
||||
{
|
||||
if(inputType == CHECK_TITLE) return checkTitle(input);
|
||||
//if(inputType == CHECK_TIME) return checkTime(input);
|
||||
if(inputType == CHECK_DATE) return checkDate(input);
|
||||
if(inputType == CHECK_WHEN_REPEAT) return checkWhenRepeat(input);
|
||||
else return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Reference in New Issue
Block a user