Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specialization for char* and MatrixXf types #1494

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading