00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(NXS_CXX_DISCRETE_MATRIX_H)
00022 #define NXS_CXX_DISCRETE_MATRIX_H
00023
00024 #include <string>
00025 #include <vector>
00026 #include "ncl/nxsdefs.h"
00027 #include "ncl/nxsallocatematrix.h"
00028 #include "ncl/nxscharactersblock.h"
00029 #include "ncl/nxscdiscretematrix.h"
00030
00036 class NxsCXXDiscreteMatrix
00037 {
00038 public:
00039 NxsCXXDiscreteMatrix()
00040 {
00041 Initialize(0L, false);
00042 }
00043 NxsCXXDiscreteMatrix(const NxsCDiscreteMatrix & );
00044 NxsCXXDiscreteMatrix(const NxsCharactersBlock & cb, bool convertGapsToMissing);
00045
00046 void Initialize(const NxsCharactersBlock * cb, bool convertGapsToMissing);
00047
00048 const NxsCDiscreteMatrix & getConstNativeC() const
00049 {
00050 return nativeCMatrix;
00051 }
00052
00053 NxsCDiscreteMatrix & getNativeC()
00054 {
00055 return nativeCMatrix;
00056 }
00057
00058 unsigned getNChar() const
00059 {
00060 return nativeCMatrix.nChar;
00061 }
00062
00063 unsigned getNTax() const
00064 {
00065 return nativeCMatrix.nTax;
00066 }
00067
00068 unsigned getNStates() const
00069 {
00070 return nativeCMatrix.nStates;
00071 }
00072
00073 const char * getSymbolsList() const
00074 {
00075 return nativeCMatrix.symbolsList;
00076 }
00077
00078 const std::vector<int8_t> &getStateList() const
00079 {
00080 return stateListAlias;
00081 }
00082
00083 const std::vector<unsigned> &getStateListPos() const
00084 {
00085 return stateListPosAlias;
00086 }
00087
00088 const NxsCDiscreteStateSet *getRow(unsigned i) const
00089 {
00090 NCL_ASSERT(i < nativeCMatrix.nTax);
00091 return nativeCMatrix.matrix[i];
00092 }
00093
00094 const std::vector<int8_t> getRowAsVector(unsigned i) const
00095 {
00096 NCL_ASSERT(i < nativeCMatrix.nTax);
00097 std::vector<int8_t> v;
00098 for (unsigned j = 0; j < nativeCMatrix.nChar; j++)
00099 {
00100 v.push_back(nativeCMatrix.matrix[i][j]);
00101 }
00102 return v;
00103 }
00104
00105 const NxsCDiscreteStateSet * const * getMatrix() const
00106 {
00107 return nativeCMatrix.matrix;
00108 }
00109
00110 const int getDatatype() const
00111 {
00112 return (int)nativeCMatrix.datatype;
00113 }
00114
00115 bool hasWeights() const
00116 {
00117 return hasIntWeights() || hasDblWeights();
00118 }
00119
00120 bool hasIntWeights() const
00121 {
00122 return !(intWts.empty());
00123 }
00124
00125 bool hasDblWeights() const
00126 {
00127 return !(dblWts.empty());
00128 }
00129
00130 std::vector<int> & getIntWeights()
00131 {
00132 return intWts;
00133 }
00134
00135 std::vector<double> & getDblWeights()
00136 {
00137 return dblWts;
00138 }
00139
00140 const std::vector<int> & getIntWeightsConst() const
00141 {
00142 return intWts;
00143 }
00144
00145 const std::vector<double> & getDblWeightsConst() const
00146 {
00147 return dblWts;
00148 }
00149
00150 const std::set<unsigned> & getExcludedCharIndices() const
00151 {
00152 return activeExSet;
00153 }
00154
00155 std::vector<unsigned> getExcludedCharIndicesAsVector() const
00156 {
00157 return std::vector<unsigned>(activeExSet.begin(), activeExSet.end());
00158 }
00159
00160 private:
00161 typedef ScopedTwoDMatrix<NxsCDiscreteStateSet> ScopedStateSetTwoDMatrix;
00162
00163 NxsCDiscreteMatrix nativeCMatrix;
00164 std::string symbolsStringAlias;
00165 ScopedStateSetTwoDMatrix matrixAlias;
00166 std::vector<NxsCDiscreteState_t> stateListAlias;
00167 std::vector<unsigned> stateListPosAlias;
00168 std::vector<int> intWts;
00169 std::vector<double> dblWts;
00170 std::set<unsigned> activeExSet;
00171 NxsCXXDiscreteMatrix(const NxsCXXDiscreteMatrix &);
00172 NxsCXXDiscreteMatrix & operator=(const NxsCXXDiscreteMatrix &);
00173 };
00174
00175 #endif // NXS_CXX_DISCRETE_MATRIX_H