00001
00002 #ifndef SENDS_CHAN_LIST_HH
00003 #define SENDS_CHAN_LIST_HH
00004 #include <string>
00005 #include <vector>
00006 #include <iosfwd>
00007
00008 namespace sends {
00009
00026 class chan_entry {
00027 public:
00028
00031 enum chan_type {
00032 kUnknown,
00033 kOnline,
00034 kRawData,
00035 kReduced,
00036 kSecondTrend,
00037 kMinuteTrend,
00038 kTypeCount
00039 };
00040
00043 enum data_type {
00044 kByte1,
00045 kInt2,
00046 kInt4,
00047 kInt8,
00048 kReal4,
00049 kReal8,
00050 kComplex8,
00051 kComplex16
00052 };
00053
00058 typedef unsigned long source_count;
00059
00063 typedef unsigned long gps_type;
00064
00065 public:
00075 chan_entry(const std::string& name, chan_type type, long access=0,
00076 data_type dtype=kReal4, double rate=0,
00077 const std::string& source="");
00078
00085 void addSource(const std::string& ftype);
00086
00092 bool available(gps_type t) const;
00093
00098 long getAccess(void) const {return mAccess;}
00099
00102 data_type dtype(void) const {return mDType;}
00103
00106 int data_size(void) const {return getDataSize(mDType);}
00107
00114 static data_type getDataCode(const std::string& str);
00115
00121 static int getDataSize(data_type type);
00122
00128 static std::string getDataString(data_type type);
00129
00134 const std::string& name(void) const {return mName;}
00135
00140 source_count getNSource(void) const;
00141
00147 const std::string& getSource(source_count inx=0) const;
00148
00152 chan_type type(void) const {return mType;}
00153
00160 static chan_type getTypeCode(const std::string& str);
00161
00167 static std::string getTypeString(chan_type type);
00168
00177 bool is_source(const std::string& src) const;
00178
00188 void merge(const chan_entry& ce);
00189
00199 bool operator<(const chan_entry& ent) const;
00200
00207 bool operator==(const chan_entry& ent) const;
00208
00216 bool operator!=(const chan_entry& ent) const;
00217
00222 double rate(void) const;
00223
00224 private:
00225 typedef std::vector<std::string> source_vect;
00226 typedef source_vect::iterator source_iter;
00227 typedef source_vect::const_iterator const_source_iter;
00228 private:
00229 std::string mName;
00230 chan_type mType;
00231 long mAccess;
00232 data_type mDType;
00233 double mRate;
00234 source_vect mSource;
00235 };
00236
00239 std::ostream& operator<<(std::ostream& out, const chan_entry& ent);
00240
00246 class chan_list {
00247 public:
00251 typedef unsigned long chan_index;
00252 public:
00258 chan_list(unsigned long ndef=100000);
00259
00265 chan_index add_channel(const chan_entry& ce);
00266
00269 void clear(void);
00270
00277 std::ostream& dump(std::ostream& out) const;
00278
00281 void enable(void);
00282
00291 chan_index find(const std::string& name, chan_entry::chan_type t) const;
00292
00299 chan_index find(const chan_entry& ent) const;
00300
00308 chan_index find_best(const std::string& name, chan_entry::chan_type t,
00309 double rate, chan_entry::gps_type gps) const;
00310
00316 chan_index lower_bound(const chan_entry& ent) const;
00317
00337 void read(const std::string& file);
00338
00345 void reserve(chan_index nMax);
00346
00350 chan_index size(void) const;
00351
00359 const chan_entry& operator[](chan_index inx) const;
00360 private:
00361 typedef std::vector<chan_entry> chan_vect;
00362
00363 private:
00364 bool list_available;
00365 chan_vect mChanList;
00366 };
00367
00368
00369
00370 inline chan_entry::source_count
00371 chan_entry::getNSource(void) const {
00372 return mSource.size();
00373 }
00374
00375 inline const std::string&
00376 chan_entry::getSource(source_count inx) const {
00377 return mSource[inx];
00378 }
00379
00380 inline bool
00381 chan_entry::operator<(const chan_entry& ent) const {
00382 return (mName < ent.mName) ||
00383 (mName == ent.mName && mType < ent.mType);
00384 }
00385
00386 inline bool
00387 chan_entry::operator==(const chan_entry& ent) const {
00388 return (mName == ent.mName && mType == ent.mType);
00389 }
00390
00391 inline bool
00392 chan_entry::operator!=(const chan_entry& ent) const {
00393 return (mName != ent.mName || mType != ent.mType);
00394 }
00395
00396 inline double
00397 chan_entry::rate(void) const {
00398 return mRate;
00399 }
00400
00401 inline chan_list::chan_index
00402 chan_list::size(void) const {
00403 return mChanList.size();
00404 }
00405
00406 }
00407
00408 #endif // !defined(SENDS_CHAN_LIST_HH)