00001 // PredictorBlock.h 00002 00003 #ifndef PREDICTORBLOCK_H 00004 #define PREDICTORBLOCK_H 00005 00006 #include "Block.h" 00007 #include "Predictor.h" 00008 00009 #include <vector> 00010 #include <list> 00011 #include <iostream> 00012 #include <sstream> 00013 00014 namespace Yosokumo 00015 { 00016 00017 /** 00018 * Represents a block of <code>Predictors</code>. 00019 */ 00020 class PredictorBlock : public Block 00021 { 00022 // At present the predictorSequence list is implemented as a 00023 // vector<Predictor> because this implementation has O(1) performance 00024 // for all three of "get", "add", and "next". The latter is used to 00025 // iterate over the list, and thus we do not want it to be expensive. 00026 // The "add" method appends to the end of the list. -- Essentially, we 00027 // want an array which can grow in size. 00028 00029 // The sequence is defined in Block.h 00030 00031 public: 00032 00033 // Constructors and destructor 00034 00035 /** 00036 * Initializes a newly created <code>PredictorBlock</code> object with 00037 * default attributes. 00038 */ 00039 PredictorBlock(); 00040 00041 /** 00042 * Initializes a newly created <code>PredictorBlock</code> object with 00043 * a study identifier. 00044 * 00045 * @param id a study identifier for the block. 00046 */ 00047 PredictorBlock(std::string id); 00048 00049 /** 00050 * Initializes a newly created <code>PredictorBlock</code> object with the 00051 * predictor vector specified by the input parameters. 00052 * 00053 * @param begin an iterator specifying the beginning of the predictor 00054 * vector. 00055 * @param end an iterator specifying the end of the predictor 00056 * vector. 00057 */ 00058 PredictorBlock( 00059 std::vector<Predictor>::iterator begin, 00060 std::vector<Predictor>::iterator end); 00061 00062 /** 00063 * Initializes a newly created <code>PredictorBlock</code> object with the 00064 * predictor list specified by the input parameters. 00065 * 00066 * @param begin an iterator specifying the beginning of the predictor list. 00067 * @param end an iterator specifying the end of the predictor list. 00068 */ 00069 PredictorBlock( 00070 std::list<Predictor>::iterator begin, 00071 std::list<Predictor>::iterator end); 00072 00073 /** 00074 * Initializes a newly created <code>PredictorBlock</code> object with the 00075 * study identifier and the predictor vector specified by the input 00076 * parameters. 00077 * 00078 * @param id a study identifier for the block. 00079 * @param begin an iterator specifying the beginning of the predictor 00080 * vector. 00081 * @param end an iterator specifying the end of the predictor 00082 * vector. 00083 */ 00084 PredictorBlock( 00085 std::string id, 00086 std::vector<Predictor>::iterator begin, 00087 std::vector<Predictor>::iterator end); 00088 00089 /** 00090 * Initializes a newly created <code>PredictorBlock</code> object with the 00091 * study identifier and the predictor list specified by the input 00092 * parameters. 00093 * 00094 * @param id a study identifier for the block. 00095 * @param begin an iterator specifying the beginning of the predictor list. 00096 * @param end an iterator specifying the end of the predictor list. 00097 */ 00098 PredictorBlock( 00099 std::string id, 00100 std::list<Predictor>::iterator begin, 00101 std::list<Predictor>::iterator end); 00102 00103 /** 00104 * Destructor. 00105 */ 00106 virtual ~PredictorBlock(); 00107 00108 private: 00109 00110 /** 00111 * Copy constructor - NOT IMPLEMENTED. 00112 */ 00113 PredictorBlock(const PredictorBlock &rhs); 00114 00115 /** 00116 * Assignment operator - NOT IMPLEMENTED. 00117 */ 00118 PredictorBlock& operator=(const PredictorBlock& rhs); 00119 00120 public: 00121 00122 // Access to the predictor sequence 00123 00124 /** 00125 * Add a <code>Predictor</code> to the block. The predictor parameter is 00126 * appended to the end of the predictor sequence. 00127 * 00128 * @param predictor the <code>Predictor</code> to add to the block. 00129 */ 00130 void addPredictor(const Predictor &predictor); 00131 00132 /** 00133 * Add a collection of <code>Predictors</code> to the block. The 00134 * <code>Predictors</code> in the vector specified by the parameters 00135 * are appended to the end of the predictor sequence. 00136 * 00137 * @param begin an iterator specifying the beginning of the predictor 00138 * vector to add to the block. 00139 * @param end an iterator specifying the end of the predictor 00140 * vector to add to the block. 00141 * 00142 * @return true if and only if the predictor sequence changes. 00143 */ 00144 bool addPredictors( 00145 std::vector<Predictor>::iterator begin, 00146 std::vector<Predictor>::iterator end); 00147 00148 /** 00149 * Add a collection of <code>Predictors</code> to the block. The 00150 * <code>Predictors</code> in the list specified by the parameters 00151 * are appended to the end of the predictor sequence. 00152 * 00153 * @param begin an iterator specifying the beginning of the predictor 00154 * list to add to the block. 00155 * @param end an iterator specifying the end of the predictor 00156 * list to add to the block. 00157 * 00158 * @return true if and only if the predictor sequence changes. 00159 */ 00160 bool addPredictors( 00161 std::list<Predictor>::iterator begin, 00162 std::list<Predictor>::iterator end); 00163 00164 /** 00165 * Remove predictors from the end of the block. The specified number of 00166 * predictors are removed from the end of the predictor sequence. 00167 * 00168 * @param numPredictorsToRemove is the number of predictors to remove 00169 * from the end of the block. If this value is zero no 00170 * predictors are removed. If this value exceeds the number 00171 * of predictors in the block, then all predictors are removed. 00172 * 00173 * @return true if and only if the sequence is changed. 00174 */ 00175 bool removePredictors(uint64_t numPredictorsToRemove); 00176 00177 00178 /** 00179 * Return a predictor from the block. This makes it possible to iterate 00180 * over all predictors in the sequence like this: 00181 * <pre> 00182 * for (uint64_t i = 0; i < predictorSequence.size(); ++i) 00183 * { 00184 * Predictor c = predictorSequence.getPredictor(i) 00185 * process predictor c 00186 * } 00187 * </pre> 00188 * 00189 * @param index specifying the predictor of the 0-based block. 00190 * 00191 * @return the <code>Predictor</code> at the location specified by the 00192 * index. 00193 */ 00194 Predictor getPredictor(uint64_t index) const; 00195 00196 00197 /** 00198 * Remove all predictors from the block. After a call of this method, 00199 * the sequence is empty, i.e., it contains no predictors. 00200 * 00201 */ 00202 void clearPredictors(); 00203 00204 /** 00205 * Return the number of predictors in the block. 00206 * 00207 * @return the number of predictors in the block. 00208 */ 00209 uint64_t size() const; 00210 00211 /** 00212 * Return <code>true</code> if the block contains no predictors. 00213 * 00214 * @return <code>true</code> if the block contains no predictors. 00215 * <code>false</code> otherwise. 00216 */ 00217 bool isEmpty() const; 00218 00219 00220 // Utility 00221 00222 /** 00223 * Return a string representation of this <code>PredictorBlock</code>. 00224 * 00225 * @return the string representation of this <code>PredictorBlock</code>. 00226 */ 00227 virtual std::string toString(); 00228 00229 }; // end class PredictorBlock 00230 00231 } // end namespace Yosokumo 00232 00233 /** Output stream insertion operator. 00234 * 00235 * @param os the output stream. 00236 * @param p the <code>PredictorBlock</code> to insert in the stream. 00237 * 00238 * @return the output stream. 00239 */ 00240 std::ostream &operator<<(std::ostream &os, Yosokumo::PredictorBlock &p); 00241 00242 00243 /** String stream insertion operator. 00244 * 00245 * @param s the string stream. 00246 * @param p the <code>PredictorBlock</code> to insert in the stream. 00247 * 00248 * @return the string stream. 00249 */ 00250 std::stringstream &operator<<(std::stringstream &s, Yosokumo::PredictorBlock &p); 00251 00252 #endif // PREDICTORBLOCK_H 00253 00254 // end PredictorBlock.h