Result.h revision 10447:a465576671d4
1#ifndef __DSENT_UTIL_RESULT_H__
2#define __DSENT_UTIL_RESULT_H__
3
4#include <iostream>
5#include <vector>
6
7#include "libutil/String.h"
8#include "libutil/Map.h"
9
10namespace DSENT
11{
12    using std::ostream;
13    using std::vector;
14    using LibUtil::Map;
15    using LibUtil::String;
16
17    class Result
18    {
19        public:
20            class SubResult
21            {
22                public:
23                    SubResult(const Result* result_, const String& producer_, double num_results_);
24                    ~SubResult();
25
26                public:
27                    const Result* getResult() const;
28                    const String& getProducer() const;
29                    double getNumResults() const;
30
31                    SubResult* clone() const;
32
33                protected:
34                    SubResult(const SubResult& sub_result_);
35
36                private:
37                    // Pointer to the actual result
38                    const Result* m_result_;
39                    // Name of the instance that produces this result
40                    String m_producer_;
41                    // Number of the times this result should be produce
42                    double m_num_results_;
43            }; // class SubResult
44
45        public:
46            Result();
47            Result(const String& result_name_);
48            virtual ~Result();
49
50        public:
51            // Get the name of result
52            const String& getName() const;
53            // Add a sub result
54            void addSubResult(const Result* sub_result_, const String& result_producer_, double num_results_);
55            // Remove all sub results
56            void removeAllSubResults();
57            // Set the value of a result, not available except for AtomicResult
58            virtual void setValue(double value_);
59            // Set the value of a result, not available except for AtomicResult
60            virtual void addValue(double value_);
61            // Get the value of a result, not available except for AtomicResult
62            virtual double getValue() const;
63            // Loop through all sub results and calculate the sum
64            virtual double calculateSum() const;
65            // Print the result with hierarchy if detail_level_ > 0. Print the sum when detail_level_ <= 0
66            void print(const String& prepend_str_, int detail_level_, ostream& ost_) const;
67            // Print the tree of the results
68            void printHierarchy(const String& prepend_str_, int detail_level_, ostream& ost_) const;
69
70            Result* clone() const;
71
72        protected:
73            Result(const Result& result_);
74            virtual void print(const String& prepend_str_, double num_results_, int detail_level_, ostream& ost_) const;
75
76        private:
77            String m_result_name_;
78            vector<SubResult*> m_sub_results_;
79    }; // class Result
80
81    class AtomicResult : public Result
82    {
83        public:
84            AtomicResult(const String& result_name_, double value_ = 0.0);
85            ~AtomicResult();
86
87        public:
88            void setValue(double value_);
89            void addValue(double value_);
90            double getValue() const;
91            virtual double calculateSum() const;
92            AtomicResult* clone() const;
93
94        protected:
95            AtomicResult(const AtomicResult& atomic_result_);
96            virtual void print(const String& prepend_str_, double num_results_, int detail_level_, ostream& ost_) const;
97
98        private:
99            // Actual value of the result
100            double m_value_;
101    }; // class AtomicResult
102} // namespace DSENT
103
104#endif // __DSENT_UTIL_RESULT_H__
105
106