00001 /* 00002 * This program is free software; you can redistribute it and/or modify 00003 * it under the terms of the GNU General Public License as published by 00004 * the Free Software Foundation; either version 3 of the License, or 00005 * (at your option) any later version. 00006 * 00007 * Written (W) 1999-2009 Soeren Sonnenburg 00008 * Written (W) 1999-2008 Gunnar Raetsch 00009 * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society 00010 */ 00011 00012 #ifndef _CCOMBINEDFEATURES__H__ 00013 #define _CCOMBINEDFEATURES__H__ 00014 00015 #include <shogun/features/Features.h> 00016 #include <shogun/lib/List.h> 00017 00018 namespace shogun 00019 { 00020 class CFeatures; 00021 class CList; 00022 class CListElement; 00023 00031 class CCombinedFeatures : public CFeatures 00032 { 00033 void init(void); 00034 00035 public: 00037 CCombinedFeatures(); 00039 CCombinedFeatures(const CCombinedFeatures& orig); 00040 00045 virtual CFeatures* duplicate() const; 00046 00048 virtual ~CCombinedFeatures(); 00049 00054 inline virtual EFeatureType get_feature_type() 00055 { 00056 return F_UNKNOWN; 00057 } 00058 00063 inline virtual EFeatureClass get_feature_class() 00064 { 00065 return C_COMBINED; 00066 } 00067 00072 inline virtual int32_t get_num_vectors() const 00073 { 00074 return num_vec; 00075 } 00076 00081 virtual int32_t get_size() 00082 { 00083 CFeatures* f=(CFeatures*) feature_list 00084 ->get_current_element(); 00085 if (f) 00086 { 00087 int32_t s=f->get_size(); 00088 SG_UNREF(f) 00089 return s; 00090 } 00091 else 00092 return 0; 00093 } 00094 00096 void list_feature_objs(); 00097 00103 bool check_feature_obj_compatibility(CCombinedFeatures* comb_feat); 00104 00109 inline CFeatures* get_first_feature_obj() 00110 { 00111 return (CFeatures*) feature_list->get_first_element(); 00112 } 00113 00119 inline CFeatures* get_first_feature_obj(CListElement*& current) 00120 { 00121 return (CFeatures*) feature_list->get_first_element(current); 00122 } 00123 00128 inline CFeatures* get_next_feature_obj() 00129 { 00130 return (CFeatures*) feature_list->get_next_element(); 00131 } 00132 00138 inline CFeatures* get_next_feature_obj(CListElement*& current) 00139 { 00140 return (CFeatures*) feature_list->get_next_element(current); 00141 } 00142 00147 inline CFeatures* get_last_feature_obj() 00148 { 00149 return (CFeatures*) feature_list->get_last_element(); 00150 } 00151 00157 inline bool insert_feature_obj(CFeatures* obj) 00158 { 00159 ASSERT(obj); 00160 int32_t n=obj->get_num_vectors(); 00161 00162 if (num_vec>0 && n!=num_vec) 00163 SG_ERROR("Number of feature vectors does not match (expected %d, obj has %d)\n", num_vec, n); 00164 00165 num_vec=n; 00166 return feature_list->insert_element(obj); 00167 } 00168 00174 inline bool append_feature_obj(CFeatures* obj) 00175 { 00176 ASSERT(obj); 00177 int32_t n=obj->get_num_vectors(); 00178 00179 if (num_vec>0 && n!=num_vec) 00180 SG_ERROR("Number of feature vectors does not match (expected %d, obj has %d)\n", num_vec, n); 00181 00182 num_vec=n; 00183 return feature_list->append_element(obj); 00184 } 00185 00190 inline bool delete_feature_obj() 00191 { 00192 CFeatures* f=(CFeatures*)feature_list->delete_element(); 00193 if (f) 00194 { 00195 SG_UNREF(f); 00196 return true; 00197 } 00198 else 00199 return false; 00200 } 00201 00206 inline int32_t get_num_feature_obj() 00207 { 00208 return feature_list->get_num_elements(); 00209 } 00210 00212 inline virtual const char* get_name() const { return "CombinedFeatures"; } 00213 00214 protected: 00216 CList* feature_list; 00217 00221 int32_t num_vec; 00222 }; 00223 } 00224 #endif