Commit e4929ee1 authored by David Thompson's avatar David Thompson
Browse files

WIP: Generated code builds.

parent d6e2b8dc
......@@ -196,21 +196,11 @@ nodeClasses = {
'smtk::markup::Image': {
'description': 'An n-dimensional grid of cells.',
'members': {
'axes': { 'type': 'std::vector<std::weak_ptr<smtk::markup::IdAllotment>>' },
'axes': { 'type': 'std::vector<std::weak_ptr<smtk::markup::IdAllotment>>', 'access': 'force-write' },
'points': { 'type': 'std::weak_ptr<smtk::markup::IdAllotment>' },
'cells': { 'type': 'std::weak_ptr<smtk::markup::IdAllotment>' },
'data': { 'type': 'vtkSmartPointer<vtkImageData>' }
},
'methods': {
'setAxes': {
'signature': 'bool setAxes(const std::vector<std::weak_ptr<smtk::markup::IdAllotment>>& axes)',
'description': 'Set the numbering of points along each axis of the image grid.',
'body': """
m_axes = axes;
return true;
"""
},
},
'header-includes': [ 'smtk/markup/IdAllotment.h', 'vtkSmartPointer.h' ],
'header-forward-classes': [ 'vtkImageData' ],
},
......@@ -289,6 +279,7 @@ nodeClasses = {
},
'smtk::markup::SideSet': {
'description': 'An adaptation of subsets for representing subsets of boundaries of spatial data.',
'header-forward-classes': [ 'smtk::markup::IdAllotment' ],
'header-includes': [
'smtk/common/Visit.h',
'smtk/markup/BoundaryOperator.h',
......@@ -301,10 +292,29 @@ nodeClasses = {
'visit': {
'signature': 'smtk::common::Visit visit(Visitor visitor)',
'description': 'The signature of functions that visit elements of a subset.',
'body': """
smtk::common::Visit result = smtk::common::Visit::Halt;
auto allotment = m_domain.lock();
if (!allotment)
{
return result;
}
auto space = allotment->idSpace().lock();
for (const auto& side : m_sides)
{
result = visitor(*space, side.first, side.second);
if (result == smtk::common::Visit::Halt)
{
break;
}
}
return result;
""",
'attributes': [ 'virtual' ]
}
},
'members': {
'domain': { 'type': 'std::weak_ptr<smtk::markup::IdAllotment>' },
'boundaryOperator': { 'type': 'std::weak_ptr<smtk::markup::BoundaryOperator>' },
'sides': {
'type': 'std::multimap<smtk::markup::IdSpace::IdType, smtk::markup::IdSpace::IdType>',
......@@ -323,6 +333,14 @@ nodeClasses = {
'idSpace': { 'type': 'std::weak_ptr<smtk::markup::IdAllotment>' },
'index': { 'type': 'std::weak_ptr<smtk::markup::Index>' },
},
'methods': {
'name': {
'signature': 'std::string name() const',
'body': """
return m_name;
"""
},
},
'smtk::markup::LabelMap': {
'description': 'A mapping from an IdSpace to an integer label, with optional string names for each integer.',
'smtk::markup::Segmentation': {
......@@ -425,7 +443,7 @@ def includeDirectives(includeList):
def generateHeaderHeader(ns, name, inherit, extraIncludes, forwardClasses):
nspath = '_'.join(ns) + '_' + name + "_h"
header = dedentString("""
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef {0}
#define {0}
......@@ -505,12 +523,12 @@ def generateMethodStubs(ns, bareName, classDef, includes):
for methodName, methodDef in classDef['methods'].items():
if isPureVirtualMethod(methodDef):
continue
sig = methodDef['signature'].replace(methodName, '{0}::{1}'.format(bareName, methodName))
sig = methodDef['signature'].replace(methodName, '{0}::{1}'.format(bareName, methodName), 1)
if 'body' in methodDef:
code += dedentString(sig) + '\n{{\n{0}}}\n\n'.format(indentString(dedentString(methodDef['body']), 2))
else:
code += dedentString(sig) + '\n{\n}\n\n'
includeScan(code, includes)
# includeScan(code, includes)
methodNames.add(methodName)
if 'members' in classDef:
......@@ -679,10 +697,10 @@ def emitClass(name, classType, classList, inherit, moduleData):
for line in description:
headerData += '/// {0}\n'.format(line)
# Do not declare a set-method if read-only or explicitly declared.
if access == 'read-write' and 'set{0}'.format(camelCase(memberName)) not in methodNames:
if (access == 'read-write' or access == 'force-write') and 'set{0}'.format(camelCase(memberName)) not in methodNames:
headerData += ' bool set{0}(const {1}& {2});\n'.format(casedName, member['type'], memberName)
# Do not declare a get-method if explicitly declared.
if (access == 'read-write' or access == 'read-only') and memberName not in methodNames:
if access != 'write-only' and memberName not in methodNames:
headerData += ' const {0}& {1}() const;\n'.format(member['type'], memberName)
headerData += ' {0}& {1}();\n'.format(member['type'], memberName)
headerData += '\nprotected:\n'
......@@ -744,7 +762,7 @@ def generate(classList, classType = 'nodes', moduleData = {}, inherit = None):
if inherit is None:
inherit = [] if classType == 'arcs' else ['smtk::graph::Component']
keywords = set(['access', 'attributes', 'description', 'enums', 'header-includes', 'header-forward-classes', 'members', 'methods', 'protected-methods', 'signature', 'type-aliases'])
keywords = set(['access', 'attributes', 'body', 'description', 'enums', 'header-includes', 'header-forward-classes', 'members', 'methods', 'protected-methods', 'signature', 'type-aliases'])
for name in classList.keys():
if name in keywords:
continue
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_AnalyticShape_h
#define smtk_markup_AnalyticShape_h
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
#include "smtk/markup/BoundaryOperator.h"
namespace smtk
{
namespace markup
{
BoundaryOperator::~BoundaryOperator() = default;
} // namespace markup
} // namespace smtk
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_BoundaryOperator_h
#define smtk_markup_BoundaryOperator_h
#include "smtk/markup/Domain.h"
namespace smtk
{
namespace markup
{
/// A discrete mapping from one IdSpace into another that enumerates boundaries of the domain.
class SMTKMARKUP_EXPORT BoundaryOperator : public smtk::markup::Domain
{
public:
smtkTypeMacro(smtk::markup::BoundaryOperator);
smtkSuperclassMacro(smtk::markup::Domain);
template<typename... Args>
BoundaryOperator(Args&&... args)
: smtk::markup::Domain(std::forward<Args>(args)...)
{
}
~BoundaryOperator() override;
protected:
};
} // namespace markup
} // namespace smtk
#endif // smtk_markup_BoundaryOperator_h
\ No newline at end of file
......@@ -18,12 +18,12 @@ bool Box::setRange(const std::array<std::array<double, 3>, 2>& range)
return true;
}
const std::array<std::array<double, 3>, 2>& range() const
const std::array<std::array<double, 3>, 2>& Box::range() const
{
return m_range;
}
std::array<std::array<double, 3>, 2>& range()
std::array<std::array<double, 3>, 2>& Box::range()
{
return m_range;
}
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_Box_h
#define smtk_markup_Box_h
......@@ -24,7 +24,7 @@ public:
~Box() override;
bool setRange(range std::array<std::array<double, 3>, 2>);
bool setRange(const std::array<std::array<double, 3>, 2>& range);
const std::array<std::array<double, 3>, 2>& range() const;
std::array<std::array<double, 3>, 2>& range();
......
......@@ -4,6 +4,7 @@ set(headers)
list(APPEND classes
Component
Domain
BoundaryOperator
IdSpace
ParameterSpace
Index
......@@ -22,7 +23,6 @@ list(APPEND classes
Grid
VolumeGrid
SurfaceGrid
References
Subset
ExplicitSubset
RangedSubset
......
......@@ -8,42 +8,66 @@ namespace markup
Collection::~Collection() = default;
bool Collection::setMembers(const std::set<std::weak_ptr<smtk::markup::Component>, std::owner_less<std::weak_ptr<smtk::markup::Component>>>& members)
{
std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>> next;
std::unordered_set<smtk::markup::IdSpace::IdType> removed;
auto newEntries = members;
for (const auto& entry : m_members)
{
if (auto member = entry.second.lock())
{
if (members.find(member) != members.end())
{
next[entry.first] = member;
newEntries.erase(member);
}
else
{
removed.insert(entry.first);
}
}
}
std::size_t ii = 0;
for (const auto& member : newEntries)
{
for (; next.find(ii) != next.end(); ++ii)
{ /* do nothing */ }
next[ii] = member.lock();
++ii;
}
m_members = next;
return removed.empty() && newEntries.empty();
}
bool Collection::setKeys(const std::weak_ptr<smtk::markup::IdAllotment>& keys)
{
if (m_keys == keys)
auto mlocked = m_keys.lock();
auto vlocked = keys.lock();
if (mlocked == vlocked)
{
return false;
}
m_keys = keys;
m_keys = vlocked;
return true;
}
const std::weak_ptr<smtk::markup::IdAllotment>& keys() const
const std::weak_ptr<smtk::markup::IdAllotment>& Collection::keys() const
{
return m_keys;
}
std::weak_ptr<smtk::markup::IdAllotment>& keys()
std::weak_ptr<smtk::markup::IdAllotment>& Collection::keys()
{
return m_keys;
}
bool Collection::setMembers(const std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>& members)
{
if (m_members == members)
{
return false;
}
m_members = members;
return true;
}
const std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>& members() const
const std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>& Collection::members() const
{
return m_members;
}
std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>& members()
std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>& Collection::members()
{
return m_members;
}
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_Collection_h
#define smtk_markup_Collection_h
#include "smtk/markup/Component.h"
#include "smtk/markup/IdAllotment.h"
namespace smtk
{
namespace markup
......@@ -24,11 +26,12 @@ public:
~Collection() override;
bool setKeys(keys std::weak_ptr<smtk::markup::IdAllotment>);
bool setMembers(const std::set<std::weak_ptr<smtk::markup::Component>, std::owner_less<std::weak_ptr<smtk::markup::Component>>>& members);
bool setKeys(const std::weak_ptr<smtk::markup::IdAllotment>& keys);
const std::weak_ptr<smtk::markup::IdAllotment>& keys() const;
std::weak_ptr<smtk::markup::IdAllotment>& keys();
bool setMembers(members std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>);
const std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>& members() const;
std::unordered_map<smtk::markup::IdSpace::IdType, std::weak_ptr<smtk::markup::Component>>& members();
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_Comment_h
#define smtk_markup_Comment_h
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_Component_h
#define smtk_markup_Component_h
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
#include "smtk/markup/CompositeSubset.h"
#include "smtk/markup/Subset.h"
namespace smtk
{
namespace markup
......@@ -8,22 +10,18 @@ namespace markup
CompositeSubset::~CompositeSubset() = default;
bool CompositeSubset::setMembers(const std::set<std::weak_ptr<smtk::markup::Subset>>& members)
bool CompositeSubset::setMembers(const std::set<std::weak_ptr<smtk::markup::Subset>, std::owner_less<std::weak_ptr<smtk::markup::Subset>>>& members)
{
if (m_members == members)
{
return false;
}
m_members = members;
return true;
}
const std::set<std::weak_ptr<smtk::markup::Subset>>& members() const
const std::set<std::weak_ptr<smtk::markup::Subset>, std::owner_less<std::weak_ptr<smtk::markup::Subset>>>& CompositeSubset::members() const
{
return m_members;
}
std::set<std::weak_ptr<smtk::markup::Subset>>& members()
std::set<std::weak_ptr<smtk::markup::Subset>, std::owner_less<std::weak_ptr<smtk::markup::Subset>>>& CompositeSubset::members()
{
return m_members;
}
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_CompositeSubset_h
#define smtk_markup_CompositeSubset_h
#include "smtk/markup/Subset.h"
namespace smtk {namespace markup { class Subset; } }
namespace smtk
{
namespace markup
......@@ -24,12 +26,12 @@ public:
~CompositeSubset() override;
bool setMembers(members std::set<std::weak_ptr<smtk::markup::Subset>>);
const std::set<std::weak_ptr<smtk::markup::Subset>>& members() const;
std::set<std::weak_ptr<smtk::markup::Subset>>& members();
bool setMembers(const std::set<std::weak_ptr<smtk::markup::Subset>, std::owner_less<std::weak_ptr<smtk::markup::Subset>>>& members);
const std::set<std::weak_ptr<smtk::markup::Subset>, std::owner_less<std::weak_ptr<smtk::markup::Subset>>>& members() const;
std::set<std::weak_ptr<smtk::markup::Subset>, std::owner_less<std::weak_ptr<smtk::markup::Subset>>>& members();
protected:
std::set<std::weak_ptr<smtk::markup::Subset>> m_members;
std::set<std::weak_ptr<smtk::markup::Subset>, std::owner_less<std::weak_ptr<smtk::markup::Subset>>> m_members;
};
} // namespace markup
......
......@@ -18,12 +18,12 @@ bool Cone::setEndpoints(const std::array<std::array<double, 3>, 2>& endpoints)
return true;
}
const std::array<std::array<double, 3>, 2>& endpoints() const
const std::array<std::array<double, 3>, 2>& Cone::endpoints() const
{
return m_endpoints;
}
std::array<std::array<double, 3>, 2>& endpoints()
std::array<std::array<double, 3>, 2>& Cone::endpoints()
{
return m_endpoints;
}
......@@ -38,12 +38,12 @@ bool Cone::setRadii(const std::array<double, 2>& radii)
return true;
}
const std::array<double, 2>& radii() const
const std::array<double, 2>& Cone::radii() const
{
return m_radii;
}
std::array<double, 2>& radii()
std::array<double, 2>& Cone::radii()
{
return m_radii;
}
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_Cone_h
#define smtk_markup_Cone_h
......@@ -24,11 +24,11 @@ public:
~Cone() override;
bool setEndpoints(endpoints std::array<std::array<double, 3>, 2>);
bool setEndpoints(const std::array<std::array<double, 3>, 2>& endpoints);
const std::array<std::array<double, 3>, 2>& endpoints() const;
std::array<std::array<double, 3>, 2>& endpoints();
bool setRadii(radii std::array<double, 2>);
bool setRadii(const std::array<double, 2>& radii);
const std::array<double, 2>& radii() const;
std::array<double, 2>& radii();
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_DiscreteGeometry_h
#define smtk_markup_DiscreteGeometry_h
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_Domain_h
#define smtk_markup_Domain_h
......
......@@ -18,12 +18,12 @@ bool ExplicitSubset::setMembers(const std::set<smtk::markup::IdSpace::IdType>& m
return true;
}
const std::set<smtk::markup::IdSpace::IdType>& members() const
const std::set<smtk::markup::IdSpace::IdType>& ExplicitSubset::members() const
{
return m_members;
}
std::set<smtk::markup::IdSpace::IdType>& members()
std::set<smtk::markup::IdSpace::IdType>& ExplicitSubset::members()
{
return m_members;
}
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_ExplicitSubset_h
#define smtk_markup_ExplicitSubset_h
......@@ -24,7 +24,7 @@ public:
~ExplicitSubset() override;
bool setMembers(members std::set<smtk::markup::IdSpace::IdType>);
bool setMembers(const std::set<smtk::markup::IdSpace::IdType>& members);
const std::set<smtk::markup::IdSpace::IdType>& members() const;
std::set<smtk::markup::IdSpace::IdType>& members();
......
// Copyright © Kitware Inc under the [BSD-3-clause license](https://kitware.com/licenses/bsd.md).
// Copyright © Kitware Inc under the [BSD-3-clause license](https://opensource.org/licenses/BSD-3-Clause).
#ifndef smtk_markup_Feature_h
#define smtk_markup_Feature_h
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment