Timer Console
Loading...
Searching...
No Matches
Files Class Reference

Files class introduces an abstraction of the filesystem api, and json parsing. This class handles reading and writing to JSON configuration files for the persistent data (Alarms, Timers, Stopwatches) within the application. More...

#include <files.h>

Public Member Functions

 Files ()
 Files constructor takes in no parameters and executes no initializing logic.
 
std::vector< TimerDatagetTimers ()
 getTimers takes in no parameters. This method is made to fetch timers stored from a configuration file which is either existing or being created by the application and returns them to the caller of the method or an empty vector
 
void saveTimers (const std::vector< TimerData > &times)
 
std::vector< AlarmDatagetAlarms ()
 getAlarms takes in no parameters. This method is made to fetch alarms from a configuration file which is either existing or being created by the application and returns them to the caller of the method or an empty vector
 

Protected Member Functions

std::string getAppDataPath ()
 getAppDataPath returns the string that represents the file path which locates the configuration directory in storage for the application
 
nlohmann::json deserializeJson (std::ifstream &inFile)
 deserializeJson returns a valid JSON object
 
void saveJsonToFile (const std::string &fileName, json j)
 saveJsonToFile does as it says. It takes any json shape and saves it to a file found or created at the location provided in params
 

Detailed Description

Files class introduces an abstraction of the filesystem api, and json parsing. This class handles reading and writing to JSON configuration files for the persistent data (Alarms, Timers, Stopwatches) within the application.

Constructor & Destructor Documentation

◆ Files()

Files::Files ( )

Files constructor takes in no parameters and executes no initializing logic.

Member Function Documentation

◆ deserializeJson()

json Files::deserializeJson ( std::ifstream & inFile)
protected

deserializeJson returns a valid JSON object

Note
json being returned can take any shape or form and must be checked by the caller
Parameters
inFileString reprisenting the path to the file which should be read from on the user's system

◆ getAlarms()

std::vector< AlarmData > Files::getAlarms ( )

getAlarms takes in no parameters. This method is made to fetch alarms from a configuration file which is either existing or being created by the application and returns them to the caller of the method or an empty vector

Returns
A vector of AlarmData structures.
See also
AlarmData

alarmFileData return type { "error": boolean // did the read fail or not
"alarms": [ // array of AlarmData types

See also
AlarmData { "dow": int[], "time": { "hour": int, "minute": int }, "on": boolean, "meridiem": "string", "vibrate": { "on": boolean, "intensity": double } }, ... ] }

◆ getAppDataPath()

std::string Files::getAppDataPath ( )
inlineprotected

getAppDataPath returns the string that represents the file path which locates the configuration directory in storage for the application

Note
This directory will be created if there is none in first search

◆ getTimers()

std::vector< TimerData > Files::getTimers ( )

getTimers takes in no parameters. This method is made to fetch timers stored from a configuration file which is either existing or being created by the application and returns them to the caller of the method or an empty vector

Returns
A vector of TimerData structures.
See also
TimerData

timerFileData json data structure { "error": boolean, "timers": [ // array of TimerData data.

See also
TimerData { "hours": int, "minutes": int, "seconds": int, "running": boolean, "paused": boolean }, ... ] }

◆ saveJsonToFile()

void Files::saveJsonToFile ( const std::string & fileName,
json j )
protected

saveJsonToFile does as it says. It takes any json shape and saves it to a file found or created at the location provided in params

Parameters
fileNamestring representing the path to the file in question
ja valid json object taking any shape to be saved to the file

◆ saveTimers()

void Files::saveTimers ( const std::vector< TimerData > & times)

The documentation for this class was generated from the following files: