00001 // Block.h 00002 00003 00004 #ifndef BLOCK_H 00005 #define BLOCK_H 00006 00007 #include <string> 00008 #include <vector> 00009 00010 #include "Predictor.h" 00011 #include "Specimen.h" 00012 00013 namespace Yosokumo 00014 { 00015 00016 /** 00017 * A base class for <code>EmptyBlock</code>, <code>CellBlock</code>, 00018 * <code>PredictorBlock</code>, and <code>SpecimenBlock</code>. The 00019 * <code>Block</code> class is not visible in the API. It is a way to package 00020 * up <code>Cells</code>, <code>Predictors</code> and <code>Specimens</code> 00021 * for transmission to the Yosokumo web service via HTTP, so that HTTP requests 00022 * are never too large. 00023 */ 00024 00025 class Block 00026 { 00027 public: 00028 00029 /** 00030 * Indicates what is stored in the <code>Block</code>, e.g., 00031 * <code>Cells</code>, <code>Predictors</code>, or <code>Specimens</code>. 00032 */ 00033 enum Type 00034 { 00035 /** 00036 * an empty block. 00037 */ 00038 EMPTY, 00039 /** 00040 * a <code>Predictor</code> block. 00041 */ 00042 PREDICTOR, 00043 /** 00044 * a <code>Specimen</code> block. 00045 */ 00046 SPECIMEN, 00047 /** 00048 * a <code>Cell</code> block. 00049 */ 00050 CELL 00051 }; 00052 00053 private: 00054 00055 /** 00056 * The type of the block. 00057 */ 00058 00059 Type type; 00060 00061 /** 00062 * Specifies the study which the block is associated with. 00063 */ 00064 00065 std::string studyIdentifier; 00066 00067 protected: 00068 00069 // An empty block has no need of any of the following, and cell blocks, 00070 // predictor blocks, and specimen blocks each need only one of the 00071 // following. However, this somewhat space-inefficient approach is taken 00072 // anyway, because it means that a Block contains all the data needed by 00073 // each of EmptyBlock, CellBlock, PredictorBlock, and SpecimenBlock, 00074 // which makes reading of blocks in protocol buffer form much easier. 00075 // 00076 // Of course, the first question is why not use a union? Unfortunately 00077 // union members must be POD, so that doesn't work. 00078 00079 /** 00080 * A sequence of <code>Cell</code>. 00081 */ 00082 std::vector<Cell> cellSequence; 00083 00084 /** 00085 * A sequence of <code>Predictor</code>. 00086 */ 00087 std::vector<Predictor> predictorSequence; 00088 00089 /** 00090 * A sequence of <code>Specimen*</code>. 00091 */ 00092 std::vector<Specimen*> specimenSequence; 00093 00094 00095 public: 00096 00097 /** 00098 * Initializes a newly created <code>Block</code> object with default 00099 * attributes. 00100 */ 00101 Block(); 00102 00103 /** 00104 * Initializes a newly created <code>Block</code> object with a study 00105 * identifier. 00106 * 00107 * @param id a study identifier for the block. 00108 */ 00109 Block(std::string id); 00110 00111 /** 00112 * Destructor. 00113 */ 00114 virtual ~Block(); 00115 00116 /** 00117 * Set the type of the block. 00118 * 00119 * @param t the type to assign to the block. 00120 */ 00121 void setType(Type t); 00122 00123 /** 00124 * Return the type of the block. 00125 * 00126 * @return the type of the block. 00127 */ 00128 Type getType() const; 00129 00130 /** 00131 * Set the study identifier of the block. 00132 * 00133 * @param id the identifier to assign to the block. 00134 */ 00135 void setStudyIdentifier(std::string id); 00136 00137 /** 00138 * Return the study identifier of the block. 00139 * 00140 * @return the study identifier of the block. 00141 */ 00142 std::string getStudyIdentifier() const; 00143 00144 /** 00145 * Return the block as a string. 00146 * 00147 * @return the block as a string. 00148 */ 00149 virtual std::string toString(); 00150 00151 }; // end class Block 00152 00153 } // end namespace Yosokumo 00154 00155 #endif // BLOCK_H 00156 00157 // end Block.h