Skip to content

Commit

Permalink
Merge pull request #1494 from ghutchis/add-variant-char-matrix
Browse files Browse the repository at this point in the history
Add specialization for char* and MatrixXf types
  • Loading branch information
ghutchis authored Dec 4, 2023
2 parents 80634d9 + 1260e1a commit 32250d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions avogadro/core/variant-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,28 @@
namespace Avogadro {
namespace Core {

inline Variant::Variant() : m_type(Null)
{
}
inline Variant::Variant() : m_type(Null) {}

template <typename T>
inline Variant::Variant(T v) : m_type(Null)
{
setValue(v);
}

template <>
inline Variant::Variant(const char* v) : m_type(String)
{
m_value.string = new std::string(v);
}

template <>
inline Variant::Variant(const MatrixXf& v) : m_type(Matrix)
{
MatrixX* m = new MatrixX(v.rows(), v.cols());
*m = v.cast<double>();
m_value.matrix = m;
}

inline Variant::Variant(const Variant& variant) : m_type(variant.type())
{
if (m_type == String)
Expand Down Expand Up @@ -444,7 +456,7 @@ inline T Variant::lexical_cast(const std::string& str)
return value;
}

} // end Core namespace
} // end Avogadro namespace
} // namespace Core
} // namespace Avogadro

#endif // AVOGADRO_CORE_VARIANT_INLINE_H
4 changes: 2 additions & 2 deletions avogadro/core/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class AVOGADROCORE_EXPORT Variant
} m_value;
};

} // end Core namespace
} // end Avogadro namespace
} // namespace Core
} // namespace Avogadro

#include "variant-inline.h"

Expand Down

0 comments on commit 32250d9

Please sign in to comment.