nidas  v1.2-1520
SortedSampleSet.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2005, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 #ifndef NIDAS_CORE_SORTEDSAMPLESET_H
27 #define NIDAS_CORE_SORTEDSAMPLESET_H
28 
29 #include "Sample.h"
30 
31 #include <set>
32 
33 namespace nidas { namespace core {
34 
39 public:
43  bool operator() (const Sample* x, const Sample *y) const {
44  return x->getTimeTag() < y->getTimeTag();
45  }
46 };
47 
60 public:
64  bool operator() (const Sample* x, const Sample *y) const {
65  if (x->getTimeTag() > y->getTimeTag()) return false;
66  if (x->getTimeTag() == y->getTimeTag()) {
67  if (x->getId() > y->getId()) return false;
68  if (x->getId() == y->getId())
69  return x->getDataLength() < y->getDataLength();
70  }
71  return true;
72  }
73 };
74 
81 public:
85  bool operator() (const Sample* x, const Sample *y) const {
86  if (x->getTimeTag() > y->getTimeTag()) return false;
87  if (x->getTimeTag() == y->getTimeTag()) {
88  if (x->getId() > y->getId()) return false;
89  if (x->getId() == y->getId()) {
90  if (x->getDataLength() > y->getDataLength()) return false;
91  if (x->getDataLength() == y->getDataLength()) {
92  // compare the data
93  return ::memcmp(x->getConstVoidDataPtr(),
94  y->getConstVoidDataPtr(),x->getDataLength()) < 0;
95  }
96  }
97  }
98  return true;
99  }
100 };
101 
107 typedef std::multiset<const Sample*,SampleTimetagComparator> SortedSampleSet;
108 
118 typedef std::set<const Sample*,SampleHeaderComparator> SortedSampleSet2;
119 
120 typedef std::set<const Sample*,FullSampleComparator> SortedSampleSet3;
121 
122 }} // namespace nidas namespace core
123 
124 #endif
virtual unsigned int getDataLength() const =0
Get the number of elements in data portion of sample.
Comparator of pointers to Samples, does the same checks as SampleHeaderComparator, but in addition, if two samples compare as equal, then compares their data.
Definition: SortedSampleSet.h:80
bool operator()(const Sample *x, const Sample *y) const
Return true if x is less than y.
Definition: SortedSampleSet.h:64
std::multiset< const Sample *, SampleTimetagComparator > SortedSampleSet
A multiset for storing samples sorted by timetag.
Definition: SortedSampleSet.h:107
virtual const void * getConstVoidDataPtr() const =0
Get a const void* pointer to the data portion of the sample.
dsm_time_t getTimeTag() const
Time-tag in non-leap microseconds since Jan 1, 1970 00:00 GMT.
Definition: Sample.h:205
dsm_sample_id_t getId() const
Get the id portion of the sample header.
Definition: Sample.h:217
bool operator()(const Sample *x, const Sample *y) const
Return true if x is less than y.
Definition: SortedSampleSet.h:43
Sample time tag comparator.
Definition: SortedSampleSet.h:38
Interface to a data sample.
Definition: Sample.h:189
std::set< const Sample *, FullSampleComparator > SortedSampleSet3
Definition: SortedSampleSet.h:120
std::set< const Sample *, SampleHeaderComparator > SortedSampleSet2
A set for storing samples sorted by the timetag, id and data length.
Definition: SortedSampleSet.h:118
Timetag and Id comparator of pointers to Samples: if two timetags are the same, then compare Ids...
Definition: SortedSampleSet.h:59
bool operator()(const Sample *x, const Sample *y) const
Return true if x is less than y.
Definition: SortedSampleSet.h:85