diff --git a/cpp/csp/adapters/utils/JSONMessageWriter.h b/cpp/csp/adapters/utils/JSONMessageWriter.h index fc5902bbd..928a66ed3 100644 --- a/cpp/csp/adapters/utils/JSONMessageWriter.h +++ b/cpp/csp/adapters/utils/JSONMessageWriter.h @@ -63,14 +63,14 @@ class JSONMessageWriter : public MessageWriter } private: - void processTickImpl( const OutputDataMapper & dataMapper, const TimeSeriesProvider * sourcets ) + void processTickImpl( const OutputDataMapper & dataMapper, const TimeSeriesProvider * sourcets ) override { dataMapper.apply( *this, sourcets ); } template inline auto convertValue( const T & value ) - { + { return value; } @@ -92,13 +92,13 @@ class JSONMessageWriter : public MessageWriter template<> inline auto JSONMessageWriter::convertValue( const std::string & value ) { - return rapidjson::StringRef( value.c_str() ); + return rapidjson::StringRef( value.c_str() ); } template<> inline auto JSONMessageWriter::convertValue( const csp::Date & value ) { - return rapidjson::Value( value.asYYYYMMDD().c_str(), m_doc.GetAllocator() ); + return rapidjson::Value( value.asYYYYMMDD().c_str(), m_doc.GetAllocator() ); } template<> @@ -123,7 +123,7 @@ inline auto JSONMessageWriter::convertValue( const csp::DateTime & value ) template<> inline auto JSONMessageWriter::convertValue( const csp::TimeDelta & value ) { - return rapidjson::Value( value.asNanoseconds() ); + return rapidjson::Value( value.asNanoseconds() ); } template<> @@ -159,7 +159,7 @@ inline auto JSONMessageWriter::convertValue( const StructPtr & struct_, const Cs if( !nestedEntry.sField -> isSet( struct_.get() ) ) continue; - + SupportedCspTypeSwitch::template invoke( nestedEntry.sField -> type().get(), [ & ]( auto tag ) diff --git a/cpp/csp/engine/CspType.h b/cpp/csp/engine/CspType.h index 803e68430..f1fa10f3d 100644 --- a/cpp/csp/engine/CspType.h +++ b/cpp/csp/engine/CspType.h @@ -217,7 +217,6 @@ template<> template<> struct CspType::Type::toCType template<> template<> struct CspType::Type::toCType { using type = StructPtr; }; template<> template<> struct CspType::Type::toCType { using type = DialectGenericType; }; template<> template struct CspType::Type::toCType { using type = std::vector; }; -template<> template<> struct CspType::Type::toCType { using type = std::vector; }; template<> struct CspType::fromCType { static CspTypePtr & type() { return CspType::BOOL(); } }; template<> struct CspType::fromCType { static CspTypePtr & type() { return CspType::INT8(); } }; diff --git a/cpp/csp/engine/InputAdapter.cpp b/cpp/csp/engine/InputAdapter.cpp index d52c620d0..dee69eeef 100644 --- a/cpp/csp/engine/InputAdapter.cpp +++ b/cpp/csp/engine/InputAdapter.cpp @@ -13,4 +13,53 @@ InputAdapter::InputAdapter( Engine *engine, const CspTypePtr &type, PushMode pus init( type ); } + +template<> +bool InputAdapter::consumeTick( const bool & value ) +{ + switch( pushMode() ) + { + case PushMode::LAST_VALUE: + { + if( unlikely( rootEngine() -> cycleCount() == lastCycleCount() ) ) + m_timeseries -> lastValueTyped() = value; + else + this -> outputTickTyped( rootEngine() -> now(), value ); + return true; + } + + case PushMode::BURST: + { + CSP_ASSERT( type() -> type() == CspType::Type::ARRAY ); + CSP_ASSERT( static_cast( type() ) -> elemType() -> type() == CspType::Type::fromCType::type ); + + using ArrayT = typename CspType::Type::toCType::type; + if( likely( rootEngine() -> cycleCount() != lastCycleCount() ) ) + { + //ensure we reuse vector memory in our buffer by using reserve api and + //clearing existing value if any + reserveTickTyped( rootEngine() -> cycleCount(), rootEngine() -> now() ).clear(); + } + + m_timeseries -> lastValueTyped().push_back( value ); + return true; + } + + case PushMode::NON_COLLAPSING: + { + if( unlikely( rootEngine() -> cycleCount() == lastCycleCount() ) ) + return false; + + this -> outputTickTyped( rootEngine() -> now(), value ); + return true; + } + + default: + CSP_THROW( NotImplemented, pushMode() << " mode is not yet supported" ); + break; + } + + return true; +} + } diff --git a/cpp/csp/engine/InputAdapter.h b/cpp/csp/engine/InputAdapter.h index 883407e3c..0fd0f7725 100644 --- a/cpp/csp/engine/InputAdapter.h +++ b/cpp/csp/engine/InputAdapter.h @@ -70,7 +70,7 @@ bool InputAdapter::consumeTick( const T & value ) using ArrayT = typename CspType::Type::toCType::type; if( likely( rootEngine() -> cycleCount() != lastCycleCount() ) ) { - //ensure we reuse vector memory in our buffer by using reserve api and + //ensure we reuse vector memory in our buffer by using reserve api and //clearing existing value if any reserveTickTyped( rootEngine() -> cycleCount(), rootEngine() -> now() ).clear(); } @@ -97,5 +97,4 @@ bool InputAdapter::consumeTick( const T & value ) } }; - #endif