Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
partons
core
elementary-utils
Commits
e358c853
Commit
e358c853
authored
Feb 20, 2020
by
Pawel Sznajder
Browse files
add functions to check if a given property set via prop. file
parent
4044e1e3
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/ElementaryUtils/PropertiesManager.h
View file @
e358c853
...
...
@@ -42,6 +42,10 @@ public:
std
::
string
getString
(
const
std
::
string
&
section
,
const
std
::
string
&
key
);
std
::
string
getString
(
const
std
::
string
&
key
);
bool
checkIfAvailable
(
const
std
::
string
&
section
,
const
std
::
string
&
key
)
const
;
bool
checkIfAvailable
(
const
std
::
string
&
key
)
const
;
std
::
string
getPropertiesFilePath
()
const
;
private:
...
...
include/ElementaryUtils/parser/IniFileParser.h
View file @
e358c853
...
...
@@ -15,7 +15,6 @@
namespace
ElemUtils
{
/**
* @class IniFileParser
* @brief
...
...
@@ -39,9 +38,14 @@ public:
void
parse
(
const
std
::
string
&
configFilePath
);
std
::
map
<
std
::
string
,
std
::
string
>
getValues
();
std
::
string
getString
(
const
std
::
string
&
key
);
std
::
string
getString
(
const
std
::
string
&
section
,
const
std
::
string
&
key
);
bool
checkIfAvailable
(
const
std
::
string
&
section
,
const
std
::
string
&
key
)
const
;
bool
checkIfAvailable
(
const
std
::
string
&
key
)
const
;
const
std
::
string
&
getFilePath
()
const
;
private:
...
...
@@ -57,7 +61,7 @@ private:
void
analyseValue
(
const
std
::
string
&
fileLine
,
const
std
::
string
&
sectionName
);
std
::
string
makeKey
(
const
std
::
string
&
sectionName
,
const
std
::
string
&
key
);
const
std
::
string
&
key
)
const
;
};
}
// namespace ElemUtils
...
...
src/ElementaryUtils/PropertiesManager.cpp
View file @
e358c853
...
...
@@ -60,6 +60,20 @@ std::string PropertiesManager::getString(const std::string & key) {
return
m_iniFileParser
.
getString
(
key
);
}
// mutex.unlock()
bool
PropertiesManager
::
checkIfAvailable
(
const
std
::
string
&
section
,
const
std
::
string
&
key
)
const
{
sf
::
Lock
lock
(
m_mutex
);
// mutex.lock()
return
m_iniFileParser
.
checkIfAvailable
(
section
,
key
);
}
// mutex.unlock()
bool
PropertiesManager
::
checkIfAvailable
(
const
std
::
string
&
key
)
const
{
sf
::
Lock
lock
(
m_mutex
);
// mutex.lock()
return
m_iniFileParser
.
checkIfAvailable
(
key
);
}
// mutex.unlock()
}
// namespace ElemUtils
std
::
string
ElemUtils
::
PropertiesManager
::
getPropertiesFilePath
()
const
{
...
...
src/ElementaryUtils/parser/IniFileParser.cpp
View file @
e358c853
...
...
@@ -122,7 +122,7 @@ void IniFileParser::analyseValue(const std::string & fileLine,
}
std
::
string
IniFileParser
::
makeKey
(
const
std
::
string
&
sectionName
,
const
std
::
string
&
key
)
{
const
std
::
string
&
key
)
const
{
// if the section's name is empty then returns only the key
// else returns the section name concatenated with the value of the key
return
(
sectionName
==
StringUtils
::
EMPTY
)
?
...
...
@@ -151,6 +151,15 @@ std::string IniFileParser::getString(const std::string & section,
<<
"
\"
in file
\"
"
<<
m_filePath
<<
"
\"
"
);
}
bool
IniFileParser
::
checkIfAvailable
(
const
std
::
string
&
section
,
const
std
::
string
&
key
)
const
{
return
(
m_values
.
find
(
makeKey
(
section
,
key
))
!=
m_values
.
end
());
}
bool
IniFileParser
::
checkIfAvailable
(
const
std
::
string
&
key
)
const
{
return
(
m_values
.
find
(
makeKey
(
StringUtils
::
EMPTY
,
key
))
!=
m_values
.
end
());
}
std
::
map
<
std
::
string
,
std
::
string
>
IniFileParser
::
getValues
()
{
return
m_values
;
}
...
...
Write
Preview
Markdown
is supported
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