From 5a4da310dea621022b1310439d0a5afc61d32d3d Mon Sep 17 00:00:00 2001 From: Dmitriy Suponitskiy Date: Thu, 28 Nov 2024 00:18:23 -0500 Subject: [PATCH] Changes for additional print functions --- .../lattice/hal/default/ildcrtparams.h | 3 +- .../include/lattice/hal/default/ilparams.h | 2 +- src/pke/include/encoding/encodingparams.h | 48 +++++++++---------- src/pke/include/metadata.h | 22 ++++----- src/pke/unittest/utils/UnitTestMetadataTest.h | 16 +++---- 5 files changed, 46 insertions(+), 45 deletions(-) diff --git a/src/core/include/lattice/hal/default/ildcrtparams.h b/src/core/include/lattice/hal/default/ildcrtparams.h index f85157476..284921758 100644 --- a/src/core/include/lattice/hal/default/ildcrtparams.h +++ b/src/core/include/lattice/hal/default/ildcrtparams.h @@ -345,7 +345,7 @@ class ILDCRTParams final : public ElemParams { return 1; } -private: +protected: std::ostream& doprint(std::ostream& out) const override { out << "ILDCRTParams "; ElemParams::doprint(out); @@ -355,6 +355,7 @@ class ILDCRTParams final : public ElemParams { return out << std::endl; } +private: // array of smaller ILParams std::vector> m_params; }; diff --git a/src/core/include/lattice/hal/default/ilparams.h b/src/core/include/lattice/hal/default/ilparams.h index ce18606fa..e08b1a732 100644 --- a/src/core/include/lattice/hal/default/ilparams.h +++ b/src/core/include/lattice/hal/default/ilparams.h @@ -152,7 +152,7 @@ class ILParamsImpl final : public ElemParams { return 1; } -private: +protected: std::ostream& doprint(std::ostream& out) const override { out << "ILParams "; ElemParams::doprint(out); diff --git a/src/pke/include/encoding/encodingparams.h b/src/pke/include/encoding/encodingparams.h index cd213c38f..e75c7f5e9 100644 --- a/src/pke/include/encoding/encodingparams.h +++ b/src/pke/include/encoding/encodingparams.h @@ -124,7 +124,7 @@ class EncodingParamsImpl : public lbcrypto::Serializable { /** * Destructor. */ - virtual ~EncodingParamsImpl() {} + virtual ~EncodingParamsImpl() = default; // ACCESSORS @@ -253,29 +253,6 @@ class EncodingParamsImpl : public lbcrypto::Serializable { return !(*this == other); } -private: - std::ostream& doprint(std::ostream& out) const { - out << "[p=" << m_plaintextModulus << " rootP =" << m_plaintextRootOfUnity << " bigP =" << m_plaintextBigModulus - << " rootBigP =" << m_plaintextBigRootOfUnity << " g=" << m_plaintextGenerator << " L=" << m_batchSize - << "]"; - return out; - } - - // plaintext modulus that is used by all schemes - PlaintextModulus m_plaintextModulus; - // root of unity for plaintext modulus - NativeInteger m_plaintextRootOfUnity; - // big plaintext modulus that is used for arbitrary cyclotomics - NativeInteger m_plaintextBigModulus; - // root of unity for big plaintext modulus - NativeInteger m_plaintextBigRootOfUnity; - // plaintext generator is used for packed encoding (to find the correct - // automorphism index) - uint32_t m_plaintextGenerator; - // maximum batch size used by EvalSumKeyGen for packed encoding - uint32_t m_batchSize; - -public: template void save(Archive& ar, std::uint32_t const version) const { ar(::cereal::make_nvp("m", m_plaintextModulus)); @@ -306,6 +283,29 @@ class EncodingParamsImpl : public lbcrypto::Serializable { static uint32_t SerializedVersion() { return 1; } + +protected: + std::ostream& doprint(std::ostream& out) const { + out << "[p=" << m_plaintextModulus << " rootP =" << m_plaintextRootOfUnity << " bigP =" << m_plaintextBigModulus + << " rootBigP =" << m_plaintextBigRootOfUnity << " g=" << m_plaintextGenerator << " L=" << m_batchSize + << "]"; + return out; + } + +private: + // plaintext modulus that is used by all schemes + PlaintextModulus m_plaintextModulus; + // root of unity for plaintext modulus + NativeInteger m_plaintextRootOfUnity; + // big plaintext modulus that is used for arbitrary cyclotomics + NativeInteger m_plaintextBigModulus; + // root of unity for big plaintext modulus + NativeInteger m_plaintextBigRootOfUnity; + // plaintext generator is used for packed encoding (to find the correct + // automorphism index) + uint32_t m_plaintextGenerator; + // maximum batch size used by EvalSumKeyGen for packed encoding + uint32_t m_batchSize; }; inline std::ostream& operator<<(std::ostream& out, const std::shared_ptr& o) { diff --git a/src/pke/include/metadata.h b/src/pke/include/metadata.h index 54ca7241e..8a08c6fea 100644 --- a/src/pke/include/metadata.h +++ b/src/pke/include/metadata.h @@ -92,20 +92,11 @@ class Metadata { } /** - * A method that prints the contents of metadata objects. - * Please override in subclasses to print all members. - */ - virtual std::ostream& print(std::ostream& out) const { - out << "[ ]" << std::endl; - return out; - } - - /** - * << operator implements by calling member method print. + * << operator implements by calling member method PrintMetadata. * This is a friend method and cannot be overriden by subclasses. */ friend std::ostream& operator<<(std::ostream& out, const Metadata& m) { - m.print(out); + m.PrintMetadata(out); return out; } @@ -139,6 +130,15 @@ class Metadata { static uint32_t SerializedVersion() { return 1; } + +protected: + /** + * A method that prints the contents of metadata objects. + * Please override in subclasses to print all members. + */ + virtual std::ostream& PrintMetadata(std::ostream& out) const { + OPENFHE_THROW("Not implemented"); + } }; } // end namespace lbcrypto diff --git a/src/pke/unittest/utils/UnitTestMetadataTest.h b/src/pke/unittest/utils/UnitTestMetadataTest.h index d4807d277..b2ae7295e 100644 --- a/src/pke/unittest/utils/UnitTestMetadataTest.h +++ b/src/pke/unittest/utils/UnitTestMetadataTest.h @@ -108,14 +108,6 @@ class MetadataTest : public Metadata { } } - /** - * Defines how to print the contents of objects of this class. - */ - std::ostream& print(std::ostream& out) const { - out << "[ " << m_s << " ]"; - return out; - } - /** * save method for serialization */ @@ -201,6 +193,14 @@ class MetadataTest : public Metadata { } protected: + /** + * Defines how to print the contents of objects of this class. + */ + std::ostream& PrintMetadata(std::ostream& out) const override { + out << "[ " << m_s << " ]"; + return out; + } + std::string m_s; };