Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
GameDevWeek
Sommersemester 2015
Cpp
Deth Buff Arr
Commits
60d668e1
Commit
60d668e1
authored
Sep 30, 2015
by
Michael Ochmann
Browse files
much better fsi::standardlibrary; 'explode' has now alias 'split'
parent
0a9c2b6b
Changes
1
Hide whitespace changes
Inline
Side-by-side
include/util/fsi.hpp
View file @
60d668e1
...
...
@@ -7,6 +7,16 @@
namespace
gdw
{
namespace
fsi
{
/**
* Explodes a string a the given character and returns a std::vector of strings.
*
* @param str Input string.
* @param delimiter a char on which 'str' should be exploded
* @return a glm::vec4 containing std::strings of the exploded string.
*
* @author Michael Ochmann
* @version 1.0.0
*/
static
std
::
vector
<
std
::
string
>
explode
(
const
std
::
string
&
str
,
char
delimiter
)
{
std
::
vector
<
std
::
string
>
tokens
;
std
::
stringstream
inStream
(
str
);
...
...
@@ -17,39 +27,75 @@ namespace gdw {
return
tokens
;
}
/**
* This is an alias for fsi::explode (just for the java guys)
*
* @see fsi::explode
*/
static
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
str
,
char
delimiter
)
{
return
fsi
::
explode
(
str
,
delimiter
);
}
/**
* Converts a string containing a hex-colorvalue into a glm::vec4 color.
*
* @param hexString is a string containing a hex rgba-colorvalue "000000FF".
* @return a glm::vec4 with the color.
*
* @author Michael Ochmann
* @version 1.0.0
*/
static
glm
::
vec4
hexToVec4
(
std
::
string
hexString
)
{
std
::
stringstream
sR
,
sG
,
sB
,
sA
;
std
::
stringstream
tempStream
;
int
r
,
g
,
b
,
a
;
sR
<<
hexString
.
substr
(
0
,
2
);
sG
<<
hexString
.
substr
(
2
,
2
);
sB
<<
hexString
.
substr
(
4
,
2
);
sA
<<
hexString
.
substr
(
6
,
2
);
sR
>>
std
::
hex
>>
r
;
sG
>>
std
::
hex
>>
g
;
sB
>>
std
::
hex
>>
b
;
sA
>>
std
::
hex
>>
a
;
tempStream
<<
hexString
.
substr
(
0
,
2
);
tempStream
>>
std
::
hex
>>
r
;
tempStream
.
clear
();
tempStream
<<
hexString
.
substr
(
2
,
2
);
tempStream
>>
std
::
hex
>>
g
;
tempStream
.
clear
();
tempStream
<<
hexString
.
substr
(
4
,
2
);
tempStream
>>
std
::
hex
>>
b
;
tempStream
.
clear
();
tempStream
<<
hexString
.
substr
(
6
,
2
);
tempStream
>>
std
::
hex
>>
a
;
tempStream
.
clear
();
return
glm
::
vec4
(
r
/
255.0
f
,
g
/
255.0
f
,
b
/
255.0
f
,
a
/
255.0
f
);
}
/**
* Contains the blue color of faculty computer science.
*/
const
glm
::
vec4
color
=
fsi
::
hexToVec4
(
"005196"
);
static
std
::
string
secondsToTimestamp
(
float
secondsFloat
,
bool
millis
=
false
)
{
/**
* This function converts a float value of seconds to a std::string with format HH:MM:SS:MMM. If second,
* optional parameter "printMillis" is set to true, milliseconds are returned, too.
*
* @param secondsFloat is a float value of seconds.
* @param printMillis defines, if the returned string contains milliseconds or not. Default is false.
* @return a std::string in the format HH:MM:SS[:MMM]
*
* @author Michael Ochmann
* @version 2.0.0
*/
static
std
::
string
secondsToTimestamp
(
float
secondsFloat
,
bool
printMillis
=
false
)
{
int
hours
=
(
int
)
floor
(
secondsFloat
/
60
/
60
);
int
minutes
=
(
int
)
floor
(
secondsFloat
/
60
)
%
60
;
int
seconds
=
(
int
)
floor
(
secondsFloat
)
%
60
;
int
milliseconds
=
(
int
)(
secondsFloat
*
1000
)
%
1000
;
std
::
string
hoursS
=
hours
<
10
?
"0"
+
std
::
to_string
(
hours
)
:
std
::
to_string
(
hours
);
std
::
string
minutesS
=
minutes
<
10
?
"0"
+
std
::
to_string
(
minutes
)
:
std
::
to_string
(
minutes
);
std
::
string
secondsS
=
seconds
<
10
?
"0"
+
std
::
to_string
(
seconds
)
:
std
::
to_string
(
seconds
);
std
::
string
millisecondsS
=
milliseconds
<
100
?
milliseconds
<
10
?
"00"
+
std
::
to_string
(
milliseconds
)
:
"0"
+
std
::
to_string
(
milliseconds
)
:
std
::
to_string
(
milliseconds
);
std
::
string
millisOut
=
millis
?
":"
+
millisecondsS
:
""
;
return
hoursS
+
":"
+
minutesS
+
":"
+
secondsS
+
millisOut
;
std
::
string
hours_
(
""
,
2
),
minutes_
(
""
,
2
),
seconds_
(
""
,
2
),
milliseconds_
(
""
,
3
);
sprintf
(
&
hours_
[
0
],
"%02d"
,
hours
);
sprintf
(
&
minutes_
[
0
],
"%02d"
,
minutes
);
sprintf
(
&
seconds_
[
0
],
"%02d"
,
seconds
);
sprintf
(
&
milliseconds_
[
0
],
"%03d"
,
milliseconds
);
milliseconds_
=
printMillis
?
":"
+
milliseconds_
:
""
;
return
hours_
+
":"
+
minutes_
+
":"
+
seconds_
+
milliseconds_
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment