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);
207 (col,
AssetClass(classdesc::enumKey<AssetClass>((
char*)args)));
210 return classdesc::enumKey<AssetClass>(
_assetClass(col));
216 throw runtime_error(
"rowSum not valid for stock var names");
219 map<string,double> sum;
221 for (
size_t c=1; c<
cols(); ++c)
241 for (
auto i=sum.begin(); i!=sum.end(); ++i)
244 if (!ret.str().empty() &&i->second>0)
248 else if (i->second!=1)
249 abs(i->second)>5*std::numeric_limits<double>::epsilon()? ret<<i->second : ret<<0;
250 abs(i->second)>5*std::numeric_limits<double>::epsilon()? ret<<i->first : ret<<
"";
254 if (ret.str().empty())
262 std::vector<std::string> r;
263 for (
unsigned row=0; row<
rows(); ++row)
264 r.push_back(
cell(row,col));
272 for (
size_t r=1; r<
rows(); ++r)
274 for (
size_t c=1; c<
cols(); ++c)
277 string& formula=
cell(r,c);
279 while (start<formula.length() && isspace(formula[start])) start++;
280 if (start==formula.length())
continue;
281 if (formula[start]==
'-')
282 formula.erase(start,1);
284 formula.insert(start,
"-");
299 auto g=dynamic_cast<GodleyIcon*>(i.get());
300 return g && g->table.title == trialName;
311 ofstream
f(filename);
313 if (!
f)
throw runtime_error(
"cannot save to "+filename);
318 ofstream
f(filename);
320 if (!
f)
throw runtime_error(
"cannot save to "+filename);
325 const unsigned numRows=
rows()>1?
rows(): 1;
326 map<AssetClass,Data> tmpCols;
327 for (
unsigned c=1; c<
cols(); ++c)
339 tc.erase(remove_if(tc.begin(), tc.end(), [](
const vector<string>& x)
340 {
return x.empty() || x[0].empty();}), tc.end());
343 tc.emplace_back(numRows);
353 for (
unsigned row=0; row<
rows(); ++row)
354 cell(row,col)=colData[row];
363 for (
size_t r=0; r<
rows(); ++r)
364 for (
size_t c=1; c<
cols(); ++c)
367 if (!fc.
name.empty() && fc.
name==from)
377 for (
size_t r=1; r<
rows(); ++r)
378 for (
size_t c=1; c<
cols(); ++c)
381 if (!fc.
name.empty() && fc.
name==from)
391 for (
size_t c=1; c<
cols(); ++c)
394 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
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
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky's state cha...
void resize(unsigned rows, unsigned cols)
std::string trimWS(const std::string &s)
string assetClass(ecolab::TCL_args args)
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
const vector< AssetClass > & _assetClass() const
class of each column (used in DE compliant mode)
std::string savedText
save text in currently highlighted column heading for renaming all variable instances and to enable u...
string to_string(CONST84 char *x)
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