From dff42354bc083dcb1363cd78f521dad9284ac2f9 Mon Sep 17 00:00:00 2001 From: Blake-Madden <66873089+Blake-Madden@users.noreply.github.com> Date: Tue, 28 May 2024 11:32:43 -0400 Subject: [PATCH] Add copy construction support Explain that each thread should have its own parser object. --- README.md | 2 +- docs/manual/index.qmd | 2 +- tinyexpr.h | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 75483ac..41e2f4d 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Note: for current users of *TinyExpr++*, please see the [compatibility advisory] - Supports C and C++ style comments within math expressions. - Released under the zlib license - free for nearly any use. - Easy to use and integrate with your code. -- Thread-safe; parser is in a self-contained object. +- Thread-safe; parser can be constructed as per thread objects. ## Changes from TinyExpr diff --git a/docs/manual/index.qmd b/docs/manual/index.qmd index 71397fa..591f3e5 100644 --- a/docs/manual/index.qmd +++ b/docs/manual/index.qmd @@ -46,4 +46,4 @@ It's open-source, free, easy-to-use, and self-contained in a single source and h - Can be configured to use `double`, `long double`, or [`float`](#te-float) for its calculations. - Released under the zlib license - free for nearly any use. - Easy to use and integrate with your code. -- Thread-safe; parser is in a self-contained object. +- Thread-safe; parser can be constructed as per thread objects. diff --git a/tinyexpr.h b/tinyexpr.h index e763ad7..0a5efc8 100644 --- a/tinyexpr.h +++ b/tinyexpr.h @@ -246,9 +246,23 @@ class te_parser /// @private te_parser() = default; /// @private - te_parser(const te_parser&) = delete; + te_parser(const te_parser& that) + { + m_customFuncsAndVars = that.m_customFuncsAndVars; + m_unknownSymbolResolve = that.m_unknownSymbolResolve; + m_keepResolvedVarialbes = that.m_keepResolvedVarialbes; + m_decimalSeparator = that.m_decimalSeparator; + m_listSeparator = that.m_listSeparator; + } /// @private - te_parser& operator=(const te_parser&) = delete; + te_parser& operator=(const te_parser& that) + { + m_customFuncsAndVars = that.m_customFuncsAndVars; + m_unknownSymbolResolve = that.m_unknownSymbolResolve; + m_keepResolvedVarialbes = that.m_keepResolvedVarialbes; + m_decimalSeparator = that.m_decimalSeparator; + m_listSeparator = that.m_listSeparator; + } /// @private ~te_parser() { te_free(m_compiledExpression); }