Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cuteLib-hsrt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Glaser
cuteLib-hsrt
Commits
da6392dd
Commit
da6392dd
authored
2 months ago
by
tobiglaser
Browse files
Options
Downloads
Patches
Plain Diff
added Doxygen comments
parent
949b618d
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/algoThread.h
+22
-2
22 additions, 2 deletions
src/algoThread.h
src/configPanel.h
+19
-15
19 additions, 15 deletions
src/configPanel.h
src/csvParser.h
+53
-8
53 additions, 8 deletions
src/csvParser.h
src/csvWriter.h
+18
-1
18 additions, 1 deletion
src/csvWriter.h
src/cute.cpp
+16
-3
16 additions, 3 deletions
src/cute.cpp
with
128 additions
and
29 deletions
src/algoThread.h
+
22
−
2
View file @
da6392dd
...
...
@@ -5,14 +5,34 @@
#include
<QThread>
/**
* @brief A QThread, specialized to run the user provided algorithm.
* QThread allows Control and CuteControl to communicate with Qt signals across the threads.
* CuteControl has to be pushed/moved to the event loop of this thread for that to work.
* It is pushed/moved back to the main thread before this thread ends.
*/
class
AlgoThread
:
public
QThread
{
private:
void
(
*
func
)();
void
(
*
func
)();
///< Pointer to the function, that will be executed by the Thread.
public:
/**
* @brief Set the function pointer to be executed in run().
*
* @param algorithm
*/
void
setAlgorithm
(
void
(
*
algorithm
)())
{
func
=
algorithm
;
}
/**
* For some cute functions it is necessary that the thread can receive signals from the main thread.
* E.g. cute::ok() and cute::verbosity().
* For this to work, the CuteControl, has to be "moved to" to the event loop of this thread.
* This moving can only be done via pushing, not pulling.
* Thus, before the thread ends, the CuteControl must be pushed back to the main thread
*
* @brief Executed by QThread::start(). Executes the provided function and moves the CuteControl back to the main
* thread.
*/
void
run
()
override
{
func
();
...
...
This diff is collapsed.
Click to expand it.
src/configPanel.h
+
19
−
15
View file @
da6392dd
...
...
@@ -9,26 +9,30 @@
#include
<QSpinBox>
#include
<QStackedWidget>
/**
* @brief Responsible for controlling the users Algorithms and generating the Problem.
* This is a Dockwidget, so it could be moved around or locked in place.
*
*/
class
ConfigPanel
:
public
QDockWidget
{
Q_OBJECT
private:
std
::
vector
<
QPushButton
*>
lockButtons
;
std
::
vector
<
QPushButton
*>
lockButtons
;
///< Holds Buttons used to prohibit changing the generated Problem.
public:
QPushButton
*
runButton
;
QPushButton
*
openButton
;
QLineEdit
*
fileLine
;
QPlainTextEdit
*
pasteBox
;
QComboBox
*
algoBox
;
QSpinBox
*
problemSizeBox
;
QComboBox
*
verbosityBox
;
QStackedWidget
*
stackedWidget
;
QWidget
*
fileWidget
;
QWidget
*
randomWidget
;
QWidget
*
pasteWidget
;
QPushButton
*
runButton
;
///< Used to Start and Stop the Algorithm.
QPushButton
*
openButton
;
///< Used to Select a File via QFileDialog.
QLineEdit
*
fileLine
;
///< Shows path and filename and allows editing it.
QPlainTextEdit
*
pasteBox
;
///< Used to enter csv data via drag n drop or copy and paste.
QComboBox
*
algoBox
;
///< Used to select one of the Algorithms registered with cute::registerAlgorithm().
QSpinBox
*
problemSizeBox
;
///< Used to adjust the number of randomly generated Points.
QComboBox
*
verbosityBox
;
///< Used to set the verbosity, the users code should exhibit.
QStackedWidget
*
stackedWidget
;
///< Holds the different problem generation Widgets.
QWidget
*
fileWidget
;
///< Holds Widgets to read a Problem from a File.
QWidget
*
randomWidget
;
///< Holds Widgets to generate random Problems.
QWidget
*
pasteWidget
;
///< Holds Widgets to read Problem from dragged or pasted Text.
public:
explicit
ConfigPanel
(
QWidget
*
parent
=
nullptr
);
...
...
@@ -42,8 +46,8 @@ public slots:
void
setGenUnlocked
();
signals:
void
previewButtonClicked
();
void
lockButtonClicked
();
void
previewButtonClicked
();
///< Signal emitted, when one of the Preview Buttons was clicked.
void
lockButtonClicked
();
///< Signal emitted, when one of the Lock/Unlock buttons was clicked.
};
#endif // CONFIGPANEL_H
This diff is collapsed.
Click to expand it.
src/csvParser.h
+
53
−
8
View file @
da6392dd
...
...
@@ -24,10 +24,26 @@ Below is the complete, self-contained code:
#include
<limits>
#include
<cmath>
// For std::isnan
/**
* @brief Kindly provided by Copilot, this can parse a .csv File into std::strings and further into floats.
*
*/
class
CSVParser
{
public:
/**
* @brief Construct a new CSVParser object
*
* @param delimiter Char that seperates the values. Default: COMMA Seperated Values
*/
CSVParser
(
char
delimiter
=
','
)
:
delimiter
(
delimiter
)
{}
/**
* @brief Opens a filestream and passes it to parseStream() to do the actual parsing.
*
* @param filename The /path/to/file.csv to parse.
* @return false if the File could not be opened.
* @return true otherwise.
*/
bool
parseFile
(
const
std
::
string
&
filename
)
{
std
::
ifstream
file
(
filename
);
if
(
!
file
.
is_open
())
{
...
...
@@ -39,18 +55,32 @@ public:
return
true
;
}
/**
* @brief Creates a stringstream from the input string and passes it to parseStream() to do the actual parsing.
*
* @param rawInput The string to be parsed.
*/
void
parseString
(
const
std
::
string
&
rawInput
)
{
std
::
istringstream
input
(
rawInput
);
parseStream
(
input
);
}
// Returns the parsed CSV data as a vector of rows containing strings.
/**
* @brief Get the whole parsed CSV data as strings.
*
* @return The parsed CSV data as a vector of rows containing strings.
*/
const
std
::
vector
<
std
::
vector
<
std
::
string
>>&
getRows
()
const
{
return
rows
;
}
// Converts each field from the CSV to a float.
// Fields that cannot be converted are represented by NaN (Not a Number).
/**
* @brief Converts each field from the already parsed CSV to a float.
* Fields that cannot be converted are represented by NaN (Not a Number).
* parseString() or parseFile() have to be called before this function so that rows is populated.
*
* @return The parsed CSV data as a vector of rows containing floats. NaN for invalid fields.
*/
std
::
vector
<
std
::
vector
<
float
>>
getFloatRows
()
const
{
std
::
vector
<
std
::
vector
<
float
>>
floatRows
;
for
(
const
auto
&
row
:
rows
)
{
...
...
@@ -73,9 +103,14 @@ public:
}
private
:
char
delimiter
;
std
::
vector
<
std
::
vector
<
std
::
string
>>
rows
;
char
delimiter
;
///< Char that separates the values.
std
::
vector
<
std
::
vector
<
std
::
string
>>
rows
;
///< Holds the strings, parsed from the file.
/**
* @brief Splits the stream into lines, passes them to parseLine() and stores the result in rows.
*
* @param input The stream to be parsed.
*/
void
parseStream
(
std
::
istream
&
input
)
{
rows
.
clear
();
// Ensure that rows is empty before starting.
...
...
@@ -86,8 +121,13 @@ private:
}
}
// Helper function that parses a single line of CSV.
// It supports quoted fields and the basic escaping of quotes by doubling ("").
/**
* @brief Helper function that parses a single line of CSV.
* It supports quoted fields and the basic escaping of quotes by doubling ("").
*
* @param line The line to be parsed.
* @return A vector of the parsed values as strings.
*/
std
::
vector
<
std
::
string
>
parseLine
(
const
std
::
string
&
line
)
{
std
::
vector
<
std
::
string
>
tokens
;
std
::
string
token
;
...
...
@@ -127,6 +167,11 @@ private:
}
};
#ifdef TESTING_CSV
/**
* @brief Only used to test the CSVParser.
*
* @return 0
*/
int
main
()
{
// Create an instance of CSVParser with skipHeader enabled.
// Replace "example.csv" with your CSV file.
...
...
This diff is collapsed.
Click to expand it.
src/csvWriter.h
+
18
−
1
View file @
da6392dd
...
...
@@ -6,21 +6,38 @@
#include
<fstream>
#include
<string>
/**
* @brief Complement to CSVParser, this class can write Points to a .csv File.
*
*/
class
csvWriter
{
private:
std
::
string
_path
;
std
::
string
_path
;
///< /path/to/file.csv to be written.
public:
csvWriter
(
std
::
string
path
);
bool
write
(
const
std
::
vector
<
cute
::
Point
>&
points
);
};
/**
* @brief Construct a new csvWriter object
*
* @param path The /path/to/file.csv to be written.
*/
csvWriter
::
csvWriter
(
std
::
string
path
)
{
_path
=
path
;
}
/**
* @brief Writes a line representing "{x}, {y}\n" for each Point.
* Uses default settings to convert the floats to strings.
*
* @param points The data to be written.
* @return true if no error occured.
* @return false if an erron occured.
*/
bool
csvWriter
::
write
(
const
std
::
vector
<
cute
::
Point
>&
points
)
{
std
::
ofstream
outFile
(
_path
);
...
...
This diff is collapsed.
Click to expand it.
src/cute.cpp
+
16
−
3
View file @
da6392dd
...
...
@@ -5,8 +5,20 @@
#include
<chrono>
/**
* @brief This namespace allows the Timer functions to have a state without a class/object representation.
* Since it is defined in cute.cpp,
* it is only visible in this translation unit and thus hidden from the cute User.
*/
namespace
timer
{
/**
* Each cute function pauses and resumes the timer automatically.
* The user can also pause and resume the Timer manually for a more accurate result.
* internallyPaused is used to not automatically resume a manually paused Timer.
*
* @brief Represents the different states the Timer can be in.
*/
enum
State
{
off
,
...
...
@@ -14,9 +26,10 @@ namespace timer
paused
,
internallyPaused
};
std
::
chrono
::
time_point
<
std
::
chrono
::
high_resolution_clock
,
std
::
chrono
::
high_resolution_clock
::
duration
>
start
;
std
::
chrono
::
microseconds
duration
;
State
state
;
std
::
chrono
::
time_point
<
std
::
chrono
::
high_resolution_clock
,
std
::
chrono
::
high_resolution_clock
::
duration
>
start
;
///< Point in Time the Timer was last started or resumed.
std
::
chrono
::
microseconds
duration
;
///< Accumulated duration that the Timer has run, updated by cute::TimerPause().
State
state
;
///< The current state of the Timer.
}
//namespace timer
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment