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 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 127