SMTK
@SMTK_VERSION@
Simulation Modeling Tool Kit
smtk
markup
json
DomainSerializer.h
1
//=========================================================================
2
// Copyright (c) Kitware, Inc.
3
// All rights reserved.
4
// See LICENSE.txt for details.
5
//
6
// This software is distributed WITHOUT ANY WARRANTY; without even
7
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8
// PURPOSE. See the above copyright notice for more information.
9
//=========================================================================
10
#ifndef smtk_markup_json_DomainSerializer_h
11
#define smtk_markup_json_DomainSerializer_h
12
13
#include "smtk/markup/Domain.h"
14
15
#include "
smtk/common/TypeName.h
"
16
17
#include "nlohmann/json.hpp"
18
19
namespace
smtk
20
{
21
namespace
markup
22
{
23
24
template
<
typename
Resource>
25
struct
DomainSerializer
26
{
27
DomainSerializer
(
const
Resource
* resource, nlohmann::json& destination)
28
: m_resource(resource)
29
, m_destination(destination)
30
{
31
}
32
33
template
<
typename
DomainType>
34
void
evaluate(std::size_t ii)
const
35
{
36
(void)ii;
37
if
(!m_resource)
38
{
39
return
;
40
}
41
nlohmann::json jDomainsOfType;
42
std::string domainType = smtk::common::typeName<DomainType>();
43
for
(
const
auto
& domainKey : m_resource->
domains
().
keys
())
44
{
45
if
(
const
auto
& domain = m_resource->
domains
().template findAs<DomainType>(domainKey))
46
{
47
if
(domain->typeName() != domainType)
48
{
49
// Ignore subclasses.
50
continue
;
51
}
52
nlohmann::json jDomain;
53
to_json(jDomain, domain.get());
54
jDomainsOfType.push_back(jDomain);
55
}
56
}
57
if
(!jDomainsOfType.empty())
58
{
59
m_destination[domainType] = jDomainsOfType;
60
}
61
}
62
63
const
Resource
* m_resource =
nullptr
;
64
nlohmann::json& m_destination;
65
};
66
67
}
// namespace markup
68
}
// namespace smtk
69
70
#endif // smtk_markup_json_DomainSerializer_h
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition:
doc.h:33
smtk::markup::Resource
A resource for annotating geometric models.
Definition:
Resource.h:53
TypeName.h
Named type functions.
smtk::markup::Resource::domains
DomainMap & domains()
Return the resource's catalog of domains.
Definition:
Resource.h:87
smtk::markup::DomainSerializer
Definition:
DomainSerializer.h:25
smtk::markup::DomainMap::keys
std::unordered_set< smtk::string::Token > keys() const
Return a set of all the domain "names" in the map.
Definition:
DomainMap.cxx:53
Generated by
1.8.17