Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
qpong
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Armin Co
qpong
Commits
158d5aa7
Commit
158d5aa7
authored
5 years ago
by
Armin Co
Browse files
Options
Downloads
Patches
Plain Diff
Configuration for the game.
Initial commit.
parent
d7427642
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Config.cpp
+34
-0
34 additions, 0 deletions
src/Config.cpp
src/Config.hpp
+83
-0
83 additions, 0 deletions
src/Config.hpp
src/qpong.config
+1
-0
1 addition, 0 deletions
src/qpong.config
with
118 additions
and
0 deletions
src/Config.cpp
0 → 100644
+
34
−
0
View file @
158d5aa7
///
/// @file Config.cpp
/// @author Armin Co
///
#include
"Config.hpp"
#include
<iostream>
#include
<fstream>
Config
::
Config
(
std
::
string
filename
)
:
m_filename
{
filename
}
{
std
::
ifstream
file
(
m_filename
);
while
(
file
)
{
std
::
string
key
;
std
::
getline
(
file
,
key
,
'\n'
);
std
::
string
value
;
std
::
getline
(
file
,
value
,
'\n'
);
Setting
s
=
fromStr
(
key
);
if
(
s
!=
Setting
::
None
)
{
m_configs
[
s
]
=
value
;
}
else
{
std
::
cout
<<
"The setting
\"
"
<<
key
<<
"
\"
is unknown!"
<<
std
::
endl
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/Config.hpp
0 → 100644
+
83
−
0
View file @
158d5aa7
///
/// @file Config.hpp
/// @author Armin Co
/// @brief Load configuration form a file and make it available.
///
#ifndef QPONG_CONFIG_HPP
#define QPONG_CONFIG_HPP
#include
<string>
#include
<map>
#include
<vector>
enum
class
Setting
{
// Array configuration
ArrayWidth
,
ArrayHeight
,
// Initial particle settings
MomentumX
,
MomentumY
,
PosX
,
PosY
,
None
};
const
char
*
toStr
(
Setting
setting
)
{
switch
(
setting
)
{
case
Setting
::
ArrayHeight
:
return
"ArrayHeight"
;
break
;
case
Setting
::
ArrayWidth
:
return
"ArrayWidth"
;
break
;
case
Setting
::
MomentumX
:
return
"MomentumX"
;
break
;
case
Setting
::
MomentumY
:
return
"MomentumY"
;
break
;
case
Setting
::
PosX
:
return
"PosX"
;
break
;
case
Setting
::
PosY
:
return
"PosY"
;
break
;
case
Setting
::
None
:
return
"None"
;
break
;
}
}
Setting
fromStr
(
std
::
string
s
)
{
if
(
s
==
"ArrayWidth"
)
return
Setting
::
ArrayWidth
;
if
(
s
==
"ArrayHeight"
)
return
Setting
::
ArrayHeight
;
if
(
s
==
"MomentumX"
)
return
Setting
::
MomentumX
;
if
(
s
==
"MomentumY"
)
return
Setting
::
MomentumY
;
if
(
s
==
"PosX"
)
return
Setting
::
PosX
;
if
(
s
==
"PosY"
)
return
Setting
::
PosY
;
return
Setting
::
None
;
}
class
Config
{
public:
Config
(
std
::
string
filename
);
void
loadFrom
(
std
::
string
filename
);
void
saveTo
(
std
::
string
filename
);
std
::
string
&
getFilename
();
void
changeSetting
(
Setting
setting
,
std
::
string
&
value
);
std
::
string
&
getSetting
(
Setting
setting
);
private:
std
::
string
m_filename
;
std
::
map
<
Setting
,
std
::
string
>
m_configs
;
};
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/qpong.config
0 → 100644
+
1
−
0
View file @
158d5aa7
ArrayWidth
=
384
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