Result.h (10447:a465576671d4) Result.h (10448:bc1a3b7ab5ef)
1/* Copyright (c) 2012 Massachusetts Institute of Technology
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to deal
5 * in the Software without restriction, including without limitation the rights
6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 * copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 * THE SOFTWARE.
20 */
21
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
22#ifndef __DSENT_UTIL_RESULT_H__
23#define __DSENT_UTIL_RESULT_H__
24
25#include <iostream>
26#include <vector>
27
28#include "libutil/String.h"
29#include "libutil/Map.h"
30
31namespace DSENT
32{
33 using std::ostream;
34 using std::vector;
35 using LibUtil::Map;
36 using LibUtil::String;
37
38 class Result
39 {
40 public:
41 class SubResult
42 {
43 public:
44 SubResult(const Result* result_, const String& producer_, double num_results_);
45 ~SubResult();
46
47 public:
48 const Result* getResult() const;
49 const String& getProducer() const;
50 double getNumResults() const;
51
52 SubResult* clone() const;
53
54 protected:
55 SubResult(const SubResult& sub_result_);
56
57 private:
58 // Pointer to the actual result
59 const Result* m_result_;
60 // Name of the instance that produces this result
61 String m_producer_;
62 // Number of the times this result should be produce
63 double m_num_results_;
64 }; // class SubResult
65
66 public:
67 Result();
68 Result(const String& result_name_);
69 virtual ~Result();
70
71 public:
72 // Get the name of result
73 const String& getName() const;
74 // Add a sub result
75 void addSubResult(const Result* sub_result_, const String& result_producer_, double num_results_);
76 // Remove all sub results
77 void removeAllSubResults();
78 // Set the value of a result, not available except for AtomicResult
79 virtual void setValue(double value_);
80 // Set the value of a result, not available except for AtomicResult
81 virtual void addValue(double value_);
82 // Get the value of a result, not available except for AtomicResult
83 virtual double getValue() const;
84 // Loop through all sub results and calculate the sum
85 virtual double calculateSum() const;
86 // Print the result with hierarchy if detail_level_ > 0. Print the sum when detail_level_ <= 0
87 void print(const String& prepend_str_, int detail_level_, ostream& ost_) const;
88 // Print the tree of the results
89 void printHierarchy(const String& prepend_str_, int detail_level_, ostream& ost_) const;
90
91 Result* clone() const;
92
93 protected:
94 Result(const Result& result_);
95 virtual void print(const String& prepend_str_, double num_results_, int detail_level_, ostream& ost_) const;
96
97 private:
98 String m_result_name_;
99 vector<SubResult*> m_sub_results_;
100 }; // class Result
101
102 class AtomicResult : public Result
103 {
104 public:
105 AtomicResult(const String& result_name_, double value_ = 0.0);
106 ~AtomicResult();
107
108 public:
109 void setValue(double value_);
110 void addValue(double value_);
111 double getValue() const;
112 virtual double calculateSum() const;
113 AtomicResult* clone() const;
114
115 protected:
116 AtomicResult(const AtomicResult& atomic_result_);
117 virtual void print(const String& prepend_str_, double num_results_, int detail_level_, ostream& ost_) const;
118
119 private:
120 // Actual value of the result
121 double m_value_;
122 }; // class AtomicResult
123} // namespace DSENT
124
125#endif // __DSENT_UTIL_RESULT_H__
126