From 8755181c0bb690597ab90783a7afe9a7b5ef9037 Mon Sep 17 00:00:00 2001
From: Aaron Cuevas Lopez <aacuelo@teleco.upv.es>
Date: Thu, 12 Jan 2017 03:14:29 +0100
Subject: [PATCH] Add methods to help find specific metadata fields in channels

---
 Source/Processors/Channel/MetaData.cpp | 25 +++++++++++++++++++++++++
 Source/Processors/Channel/MetaData.h   |  4 +++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/Source/Processors/Channel/MetaData.cpp b/Source/Processors/Channel/MetaData.cpp
index 6e73d3d03..7fa9aee1c 100644
--- a/Source/Processors/Channel/MetaData.cpp
+++ b/Source/Processors/Channel/MetaData.cpp
@@ -39,6 +39,7 @@ bool checkMetaDataType(MetaDataDescriptor::MetaDataTypes baseType)
 	case MetaDataDescriptor::UINT32: return std::is_same<uint32, T>::value;
 	case MetaDataDescriptor::INT64: return std::is_same<int64, T>::value;
 	case MetaDataDescriptor::UINT64: return std::is_same<uint64, T>::value;
+	default: return false;
 	}
 }
 
@@ -300,6 +301,18 @@ const int MetaDataInfoObject::getMetaDataCount() const
 	return m_metaDataDescriptorArray.size();
 }
 
+int MetaDataInfoObject::findMetaData(MetaDataDescriptor::MetaDataTypes type, unsigned int length, String descriptor) const
+{
+	int nMetaData = m_metaDataDescriptorArray.size();
+	for (int i = 0; i < nMetaData; i++)
+	{
+		MetaDataDescriptorPtr md = m_metaDataDescriptorArray[i];
+		if (md->getType() == type && md->getLength() == length && (descriptor.isEmpty() || descriptor.equalsIgnoreCase(md->getDescriptor())))
+			return i;
+	}
+	return -1;
+}
+
 //MetaDataEventObject
 
 MetaDataEventObject::MetaDataEventObject() {}
@@ -343,6 +356,18 @@ const int MetaDataEventObject::getEventMetaDataCount() const
 	return m_eventMetaDataDescriptorArray.size();
 }
 
+int MetaDataEventObject::findEventMetaData(MetaDataDescriptor::MetaDataTypes type, unsigned int length, String descriptor) const
+{
+	int nMetaData = m_eventMetaDataDescriptorArray.size();
+	for (int i = 0; i < nMetaData; i++)
+	{
+		MetaDataDescriptorPtr md = m_eventMetaDataDescriptorArray[i];
+		if (md->getType() == type && md->getLength() == length && (descriptor.isEmpty() || descriptor.equalsIgnoreCase(md->getDescriptor())))
+			return i;
+	}
+	return -1;
+}
+
 //MetaDataEvent
 MetaDataEvent::MetaDataEvent() {}
 
diff --git a/Source/Processors/Channel/MetaData.h b/Source/Processors/Channel/MetaData.h
index 60801fc3c..5dd992ba3 100644
--- a/Source/Processors/Channel/MetaData.h
+++ b/Source/Processors/Channel/MetaData.h
@@ -175,13 +175,14 @@ public:
 	void addMetaData(const MetaDataDescriptor& desc, const MetaDataValue& val);
 	const MetaDataDescriptor* getMetaDataDescriptor(int index) const;
 	const MetaDataValue* getMetaDataValue(int index) const;
+	int findMetaData(MetaDataDescriptor::MetaDataTypes type, unsigned int length, String descriptor = String::empty) const;
 	const int getMetaDataCount() const;
 protected:
 	MetaDataDescriptorArray m_metaDataDescriptorArray;
 	MetaDataValueArray m_metaDataValueArray;
 };
 
-class MetaDataEventLock
+class PLUGIN_API MetaDataEventLock
 {
 	//GenericProcessor will set this to true when copying channels in the update method so no other processor but the one which
 	//created the object can call addEventMetaData. This is done this way because since the events themselves are created by the
@@ -201,6 +202,7 @@ public:
 	void addEventMetaData(MetaDataDescriptor* desc);
 	void addEventMetaData(const MetaDataDescriptor& desc);
 	const MetaDataDescriptor* getEventMetaDataDescriptor(int index) const;
+	int findEventMetaData(MetaDataDescriptor::MetaDataTypes type, unsigned int length, String descriptor = String::empty) const;
 	size_t getTotalEventMetaDataSize() const;
 	const int getEventMetaDataCount() const;
 protected:
-- 
GitLab