Feature.h

Go to the documentation of this file.
00001 
00027 #ifndef _FEATURE_H
00028 #define _FEATURE_H
00029 
00030 #include "../util/defines.h"
00031 
00032 #include <time.h>
00033 #include <assert.h>
00034 #ifndef _SYMBIAN
00035 #endif
00036 
00038 
00040 #if defined(_WINDOWS) || defined(_WIN32_WCE)
00041 # ifdef _FEATURE_EXPORT
00042 #  define FEATURE_EXPORT __declspec(dllexport)
00043 #  ifdef _FEATURE_EXPORT_CLASS
00044 #   define FEATURE_EXPORT_CLASS __declspec(dllexport)
00045 #  endif // _FEATURE_EXPORT_CLASS
00046 # else // _FEATURE_EXPORT
00047 #  define FEATURE_EXPORT __declspec(dllimport)
00048 #  ifdef _FEATURE_EXPORT_CLASS
00049 #   define FEATURE_EXPORT_CLASS __declspec(dllimport)
00050 #  endif // _FEATURE_EXPORT_CLASS
00051 # endif // _FEATURE_EXPORT
00052 #elif defined(_LINUX) // _WINDOWS or _WIN32_WCE
00053 # define FEATURE_EXPORT
00054 # define FEATURE_EXPORT_CLASS
00055 #elif defined(_SYMBIAN)
00056 # ifdef _FEATURE_EXPORT
00057 #  define FEATURE_EXPORT EXPORT_C
00058 #  ifdef _FEATURE_EXPORT_CLASS
00059 #   define FEATURE_EXPORT_CLASS EXPORT_C
00060 #  endif // _FEATURE_EXPORT_CLASS
00061 # else // _FEATURE_EXPORT
00062 #  define FEATURE_EXPORT IMPORT_C
00063 #  ifdef _FEATURE_EXPORT_CLASS
00064 #   define FEATURE_EXPORT_CLASS IMPORT_C
00065 #  endif // _FEATURE_EXPORT_CLASS
00066 # endif // _FEATURE_EXPORT
00067 #endif // _WINDOWS or _WIN32_WCE
00068 
00069 #ifndef FEATURE_EXPORT_CLASS
00070 # define FEATURE_EXPORT_CLASS
00071 #endif
00072 
00073 
00074 #ifdef _SYMBIAN
00075 // for Symbian OS, static variables are not supported in DLLs, we have to use Thread Local Storage for that
00076 /*
00077 #define EXPORT_FEATURE(provider) \
00078         void INIT_EXPORT library_initialize() { Dll::SetTls(NULL); } \
00079         void FINI_EXPORT library_finalize() { if (Dll::Tls() != NULL) delete (provider*) (Dll::Tls()); } \
00080         extern "C" FEATURE_EXPORT FeatureProvider* getProvider(providerparams &params) { if (Dll::Tls() == NULL) Dll::SetTls((TAny*) new provider(params)); return (provider*) Dll::Tls(); }*/
00081 // there is no support for loading DLLs by now anyways
00082 #define EXPORT_FEATURE(provider)
00083 #else // _SYMBIAN
00084 
00094 #define EXPORT_FEATURE(provider) \
00095  \
00096         static provider *fp; \
00097         void INIT_EXPORT library_initialize() { fp = NULL; } \
00098         void FINI_EXPORT library_finalize() { if (fp != NULL) delete fp; } \
00099  \
00105         extern "C" FEATURE_EXPORT FeatureProvider* getProvider(providerparams &params) { if (fp == NULL) fp = new provider(params); return fp; }
00106 #endif // _SYMBIAN
00107 
00108 class Feature;
00109 
00124 typedef parametermap providerparams;
00125 
00127 typedef parametermap featureparams;
00128 
00130 typedef pair<time_t, Feature*> aggregatefeature;
00131 
00133 typedef list<aggregatefeature> aggregatelist;
00134 
00136 typedef map<unsigned long, double> membershiplist;
00137 
00145 extern "C" {
00147         void library_initialize();
00149         void library_finalize();
00150 }
00152 
00172 class Feature {
00173         public:
00175                 typedef enum { boolean, nominal, ordinal, numerical_discrete, numerical_continuous } FeatureType;
00176 
00177         protected:
00192                 const bool externalize;
00193 
00201                 Feature(bool ext) : externalize(ext) {}
00202 
00210                 Feature() : externalize(false) {}
00211 
00212         public:
00220                 virtual ~Feature() {}
00221 
00227                 virtual FeatureType getType() const = 0;
00228 
00234                 virtual const string getName() const = 0;
00235 
00246                 virtual double getPosition() const = 0;
00247 
00255                 bool isExternalizable() { return externalize; }
00256 
00266                 virtual double getDistance(Feature *f) const = 0;
00267 
00281                 virtual void moveTowards(Feature *f, double factor) = 0;
00282 
00289                 virtual Feature* clone() const = 0;
00290 
00296                 virtual string serialize() const = 0;
00297 
00303                 virtual void unserialize(string value) = 0;
00304 
00310                 virtual void aggregate(aggregatelist samples) = 0;
00311 
00312 #if _DEBUG_FEATURES
00313 
00314                 virtual string toString() const = 0;
00315 #endif
00316 };
00317 
00326 class PersistantFeature : public Feature {
00327         private:
00335                 bool valid;
00336 
00337         protected:
00347                 PersistantFeature() : Feature(true) { valid = true; }
00348 
00349         public:
00356                 virtual featureparams write() const = 0;
00357                 
00366                 virtual void read(featureparams *param) = 0;
00367 
00375                 void invalidate() { valid = false; }
00376                 
00378                 void validate() { valid = true; }
00379                 
00386                 bool isValid() { return valid; }
00387 };
00388 
00401 typedef vector<Feature*> featurevector;
00402 
00418 class FeatureProvider {
00419         private:
00421                 stringvector *features;
00423                 string name;
00424 
00425         protected:
00434                 FeatureProvider(string name, stringvector *features) {
00435                         this->name = name;
00436                         this->features = features;
00437                 }
00438                 
00439         public:
00447                 virtual ~FeatureProvider() {}
00448 
00458                 virtual Feature* getFeature(string name) const = 0;
00459 
00472                 virtual Feature* getSample(string name) const = 0;
00473 
00485                 virtual void nextSample(clock_t checkpoint) = 0;
00486 
00492                 string getName() const
00493                 {
00494                         return name;
00495                 }
00496 
00502                 stringvector* getFeatureList() const
00503                 {
00504                         return features;
00505                 }
00506 };
00507 
00514 typedef FeatureProvider* (*getProvider_t) (const providerparams &params);
00515 
00516 #endif // _FEATURE_H

Generated on Mon Jun 5 10:20:42 2006 for Intelligence.kdevelop by  doxygen 1.4.6