Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CxxClient
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TGenBase
CxxClient
Commits
625848cd
Commit
625848cd
authored
5 years ago
by
Evgeny Lavrik
Browse files
Options
Downloads
Patches
Plain Diff
Add merging json files
parent
c6918fe9
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TGenBaseClient/BaseClass.h
+19
-39
19 additions, 39 deletions
TGenBaseClient/BaseClass.h
TGenBaseClient/JsonFileClient.cxx
+32
-0
32 additions, 0 deletions
TGenBaseClient/JsonFileClient.cxx
TGenBaseClient/JsonFileClient.h
+2
-0
2 additions, 0 deletions
TGenBaseClient/JsonFileClient.h
with
53 additions
and
39 deletions
TGenBaseClient/BaseClass.h
+
19
−
39
View file @
625848cd
...
...
@@ -49,26 +49,6 @@ static std::string ClassName() {
return
result
.
substr
(
idx
+
2
,
result
.
size
()
-
idx
-
2
);
}
// static std::string FullClassName(void* object) {
// int status = -4;
// const char * name = typeid(*object).name();
// std::string result = abi::__cxa_demangle(name, nullptr, nullptr, &status);
// if (status != 0)
// return name;
// return result;
// }
// static std::string ClassName(void* object) {
// std::string result = FullClassName(object);
// auto idx = result.find("::");
// if (idx == std::string::npos)
// return result;
// return result.substr(idx + 2, result.size() - idx - 2);
// }
template
<
class
T
>
static
inline
T
*
FromJson
(
jsoncons
::
ojson
json
)
{
if
(
!
json
.
is_object
())
return
nullptr
;
...
...
@@ -100,7 +80,7 @@ class BaseClass
public:
virtual
std
::
string
FullClassName
()
{
int
status
=
-
4
;
const
char
*
name
=
typeid
(
*
this
).
name
();
const
char
*
name
=
typeid
(
*
this
).
name
();
std
::
string
result
=
abi
::
__cxa_demangle
(
name
,
nullptr
,
nullptr
,
&
status
);
if
(
status
!=
0
)
return
name
;
...
...
@@ -205,9 +185,9 @@ class BaseObject: public BaseClass {
return
TGenBase
::
FromJson
<
BaseObject
>
(
json
);
}
int
GetId
()
const
{
return
fId
;
};
virtual
int
GetId
()
const
{
return
fId
;
};
void
SetId
(
int
value
)
{
fId
=
value
;
};
virtual
void
SetId
(
int
value
)
{
fId
=
value
;
};
protected
:
int
fId
{
0
};
///< Object Id
...
...
@@ -227,15 +207,15 @@ class BaseCondition: public BaseClass {
#else
virtual
std
::
string
GetName
()
const
{
return
fName
;
};
#endif
std
::
map
<
std
::
string
,
std
::
string
>
GetMetadata
()
const
{
return
fMetadata
;
}
int
GetRunId
()
const
{
return
fRunId
;
}
int
GetVersion
()
const
{
return
fVersion
;
}
virtual
std
::
map
<
std
::
string
,
std
::
string
>
GetMetadata
()
const
{
return
fMetadata
;
}
virtual
int
GetRunId
()
const
{
return
fRunId
;
}
virtual
int
GetVersion
()
const
{
return
fVersion
;
}
void
SetName
(
std
::
string
value
)
{
fName
=
value
;
};
void
SetName
(
char
*
value
)
{
fName
=
value
;
};
void
SetMetadata
(
std
::
map
<
std
::
string
,
std
::
string
>
value
)
{
fMetadata
=
value
;
}
void
SetRunId
(
int
value
)
{
fRunId
=
value
;
}
void
SetVersion
(
int
value
)
{
fVersion
=
value
;
}
virtual
void
SetName
(
std
::
string
value
)
{
fName
=
value
;
};
virtual
void
SetName
(
char
*
value
)
{
fName
=
value
;
};
virtual
void
SetMetadata
(
std
::
map
<
std
::
string
,
std
::
string
>
value
)
{
fMetadata
=
value
;
}
virtual
void
SetRunId
(
int
value
)
{
fRunId
=
value
;
}
virtual
void
SetVersion
(
int
value
)
{
fVersion
=
value
;
}
protected
:
std
::
string
fName
{};
///< Parameter Name
...
...
@@ -253,8 +233,8 @@ class ParameterJsonWrapper: public BaseCondition {
return
TGenBase
::
FromJson
<
ParameterJsonWrapper
>
(
json
);
}
jsoncons
::
ojson
GetParameter
()
const
{
return
fParameter
;
}
void
SetParameter
(
jsoncons
::
ojson
value
)
{
fParameter
=
value
;
}
virtual
jsoncons
::
ojson
GetParameter
()
const
{
return
fParameter
;
}
virtual
void
SetParameter
(
jsoncons
::
ojson
value
)
{
fParameter
=
value
;
}
template
<
class
T
>
T
*
GetParameter
()
{
...
...
@@ -292,8 +272,8 @@ class ParameterJsonStringWrapper: public BaseCondition {
virtual
std
::
string
ClassName
()
{
return
"ParameterWrapper"
;
}
std
::
string
GetParameter
()
const
{
return
fParameter
;
}
void
SetParameter
(
std
::
string
value
)
{
fParameter
=
value
;
}
virtual
std
::
string
GetParameter
()
const
{
return
fParameter
;
}
virtual
void
SetParameter
(
std
::
string
value
)
{
fParameter
=
value
;
}
template
<
class
T
>
T
*
GetParameter
()
{
...
...
@@ -327,8 +307,8 @@ class ParameterWrapper: public BaseCondition {
return
TGenBase
::
FromJson
<
ParameterWrapper
>
(
json
);
}
std
::
string
GetParameter
()
const
{
return
fParameter
;
}
void
SetParameter
(
std
::
string
value
)
{
fParameter
=
value
;
}
virtual
std
::
string
GetParameter
()
const
{
return
fParameter
;
}
virtual
void
SetParameter
(
std
::
string
value
)
{
fParameter
=
value
;
}
template
<
class
T
>
T
*
GetParameter
()
{
...
...
@@ -389,8 +369,8 @@ class ParameterTemplate: public BaseCondition {
return
instance
;
}
P
*
GetParameter
()
const
{
return
fParameter
;
}
void
SetParameter
(
P
*
value
)
{
virtual
P
*
GetParameter
()
const
{
return
fParameter
;
}
virtual
void
SetParameter
(
P
*
value
)
{
if
(
fParameter
)
delete
fParameter
;
fParameter
=
new
P
(
*
value
);
}
...
...
This diff is collapsed.
Click to expand it.
TGenBaseClient/JsonFileClient.cxx
+
32
−
0
View file @
625848cd
...
...
@@ -59,6 +59,38 @@ void JsonFileClient::FlushFile() {
os
<<
jsoncons
::
pretty_print
(
fJson
,
options
);
}
void
JsonFileClient
::
MergeFiles
(
std
::
vector
<
std
::
string
>
files
,
std
::
string
outputFile
)
{
std
::
ofstream
os
(
outputFile
);
if
(
!
os
.
good
())
{
std
::
cout
<<
"Can not access output file "
<<
outputFile
<<
std
::
endl
;
return
;
}
jsoncons
::
ojson
result
=
jsoncons
::
ojson
::
object
();
for
(
auto
&
file
:
files
)
{
std
::
ifstream
is
(
file
.
c_str
());
if
(
!
is
.
good
())
{
std
::
cout
<<
"File "
<<
file
<<
" does not exist. "
"It will be skipped."
<<
std
::
endl
;
}
else
{
std
::
string
jsonString
((
std
::
istreambuf_iterator
<
char
>
(
is
)),
std
::
istreambuf_iterator
<
char
>
());
try
{
result
.
merge
(
jsoncons
::
ojson
::
parse
(
jsonString
));
}
catch
(
const
jsoncons
::
ser_error
&
e
)
{
std
::
cout
<<
"Can not read in the json file "
<<
file
<<
std
::
endl
;
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
}
}
}
jsoncons
::
json_options
options
;
options
.
indent_size
(
2
);
os
<<
jsoncons
::
pretty_print
(
result
,
options
);
}
void
JsonFileClient
::
Store
(
BaseClass
*
instance
,
std
::
string
name
,
int
ts
)
{
std
::
cout
<<
"Json File Store"
<<
std
::
endl
;
instance
->
SetCreatedAt
(
ts
);
...
...
This diff is collapsed.
Click to expand it.
TGenBaseClient/JsonFileClient.h
+
2
−
0
View file @
625848cd
...
...
@@ -27,6 +27,8 @@ class JsonFileClient: public Client
void
CloseFile
();
void
FlushFile
();
void
MergeFiles
(
std
::
vector
<
std
::
string
>
files
,
std
::
string
outputFile
);
std
::
string
GetFileName
()
{
return
fFileName
;
}
virtual
BaseObject
*
GetById
(
int
id
,
int
ts
,
BaseObject
*
context
);
...
...
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