22 #include <ddl/codec/codec_factory.h>
27 #define A_UTIL_THROW_IF_FAILED(__exp, __msg)\
29 auto __result = (__exp);\
30 if (a_util::result::isFailed(__result))\
32 throw std::runtime_error(std::string(__msg) + ": " +\
33 a_util::result::toString(__result));\
47 auto property_type = std::dynamic_pointer_cast<const adtf_file::PropertyStreamType>(stream_type);
50 throw std::runtime_error(
"The stream type is not a property stream type");
53 auto media_description = property_type->getProperty(
"md_definitions");
54 auto struct_name = property_type->getProperty(
"md_struct");
55 bool data_is_serialized =
false;
58 data_is_serialized = property_type->getProperty(
"md_data_serialized").second ==
"true";
64 return {struct_name.second, media_description.second, data_is_serialized};
75 const std::string& struct_definition,
76 bool is_serialized =
false)
78 auto type = std::make_shared<adtf_file::DefaultStreamType>(
"adtf/default");
79 type->setProperty(
"md_definitions",
"cString", struct_definition);
80 type->setProperty(
"md_struct",
"cString", struct_name);
81 type->setProperty(
"md_data_serialized",
"tBool", is_serialized ?
"true" :
"false");
94 ddl::codec::CodecFactory factory(std::get<0>(media_description), std::get<1>(media_description));
95 if (a_util::result::isFailed(factory.isValid()))
97 throw std::runtime_error(
"unable to parse media description: " + a_util::result::toString(factory.isValid()));
100 return std::tuple<ddl::codec::CodecFactory, bool>(std::move(factory), std::get<2>(media_description));
106 template<
typename ElementsType>
107 using element_callback = std::function<void(std::conditional_t<std::is_const<ElementsType>::value,
108 const typename ElementsType::element_type,
109 typename ElementsType::element_type>&)>;
146 template<
typename ElementsType>
149 for (
auto& current_element : elements)
151 if (current_element.hasChildren())
153 if (current_element.isArray())
155 for (
size_t array_pos = 0; array_pos < current_element.getArraySize(); ++array_pos)
157 auto array_element = current_element.getArrayElement(array_pos);
158 auto& children = array_element.getChildElements();
164 auto& children = current_element.getChildElements();
170 if (current_element.isArray())
172 for (
size_t array_pos = 0; array_pos < current_element.getArraySize(); ++array_pos)
174 auto array_element = current_element.getArrayElement(array_pos);
175 callback(array_element);
180 callback(current_element);
namespace for ADTF DAT Processing library.
Definition: ddl_helpers.h:38
void for_each_leaf_element(ElementsType &elements, const element_callback< ElementsType > &callback)
Iterates ALL leaf elements within ALL array elements.
Definition: ddl_helpers.h:147
std::tuple< std::string, std::string, bool > getMediaDescriptionFromStreamType(const std::shared_ptr< const adtf_file::StreamType > &stream_type)
Definition: ddl_helpers.h:45
std::tuple< ddl::codec::CodecFactory, bool > createDDLCodecFactoryFromStreamType(const std::shared_ptr< const adtf_file::StreamType > &stream_type)
Definition: ddl_helpers.h:90
std::function< void(std::conditional_t< std::is_const< ElementsType >::value, const typename ElementsType::element_type, typename ElementsType::element_type > &)> element_callback
Callback type for member elements.
Definition: ddl_helpers.h:109
std::shared_ptr< adtf_file::StreamType > createAdtfDefaultStreamType(const std::string &struct_name, const std::string &struct_definition, bool is_serialized=false)
Definition: ddl_helpers.h:74