Skip to content

Commit

Permalink
Short circuit.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Sep 4, 2019
1 parent db0918f commit 10e3024
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pdal/DimUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,47 @@ inline Type type(const std::string& baseType, size_t size)
return static_cast<Type>((size_t)(base) | size);
}

template<typename T>
inline constexpr Type type()
{ return Type::None; }

template<>
inline constexpr Type type<float>()
{ return Type::Float; }

template<>
inline constexpr Type type<uint64_t>()
{ return Type::Unsigned64; }

template<>
inline constexpr Type type<uint32_t>()
{ return Type::Unsigned32; }

template<>
inline constexpr Type type<uint16_t>()
{ return Type::Unsigned16; }

template<>
inline constexpr Type type<uint8_t>()
{ return Type::Unsigned8; }


template<>
inline constexpr Type type<int64_t>()
{ return Type::Signed64; }

template<>
inline constexpr Type type<int32_t>()
{ return Type::Signed32; }

template<>
inline constexpr Type type<int16_t>()
{ return Type::Signed16; }

template<>
inline constexpr Type type<int8_t>()
{ return Type::Signed8; }

/// Extract a dimension name of a string. Dimension names start with an alpha
/// and continue with numbers or underscores.
/// \param s String from which to extract dimension name.
Expand Down
11 changes: 11 additions & 0 deletions pdal/PointRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class PDAL_DLL PointRef
Everything e;
Dimension::Type type = m_layout.dimDetail(dim)->type();

if (Dimension::type<T>() == type)
{
T t;
m_container.getFieldInternal(dim, m_idx, &t);
return t;
}

m_container.getFieldInternal(dim, m_idx, &e);
switch (type)
{
Expand Down Expand Up @@ -135,6 +142,10 @@ class PDAL_DLL PointRef
void setField(Dimension::Id dim, T val)
{
Dimension::Type type = m_layout.dimDetail(dim)->type();

if (Dimension::type<T>() == type)
m_container.setFieldInternal(dim, m_idx, &val);

Everything e;
bool success = false;

Expand Down
3 changes: 3 additions & 0 deletions pdal/PointView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ void PointView::setField(Dimension::Id dim, PointId idx, T val)
{
const Dimension::Detail *dd = layout()->dimDetail(dim);

if (Dimension::type<T>() == dd->type())
setFieldInternal(dim, idx, &val);

bool ok = true;
switch (dd->type())
{
Expand Down

0 comments on commit 10e3024

Please sign in to comment.