Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Institute of Technical Acoustics (ITA)
VACore
Commits
cdc51ec1
Commit
cdc51ec1
authored
Nov 28, 2017
by
Dipl.-Ing. Jonas Stienen
Browse files
Refactoring and adding feature to store a struct to INI file (e.g. VACore.ini
parent
200f97d2
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/VACoreFactory.h
View file @
cdc51ec1
...
...
@@ -34,13 +34,20 @@ namespace VACore
* @return Pointer to the core instance (VA interface API from VABase)
*/
VACORE_API
IVAInterface
*
CreateCoreInstance
(
const
CVAStruct
&
oArgs
);
//! Parses input INI configuration file and converts it into a VA core config struct
/**
* @param[in] sConfigFilePath File path to core config (INI) file
* @return Core configuration
*/
VACORE_API
CVAStruct
GetCoreConfigFromFile
(
const
std
::
string
&
sConfigFilePath
);
* @param[in] sConfigFilePath File path to core config (INI) file
* @return Core configuration
*/
VACORE_API
CVAStruct
LoadCoreConfigFromFile
(
const
std
::
string
&
sConfigFilePath
);
//! Store configuration to INI file from VA core config struct
/**
* @param[in] oCoreConfig Core configuration struct
* @param[in] sConfigFilePath File path to core config (INI) file
*/
VACORE_API
void
StoreCoreConfigToFile
(
const
CVAStruct
&
oCoreConfig
,
const
std
::
string
&
sConfigFilePath
);
//! Factore method - create a VACore instance with configuration file
/**
...
...
@@ -51,7 +58,7 @@ namespace VACore
*/
inline
IVAInterface
*
CreateCoreInstance
(
const
std
::
string
&
sConfigFile
=
VACORE_DEFAULT_CONFIGFILE
)
{
return
CreateCoreInstance
(
VACore
::
Get
CoreConfigFromFile
(
sConfigFile
)
);
return
CreateCoreInstance
(
VACore
::
Load
CoreConfigFromFile
(
sConfigFile
)
);
};
//! Returns the filesystem path of the VACore shared lib (e.g. VACore.dll)
...
...
src/Utils/VAUtils.cpp
View file @
cdc51ec1
...
...
@@ -140,18 +140,18 @@ CVAStructValue interpretStructKey( const std::string& s )
return
CVAStructValue
(
s
);
}
void
readINIFileAsStruct
(
const
std
::
string
&
sFile
name
,
CVAStruct
&
oData
)
void
LoadStructFromINIFIle
(
const
std
::
string
&
sFile
Path
,
CVAStruct
&
oData
)
{
if
(
!
doesFileExist
(
sFile
name
)
)
VA_EXCEPT2
(
FILE_NOT_FOUND
,
std
::
string
(
"INI file
\"
"
)
+
sFile
name
+
std
::
string
(
"
\"
not found"
)
);
if
(
!
doesFileExist
(
sFile
Path
)
)
VA_EXCEPT2
(
FILE_NOT_FOUND
,
std
::
string
(
"INI file
\"
"
)
+
sFile
Path
+
std
::
string
(
"
\"
not found"
)
);
oData
.
Clear
();
std
::
vector
<
std
::
string
>
vsSections
=
INIFileGetSections
(
sFile
name
);
std
::
vector
<
std
::
string
>
vsSections
=
INIFileGetSections
(
sFile
Path
);
for
(
std
::
vector
<
std
::
string
>::
iterator
it
=
vsSections
.
begin
();
it
!=
vsSections
.
end
();
++
it
)
{
std
::
string
&
sSection
(
*
it
);
std
::
vector
<
std
::
string
>
vsKeys
=
INIFileGetKeys
(
sFile
name
,
sSection
);
std
::
vector
<
std
::
string
>
vsKeys
=
INIFileGetKeys
(
sFile
Path
,
sSection
);
// Spezialfall: Section [] nach Root abbilden
if
(
it
->
empty
()
)
...
...
@@ -160,8 +160,8 @@ void readINIFileAsStruct( const std::string& sFilename, CVAStruct& oData )
{
std
::
string
&
sKey
(
*
jt
);
if
(
oData
.
HasKey
(
sKey
)
)
VA_EXCEPT2
(
INVALID_PARAMETER
,
"Uniqueness violation in "
+
sFile
name
+
": multiple detection of key '"
+
sKey
+
"' in section '"
+
sSection
+
"'"
);
oData
[
sKey
]
=
interpretStructKey
(
INIFileReadString
(
sFile
name
,
sSection
,
sKey
)
);
VA_EXCEPT2
(
INVALID_PARAMETER
,
"Uniqueness violation in "
+
sFile
Path
+
": multiple detection of key '"
+
sKey
+
"' in section '"
+
sSection
+
"'"
);
oData
[
sKey
]
=
interpretStructKey
(
INIFileReadString
(
sFile
Path
,
sSection
,
sKey
)
);
}
}
else
...
...
@@ -171,14 +171,93 @@ void readINIFileAsStruct( const std::string& sFilename, CVAStruct& oData )
{
std
::
string
&
sKey
(
*
jt
);
if
(
oData
.
HasKey
(
sKey
)
)
VA_EXCEPT2
(
INVALID_PARAMETER
,
"Uniqueness violation in "
+
sFile
name
+
": multiple detection of key '"
+
sKey
+
"' in section '"
+
sSection
+
"'"
);
oSubData
[
*
jt
]
=
interpretStructKey
(
INIFileReadString
(
sFile
name
,
sSection
,
sKey
)
);
VA_EXCEPT2
(
INVALID_PARAMETER
,
"Uniqueness violation in "
+
sFile
Path
+
": multiple detection of key '"
+
sKey
+
"' in section '"
+
sSection
+
"'"
);
oSubData
[
*
jt
]
=
interpretStructKey
(
INIFileReadString
(
sFile
Path
,
sSection
,
sKey
)
);
}
oData
[
sSection
]
=
oSubData
;
}
}
}
void
StoreStructToINIFile
(
const
std
::
string
&
sFilePath
,
const
CVAStruct
&
oData
)
{
CVAStruct
::
const_iterator
cit
=
oData
.
Begin
();
while
(
cit
!=
oData
.
End
()
)
{
const
std
::
string
&
sKey
(
cit
->
first
);
const
CVAStructValue
&
oValue
(
cit
->
second
);
cit
++
;
// Root-level plain key-value pairs, a bit unusual though
switch
(
oValue
.
GetDatatype
()
)
{
case
CVAStructValue
::
BOOL
:
{
INIFileWriteBool
(
sKey
,
bool
(
oValue
)
);
break
;
}
case
CVAStructValue
::
INT
:
{
INIFileWriteInt
(
sKey
,
int
(
oValue
)
);
break
;
}
case
CVAStructValue
::
DOUBLE
:
{
INIFileWriteDouble
(
sKey
,
double
(
oValue
)
);
break
;
}
case
CVAStructValue
::
STRING
:
{
INIFileWriteString
(
sKey
,
std
::
string
(
oValue
)
);
break
;
}
case
CVAStructValue
::
STRUCT
:
{
const
std
::
string
&
sSection
(
sKey
);
const
CVAStruct
&
oSection
(
oValue
);
CVAStruct
::
const_iterator
cit_section
=
oSection
.
Begin
();
while
(
cit_section
!=
oSection
.
End
()
)
{
const
std
::
string
&
sKeyInSection
(
cit_section
->
first
);
const
CVAStructValue
&
oSectionValue
(
cit_section
->
second
);
cit_section
++
;
// Section-level key-value pairs
switch
(
oSectionValue
.
GetDatatype
()
)
{
case
CVAStructValue
::
BOOL
:
{
INIFileWriteBool
(
sFilePath
,
sSection
,
sKeyInSection
,
bool
(
oSectionValue
)
);
break
;
}
case
CVAStructValue
::
INT
:
{
INIFileWriteInt
(
sFilePath
,
sSection
,
sKeyInSection
,
int
(
oSectionValue
)
);
break
;
}
case
CVAStructValue
::
DOUBLE
:
{
INIFileWriteDouble
(
sFilePath
,
sSection
,
sKeyInSection
,
double
(
oSectionValue
)
);
break
;
}
case
CVAStructValue
::
STRING
:
{
INIFileWriteString
(
sFilePath
,
sSection
,
sKeyInSection
,
std
::
string
(
oSectionValue
)
);
break
;
}
}
}
break
;
}
}
}
}
double
GetAzimuthOnTarget_DEG
(
const
VAVec3
&
vOriginPos
,
const
VAVec3
&
vView
,
const
VAVec3
&
vUp
,
const
VAVec3
&
vTargetPos
)
{
VAVec3
vDir
=
vTargetPos
-
vOriginPos
;
...
...
src/Utils/VAUtils.h
View file @
cdc51ec1
...
...
@@ -59,8 +59,15 @@ double GetElevationOnTarget_DEG( const VAVec3& vOriginPos, const VAVec3& vView,
//! Ersetzt Backslashes (bzw. PATH_SEPARATOR) durch doppelte Backslashes (bzw. PATH_SEPARATOR)
std
::
string
correctPathForLUA
(
const
std
::
string
&
sPath
);
//! Lies eine INI-Datei ein und gibt sie als VAStruct zurck
void
readINIFileAsStruct
(
const
std
::
string
&
sFilename
,
CVAStruct
&
oData
);
//! Loads an INI file and converts it to a VA struct
void
LoadStructFromINIFIle
(
const
std
::
string
&
sFilePath
,
CVAStruct
&
oData
);
//! Will only write top level values and first level structs as sections with simple types
/**
* @param[in] sFilePath File path
* @param[in] oData Struct data
*/
void
StoreStructToINIFile
(
const
std
::
string
&
sFilePath
,
const
CVAStruct
&
oData
);
//! Sets all motion related parameters in a core event based on a motion event
void
SetCoreEventParams
(
CVAEvent
&
oEvent
,
const
CVAMotionState
*
pMotionState
);
...
...
src/VACoreImpl.cpp
View file @
cdc51ec1
...
...
@@ -185,7 +185,12 @@ IVAInterface* VACore::CreateCoreInstance( const CVAStruct& oArgs )
return
new
CVACoreImpl
(
oArgs
);
}
CVAStruct
VACore
::
GetCoreConfigFromFile
(
const
std
::
string
&
sConfigFilePath
)
void
VACore
::
StoreCoreConfigToFile
(
const
CVAStruct
&
oConfig
,
const
std
::
string
&
sConfigFilePath
)
{
StoreStructToINIFile
(
sConfigFilePath
,
oConfig
);
}
CVAStruct
VACore
::
LoadCoreConfigFromFile
(
const
std
::
string
&
sConfigFilePath
)
{
CVAStruct
oFinalCoreConfigStruct
,
oCurrentConfig
;
std
::
list
<
VistaFileSystemFile
>
voConfigFiles
;
...
...
@@ -220,7 +225,7 @@ CVAStruct VACore::GetCoreConfigFromFile( const std::string& sConfigFilePath )
}
VA_VERBOSE
(
"Config"
,
std
::
string
(
"Reading INI file '"
)
+
oCurrentConfigFile
.
GetLocalName
()
+
"'"
);
readINIFileAsStruct
(
oCurrentConfigFile
.
GetName
(),
oCurrentConfig
);
LoadStructFromINIFIle
(
oCurrentConfigFile
.
GetName
(),
oCurrentConfig
);
if
(
oCurrentConfig
.
HasKey
(
"paths"
)
)
{
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment