Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / idlist.h @ a3be1d55

History | View | Annotate | Download (5.22 KB)

1
//=========================================================================
2
//  IDLIST.H - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga, Tamas Borbely
7
//
8
//=========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16

    
17
#ifndef _IDLIST_H_
18
#define _IDLIST_H_
19

    
20
#include <vector>
21
#include <exception>
22
#include <stdexcept>
23
#include "scavedefs.h" // int64
24

    
25
NAMESPACE_BEGIN
26

    
27
class ResultFileManager;
28

    
29
/**
30
 * Result ID -- identifies a scalar or a vector in a ResultFileManager
31
 */
32
typedef int64 ID;
33

    
34

    
35
/**
36
 * Stores a set of unique IDs. Order is not important, and may occasionally
37
 * change (after merge(), substract() or intersect()).
38
 *
39
 * Beware: Copy ctor implements transfer-of-ownership semantics!
40
 */
41
class SCAVE_API IDList
42
{
43
    private:
44
        friend class ResultFileManager;
45
        typedef std::vector<ID> V;
46
        V *v;
47

    
48
        void operator=(const IDList&); // undefined, to prevent calling it
49
        void checkV() const {if (!v) throw std::runtime_error("this is a zombie IDList");}
50
        void uncheckedAdd(ID id) {v->push_back(id);} // doesn't check if already in there
51
        void discardDuplicates();
52
        void checkIntegrity(ResultFileManager *mgr) const;
53
        void checkIntegrityAllScalars(ResultFileManager *mgr) const;
54
        void checkIntegrityAllVectors(ResultFileManager *mgr) const;
55
        void checkIntegrityAllHistograms(ResultFileManager *mgr) const;
56

    
57
        template <class T> void sortBy(ResultFileManager *mgr, bool ascending, T& comparator);
58
        template <class T> void sortScalarsBy(ResultFileManager *mgr, bool ascending, T& comparator);
59
        template <class T> void sortVectorsBy(ResultFileManager *mgr, bool ascending, T& comparator);
60
        template <class T> void sortHistogramsBy(ResultFileManager *mgr, bool ascending, T& comparator);
61

    
62
    public:
63
        IDList()  {v = new V;}
64
        IDList(unsigned int sz)  {v = new V(sz);}
65
        IDList(const IDList& ids); // transfer of ownership semantics!
66
        ~IDList()  {delete v;}
67
        int size() const  {checkV(); return (int)v->size();}
68
        bool isEmpty() const  {checkV(); return v->empty();}
69
        void clear()  {checkV(); v->clear();}
70
        void set(const IDList& ids);
71
        void add(ID x);
72
        ID get(int i) const {checkV(); return v->at(i);} // at() includes bounds check
73
        // void set(int i, ID x);
74
        void erase(int i);
75
        void substract(ID x); // this -= {x}
76
        int indexOf(ID x) const;
77
        void merge(IDList& ids);  // this += ids
78
        void substract(IDList& ids);  // this -= ids
79
        void intersect(IDList& ids);  // this = intersection(this,ids)
80
        IDList getSubsetByIndices(int *array, int n) const;
81
        IDList dup() const;
82
        int getItemTypes() const;  // SCALAR, VECTOR or their binary OR
83
        bool areAllScalars() const;
84
        bool areAllVectors() const;
85
        bool areAllHistograms() const;
86
        // sorting
87
        // TODO: there's a duplication between vector and histogram sorting due to not having a proper superclass with the statistics inside
88
        void sortByFileAndRun(ResultFileManager *mgr, bool ascending);
89
        void sortByRunAndFile(ResultFileManager *mgr, bool ascending);
90
        void sortByDirectory(ResultFileManager *mgr, bool ascending);
91
        void sortByFileName(ResultFileManager *mgr, bool ascending);
92
        void sortByRun(ResultFileManager *mgr, bool ascending);
93
        void sortByModule(ResultFileManager *mgr, bool ascending);
94
        void sortByName(ResultFileManager *mgr, bool ascending);
95
        void sortScalarsByValue(ResultFileManager *mgr, bool ascending);
96
        void sortVectorsByVectorId(ResultFileManager *mgr, bool ascending);
97
        void sortVectorsByLength(ResultFileManager *mgr, bool ascending);
98
        void sortVectorsByMean(ResultFileManager *mgr, bool ascending);
99
        void sortVectorsByStdDev(ResultFileManager *mgr, bool ascending);
100
        void sortVectorsByMin(ResultFileManager *mgr, bool ascending);
101
        void sortVectorsByMax(ResultFileManager *mgr, bool ascending);
102
        void sortVectorsByVariance(ResultFileManager *mgr, bool ascending);
103
        void sortVectorsByStartTime(ResultFileManager *mgr, bool ascending);
104
        void sortVectorsByEndTime(ResultFileManager *mgr, bool ascending);
105
        void sortHistogramsByLength(ResultFileManager *mgr, bool ascending);
106
        void sortHistogramsByMean(ResultFileManager *mgr, bool ascending);
107
        void sortHistogramsByStdDev(ResultFileManager *mgr, bool ascending);
108
        void sortHistogramsByMin(ResultFileManager *mgr, bool ascending);
109
        void sortHistogramsByMax(ResultFileManager *mgr, bool ascending);
110
        void sortHistogramsByVariance(ResultFileManager *mgr, bool ascending);
111
        void sortByRunAttribute(ResultFileManager *mgr, const char* runAttr, bool ascending);
112
        void reverse();
113
        void toByteArray(char *array, int n) const;
114
        void fromByteArray(char *array, int n);
115
};
116

    
117
NAMESPACE_END
118

    
119

    
120
#endif
121

    
122