00001 /* 00002 * SEMAINEFeatureMessage.h 00003 * semaine 00004 * 00005 * Created by Marc Schröder on 17.09.08. 00006 * Copyright 2008 DFKI GmbH. All rights reserved. 00007 * 00008 */ 00009 00010 #ifndef SEMAINE_CMS_MESSAGE_SEMAINEFEATUREMESSAGE_H 00011 #define SEMAINE_CMS_MESSAGE_SEMAINEFEATUREMESSAGE_H 00012 00013 #include <semaine/config.h> 00014 00015 #include <semaine/cms/message/SEMAINEMessage.h> 00016 #include <semaine/cms/exceptions/MessageFormatException.h> 00017 00018 #include <cms/Message.h> 00019 #include <cms/TextMessage.h> 00020 #include <cms/BytesMessage.h> 00021 #include <cms/CMSException.h> 00022 00023 #include <sstream> 00024 00025 using namespace cms; 00026 00027 namespace semaine { 00028 namespace cms { 00029 namespace message { 00030 00031 class SEMAINEFeatureMessage : public SEMAINEMessage 00032 { 00033 public: 00034 SEMAINEFeatureMessage(const Message * message) throw(semaine::cms::exceptions::MessageFormatException); 00035 virtual ~SEMAINEFeatureMessage(); 00036 00043 std::vector<float> getFeatureVector() 00044 throw(CMSException, semaine::cms::exceptions::MessageFormatException); 00045 00052 std::vector<std::string> getFeatureNames() 00053 throw(CMSException); 00054 00058 bool hasFeatureNames() { return !featureNames.empty(); } 00059 00068 void setFeatureNames(std::vector<std::string> const & names) 00069 throw (semaine::cms::exceptions::MessageFormatException) 00070 { 00071 if (names.size() != features.size()) 00072 { 00073 std::stringstream buf; 00074 buf << "There are " << features.size() << " features but " << names.size() << " feature names"; 00075 throw semaine::cms::exceptions::MessageFormatException(buf.str()); 00076 } 00077 featureNames = names; 00078 } 00079 00080 protected: 00081 std::vector<float> features; 00082 std::vector<std::string> featureNames; 00083 00084 00085 void readFromBytesMessage(const BytesMessage * bm) 00086 throw(CMSException, semaine::cms::exceptions::MessageFormatException); 00087 00088 00089 void readFromTextMessage(const TextMessage * tm) 00090 throw(CMSException); 00091 00092 00093 00094 00095 }; 00096 00097 } // namespace message 00098 } // namespace cms 00099 } // namespace semaine 00100 00101 00102 #endif 00103