25 #include "assetClass.rcd" 26 #include "godleyTable.rcd" 39 if (row>=
rows())
return false;
40 const string& label=
cell(row,0);
44 for (i=0; isspace(label[i]); ++i);
46 for (j=0; j<initialConditionsSz && i<label.size() &&
48 return j==initialConditionsSz;
53 for (
size_t c=0; c<
cols(); ++c)
54 if (c!=col && !
cell(row, c).empty())
74 for (
unsigned row=0; row<
data.size(); ++row)
76 for (
size_t i=
data[row].size(); i<col; ++i)
77 data[row].insert(
data[row].end(),
"");
78 data[row].insert(
data[row].begin()+col,
"");
88 if (col>0 && col<=
data[0].size())
90 for (
unsigned row=0; row<
rows(); ++row)
91 data[row].erase(
data[row].begin()+col-1);
100 if (n==0 || row<0 || row>=
int(
rows()) || row+n<0 || row+n>=
int(
rows()))
102 vector<string> rowToMove;
103 rowToMove.swap(
data[row]);
104 for ( ; abs(n)>0; n=n>0? n-1:n+1)
105 rowToMove.swap(
data[row+n]);
106 rowToMove.swap(
data[row]);
111 if (n==0 || col<0 || col>=
int(
cols()) || col+n<0 || col+n>=
int(
cols()))
114 for (
size_t row=0; row<
rows(); ++row)
117 cellToMove.swap(
data[row][col]);
118 for (
int i=n; abs(i)>0; i=i>0? i-1:i+1)
119 cellToMove.swap(
data[row][col+i]);
120 cellToMove.swap(
data[row][col]);
123 for (
int i=n; abs(i)>0; i=i>0? i-1:i+1)
137 for (
unsigned r=1; r<
rows(); ++r)
150 for (
size_t c=1; c<
cols(); ++c)
156 if (
assetClass(c)!=AssetClass::equity && !uvars.insert(
var).second)
157 throw error(
"Duplicate column label detected");
168 for (
size_t r=1; r<
rows(); ++r)
170 for (
size_t c=1; c<
cols(); ++c)
173 if (!fc.
name.empty() && uvars.insert(fc.
name).second)
174 vars.push_back(fc.
name);
204 throw runtime_error(
"rowSum not valid for stock var names");
207 map<string,double> sum;
209 for (
size_t c=1; c<
cols(); ++c)
229 for (
auto i=sum.begin(); i!=sum.end(); ++i)
232 if (!ret.str().empty() &&i->second>0)
236 else if (i->second!=1)
237 abs(i->second)>5*std::numeric_limits<double>::epsilon()? ret<<i->second : ret<<0;
238 abs(i->second)>5*std::numeric_limits<double>::epsilon()? ret<<i->first : ret<<
"";
242 if (ret.str().empty())
250 std::vector<std::string> r;
251 for (
unsigned row=0; row<
rows(); ++row)
252 r.push_back(
cell(row,col));
260 for (
size_t r=1; r<
rows(); ++r)
262 for (
size_t c=1; c<
cols(); ++c)
265 string& formula=
cell(r,c);
267 while (start<formula.length() && isspace(formula[start])) start++;
268 if (start==formula.length())
continue;
269 if (formula[start]==
'-')
270 formula.erase(start,1);
272 formula.insert(start,
"-");
281 string trialName=
"Godley"+to_string(i);
287 auto g=dynamic_cast<GodleyIcon*>(i.get());
288 return g && g->table.title == trialName;
299 ofstream
f(filename);
301 if (!
f)
throw runtime_error(
"cannot save to "+filename);
306 ofstream
f(filename);
308 if (!
f)
throw runtime_error(
"cannot save to "+filename);
313 const unsigned numRows=
rows()>1?
rows(): 1;
314 map<AssetClass,Data> tmpCols;
315 for (
unsigned c=1; c<
cols(); ++c)
327 tc.erase(remove_if(tc.begin(), tc.end(), [](
const vector<string>& x)
328 {
return x.empty() || x[0].empty();}), tc.end());
331 tc.emplace_back(numRows);
341 for (
unsigned row=0; row<
rows(); ++row)
342 cell(row,col)=colData[row];
351 for (
size_t r=0; r<
rows(); ++r)
352 for (
size_t c=1; c<
cols(); ++c)
355 if (!fc.
name.empty() && fc.
name==from)
365 for (
size_t r=1; r<
rows(); ++r)
366 for (
size_t c=1; c<
cols(); ++c)
369 if (!fc.
name.empty() && fc.
name==from)
379 for (
size_t c=1; c<
cols(); ++c)
382 if (!fc.
name.empty() && fc.
name==from)
void renameFlows(const std::string &from, const std::string &to)
rename all instances of a flow variable
bool singleEquity() const
Check whether more than one equity column is present irrespective of single or multiple equity column...
void deleteCol(unsigned col)
delete col before col
const vector< AssetClass > & assetClass() const
class of each column (used in DE compliant mode)
void orderAssetClasses()
reorders columns into assets/liabilities and equities. Adds empty columns if an asset class is not pr...
void exportToLaTeX(std::ostream &f, const GodleyTable &g)
std::vector< std::string > getColumn(unsigned col) const
get column data
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
void moveCol(int col, int n)
std::shared_ptr< Item > ItemPtr
bool doubleEntryCompliant
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
static std::string stringify(const std::map< std::string, double > &)
string & cell(unsigned row, unsigned col)
void markEdited()
indicate model has been changed since last saved
void renameStock(const std::string &from, const std::string &to)
rename a stock variable
void exportToCSV(const std::string &filename) const
void moveRow(int row, int n)
move row row down by n places (up if -ve)
void insertRow(unsigned row)
insert row at row
void resize(unsigned rows, unsigned cols)
std::string trimWS(const std::string &s)
static void markEdited()
mark model as having changed
const Minsky & cminsky()
const version to help in const correctness
void balanceEquity(int col)
insert A-L into the equity column c, such that A-L-E=0
std::map< std::string, double > rowSumAsMap(int row) const
CLASSDESC_ACCESS_EXPLICIT_INSTANTIATION(minsky::GodleyTable)
std::vector< std::string > getColumnVariables() const
get the set of column labels, in column order
void insertCol(unsigned col)
insert col at col
represents a numerical coefficient times a variable (a "flow")
void setDEmode(bool doubleEntryCompliant)
toggle flow signs according to double entry compliant mode
GodleyAssetClass::AssetClass AssetClass
void rename(const std::string &from, const std::string &to)
rename all instances of a variable
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)
Minsky & minsky()
global minsky object
void exportToLaTeX(const std::string &filename) const
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::string > getVariables() const
get the vector of unique variable names from the interior of the table, in row, then column order ...
bool singularRow(unsigned row, unsigned col)
return true if row is empty apart from a value in column col