31 using classdesc::shared_ptr;
39 typedef std::vector<std::vector<string>>
Data;
43 vector<AssetClass> m_assetClass{noAssetClass, asset, liability, equity};
46 static void markEdited();
47 void _resize(
unsigned rows,
unsigned cols) {
49 for (std::size_t i=0; i<data.size(); ++i) data[i].resize(cols);
50 data.resize(rows, vector<string>(cols));
51 m_assetClass.resize(cols, noAssetClass);
64 cell(1,0)=initialConditions;
76 const vector<AssetClass>&
assetClass()
const {
return m_assetClass;}
77 AssetClass assetClass(std::size_t col)
const;
78 AssetClass assetClass(std::size_t col, AssetClass cls);
82 bool singleEquity()
const;
94 return doubleEntryCompliant &&
95 (assetClass(col)==liability || assetClass(col)==equity);
99 bool initialConditionRow(
unsigned row)
const;
102 bool singularRow(
unsigned row,
unsigned col);
104 std::size_t
rows()
const {
return data.size();}
105 std::size_t
cols()
const {
return data.empty()? 0: data[0].size();}
107 void clear() {data.clear(); m_assetClass.clear(); markEdited();}
108 void resize(
unsigned rows,
unsigned cols){_resize(rows,cols); markEdited();}
118 void insertRow(
unsigned row);
121 void deleteRow(
unsigned row) {data.erase(data.begin()+row);}
123 void insertCol(
unsigned col);
125 void deleteCol(
unsigned col);
128 void moveRow(
int row,
int n);
130 void moveCol(
int col,
int n);
132 void dimension(
unsigned rows,
unsigned cols) {clear(); resize(rows,cols);}
134 string&
cell(
unsigned row,
unsigned col) {
135 if (row>=rows() || col>=cols())
136 _resize(row+1, col+1);
137 if (data[row].size()<=col) data[row].resize(cols());
138 return data[row][col];
140 const string&
cell(
unsigned row,
unsigned col)
const {
141 if (row>=data.size() || col>=data[row].size())
142 throw std::out_of_range(
"Godley table index error");
143 return data[row][col];
146 {
return row>=0 && std::size_t(row)<rows() && col>=0 && std::size_t(col)<cols();}
147 string getCell(
unsigned row,
unsigned col)
const {
148 if (row<rows() && col<cols())
149 return cell(row,col);
153 void setCell(
unsigned row,
unsigned col,
const string& data) {
158 void balanceEquity(
int col);
161 std::vector<std::string> getColumnVariables()
const;
164 std::vector<std::string> getVariables()
const;
170 std::vector<std::string> getColumn(
unsigned col)
const;
173 void setDEmode(
bool doubleEntryCompliant);
175 std::map<std::string,double> rowSumAsMap(
int row)
const;
176 static std::string stringify(
const std::map<std::string,double>&);
179 std::string
rowSum(
int row)
const {
return stringify(rowSumAsMap(row));}
185 void exportToCSV(
const std::string& filename)
const;
188 void orderAssetClasses();
191 void rename(
const std::string& from,
const std::string& to);
193 void renameFlows(
const std::string& from,
const std::string& to);
195 void renameStock(
const std::string& from,
const std::string& to);
200 #include "godleyTable.cd" 201 #include "godleyTable.xcd"
const Data & getData() const
accessor for schema access
bool cellInTable(int row, int col) const
const vector< AssetClass > & assetClass() const
class of each column (used in DE compliant mode)
void exportToLaTeX(std::ostream &f, const GodleyTable &g)
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
void deleteRow(unsigned row)
delete row at row
std::string rowSum(int row) const
return the symbolic sum across a row
bool doubleEntryCompliant
string & cell(unsigned row, unsigned col)
string getCell(unsigned row, unsigned col) const
void resize(unsigned rows, unsigned cols)
void setCell(unsigned row, unsigned col, const string &data)
#define CLASSDESC_ACCESS(type)
const string & cell(unsigned row, unsigned col) const
GodleyAssetClass::AssetClass AssetClass
void dimension(unsigned rows, unsigned cols)
void _resize(unsigned rows, unsigned cols)
std::string savedText
save text in currently highlighted column heading for renaming all variable instances and to enable u...
void exportToCSV(std::ostream &s, const GodleyTable &g)
static const char * initialConditions
bool signConventionReversed(int col) const
The usual mathematical sign convention is reversed in double entry book keeping conventions if the as...
std::vector< std::vector< string > > Data
bool operator==(const GodleyTable &other) const