Minsky: 3.17.0
minsky::GodleyTable Class Reference

#include <godleyTable.h>

Inheritance diagram for minsky::GodleyTable:
Inheritance graph
Collaboration diagram for minsky::GodleyTable:
Collaboration graph

Public Types

typedef std::vector< std::vector< string > > Data
 
typedef GodleyAssetClass::AssetClass AssetClass
 
- Public Types inherited from minsky::GodleyAssetClass
enum  AssetClass { noAssetClass, asset, liability, equity }
 
enum  DisplayStyle { DRCR, sign }
 

Public Member Functions

 GodleyTable ()
 
bool operator== (const GodleyTable &other) const
 
const vector< AssetClass > & assetClass () const
 class of each column (used in DE compliant mode) More...
 
AssetClass assetClass (std::size_t col) const
 
AssetClass assetClass (std::size_t col, AssetClass cls)
 
bool singleEquity () const
 Check whether more than one equity column is present irrespective of single or multiple equity column mode. More...
 
void nameUnique ()
 
bool signConventionReversed (int col) const
 The usual mathematical sign convention is reversed in double entry book keeping conventions if the asset class is a liability or equity. More...
 
bool initialConditionRow (unsigned row) const
 returns true if row is an "Initial Conditions" row More...
 
bool singularRow (unsigned row, unsigned col)
 return true if row is empty apart from a value in column col More...
 
std::size_t rows () const
 
std::size_t cols () const
 
void clear ()
 
void resize (unsigned rows, unsigned cols)
 
void moveRow (int row, int n)
 move row row down by n places (up if -ve) More...
 
void moveCol (int col, int n)
 
void dimension (unsigned rows, unsigned cols)
 
string & cell (unsigned row, unsigned col)
 
const string & cell (unsigned row, unsigned col) const
 
bool cellInTable (int row, int col) const
 
string getCell (unsigned row, unsigned col) const
 
void setCell (unsigned row, unsigned col, const string &data)
 
void balanceEquity (int col)
 insert A-L into the equity column c, such that A-L-E=0 More...
 
std::vector< std::string > getColumnVariables () const
 get the set of column labels, in column order More...
 
std::vector< std::string > getVariables () const
 get the vector of unique variable names from the interior of the table, in row, then column order More...
 
std::vector< std::string > getColumn (unsigned col) const
 get column data More...
 
void setDEmode (bool doubleEntryCompliant)
 toggle flow signs according to double entry compliant mode More...
 
std::map< std::string, double > rowSumAsMap (int row) const
 
std::string rowSum (int row) const
 return the symbolic sum across a row More...
 
const DatagetData () const
 accessor for schema access More...
 
void exportToLaTeX (const std::string &filename) const
 
void exportToCSV (const std::string &filename) const
 
void orderAssetClasses ()
 reorders columns into assets/liabilities and equities. Adds empty columns if an asset class is not present. More...
 
void rename (const std::string &from, const std::string &to)
 rename all instances of a variable More...
 
void renameFlows (const std::string &from, const std::string &to)
 rename all instances of a flow variable More...
 
void renameStock (const std::string &from, const std::string &to)
 rename a stock variable More...
 
void insertRow (unsigned row)
 insert row at row More...
 
void deleteRow (unsigned row)
 delete row at row More...
 
void insertCol (unsigned col)
 insert col at col More...
 
void deleteCol (unsigned col)
 delete col before col More...
 

Static Public Member Functions

static std::string stringify (const std::map< std::string, double > &)
 

Public Attributes

bool doubleEntryCompliant
 
std::string title
 
std::string savedText
 save text in currently highlighted column heading for renaming all variable instances and to enable user to fix problems More...
 

Static Public Attributes

static const char * initialConditions ="Initial Conditions"
 

Private Member Functions

 CLASSDESC_ACCESS (GodleyTable)
 
void _resize (unsigned rows, unsigned cols)
 

Static Private Member Functions

static void markEdited ()
 mark model as having changed More...
 

Private Attributes

vector< AssetClassm_assetClass {noAssetClass, asset, liability, equity}
 class of each column (used in DE compliant mode) More...
 
Data data
 

Friends

struct SchemaHelper
 
class GodleyIcon
 

Detailed Description

Definition at line 33 of file godleyTable.h.

Member Typedef Documentation

◆ AssetClass

◆ Data

typedef std::vector<std::vector<string> > minsky::GodleyTable::Data

Definition at line 39 of file godleyTable.h.

Constructor & Destructor Documentation

◆ GodleyTable()

minsky::GodleyTable::GodleyTable ( )
inline

Definition at line 61 of file godleyTable.h.

61  : doubleEntryCompliant(true)
62  {
63  _resize(2,4);
65 
66  }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
void _resize(unsigned rows, unsigned cols)
Definition: godleyTable.h:47
static const char * initialConditions
Definition: godleyTable.h:60

Member Function Documentation

◆ _resize()

void minsky::GodleyTable::_resize ( unsigned  rows,
unsigned  cols 
)
inlineprivate

Definition at line 47 of file godleyTable.h.

47  {
48  // resize existing
49  for (std::size_t i=0; i<data.size(); ++i) data[i].resize(cols);
50  data.resize(rows, vector<string>(cols));
52  }
std::size_t cols() const
Definition: godleyTable.h:105
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
std::size_t rows() const
Definition: godleyTable.h:104
void resize(unsigned rows, unsigned cols)
Definition: godleyTable.h:108

◆ assetClass() [1/3]

const vector<AssetClass>& minsky::GodleyTable::assetClass ( ) const
inline

class of each column (used in DE compliant mode)

Definition at line 76 of file godleyTable.h.

Referenced by minsky::Minsky::balanceDuplicateColumns(), balanceEquity(), minsky::exportToCSV(), minsky::exportToLaTeX(), getColumnVariables(), moveCol(), and orderAssetClasses().

76 {return m_assetClass;}
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
Here is the caller graph for this function:

◆ assetClass() [2/3]

AssetClass minsky::GodleyTable::assetClass ( std::size_t  col) const

◆ assetClass() [3/3]

AssetClass minsky::GodleyTable::assetClass ( std::size_t  col,
AssetClass  cls 
)

◆ balanceEquity()

void GodleyTable::balanceEquity ( int  col)

insert A-L into the equity column c, such that A-L-E=0

Definition at line 134 of file godleyTable.cc.

References assetClass(), cell(), minsky::GodleyAssetClass::equity, rows(), rowSumAsMap(), and stringify().

135 {
136  if (assetClass(col)!=equity) return;
137  for (unsigned r=1; r<rows(); ++r)
138  {
139  cell(r,col)="";
140  auto sum=rowSumAsMap(r);
141  cell(r,col)=stringify(sum);
142  }
143 }
const vector< AssetClass > & assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:76
static std::string stringify(const std::map< std::string, double > &)
Definition: godleyTable.cc:225
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
std::map< std::string, double > rowSumAsMap(int row) const
Definition: godleyTable.cc:201
Here is the call graph for this function:

◆ cell() [1/2]

string& minsky::GodleyTable::cell ( unsigned  row,
unsigned  col 
)
inline

Definition at line 134 of file godleyTable.h.

Referenced by minsky::Minsky::balanceDuplicateColumns(), balanceEquity(), getColumn(), getColumnVariables(), getVariables(), minsky::Minsky::importDuplicateColumn(), initialConditionRow(), orderAssetClasses(), rename(), renameFlows(), renameStock(), rowSumAsMap(), setDEmode(), and singularRow().

134  {
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];
139  }
std::size_t cols() const
Definition: godleyTable.h:105
std::size_t rows() const
Definition: godleyTable.h:104
void _resize(unsigned rows, unsigned cols)
Definition: godleyTable.h:47
Here is the caller graph for this function:

◆ cell() [2/2]

const string& minsky::GodleyTable::cell ( unsigned  row,
unsigned  col 
) const
inline

Definition at line 140 of file godleyTable.h.

140  {
141  if (row>=data.size() || col>=data[row].size())
142  throw std::out_of_range("Godley table index error");
143  return data[row][col];
144  }

◆ cellInTable()

bool minsky::GodleyTable::cellInTable ( int  row,
int  col 
) const
inline

Definition at line 145 of file godleyTable.h.

146  {return row>=0 && std::size_t(row)<rows() && col>=0 && std::size_t(col)<cols();}
std::size_t cols() const
Definition: godleyTable.h:105
std::size_t rows() const
Definition: godleyTable.h:104

◆ CLASSDESC_ACCESS()

minsky::GodleyTable::CLASSDESC_ACCESS ( GodleyTable  )
private

◆ clear()

void minsky::GodleyTable::clear ( )
inline

Definition at line 107 of file godleyTable.h.

107 {data.clear(); m_assetClass.clear(); markEdited();}
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
static void markEdited()
mark model as having changed
Definition: godleyTable.cc:32

◆ cols()

◆ deleteCol()

void GodleyTable::deleteCol ( unsigned  col)

delete col before col

Definition at line 83 of file godleyTable.cc.

References cols(), data, m_assetClass, markEdited(), minsky::GodleyAssetClass::noAssetClass, orderAssetClasses(), and rows().

84 {
85  if (col>=m_assetClass.size())
86  m_assetClass.resize(cols(), noAssetClass);
87  m_assetClass.erase(m_assetClass.begin()+col-1);
88  if (col>0 && col<=data[0].size())
89  {
90  for (unsigned row=0; row<rows(); ++row)
91  data[row].erase(data[row].begin()+col-1);
92  markEdited();
93  }
94  // insert extra empty column if an asset class gets emptied out of this
96 }
std::size_t cols() const
Definition: godleyTable.h:105
void orderAssetClasses()
reorders columns into assets/liabilities and equities. Adds empty columns if an asset class is not pr...
Definition: godleyTable.cc:311
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
std::size_t rows() const
Definition: godleyTable.h:104
static void markEdited()
mark model as having changed
Definition: godleyTable.cc:32
Here is the call graph for this function:

◆ deleteRow()

void minsky::GodleyTable::deleteRow ( unsigned  row)
inline

delete row at row

Definition at line 121 of file godleyTable.h.

121 {data.erase(data.begin()+row);}

◆ dimension()

void minsky::GodleyTable::dimension ( unsigned  rows,
unsigned  cols 
)
inline

Definition at line 132 of file godleyTable.h.

132 {clear(); resize(rows,cols);}
std::size_t cols() const
Definition: godleyTable.h:105
std::size_t rows() const
Definition: godleyTable.h:104
void resize(unsigned rows, unsigned cols)
Definition: godleyTable.h:108

◆ exportToCSV()

void GodleyTable::exportToCSV ( const std::string &  filename) const

Definition at line 304 of file godleyTable.cc.

References minsky::exportToCSV(), and f.

305 {
306  ofstream f(filename);
307  minsky::exportToCSV(f, *this);
308  if (!f) throw runtime_error("cannot save to "+filename);
309 }
function f
Definition: canvas.m:1
void exportToCSV(std::ostream &s, const GodleyTable &g)
Definition: godleyExport.cc:61
Here is the call graph for this function:

◆ exportToLaTeX()

void GodleyTable::exportToLaTeX ( const std::string &  filename) const

Definition at line 297 of file godleyTable.cc.

References minsky::exportToLaTeX(), and f.

298 {
299  ofstream f(filename);
300  minsky::exportToLaTeX(f, *this);
301  if (!f) throw runtime_error("cannot save to "+filename);
302 }
function f
Definition: canvas.m:1
void exportToLaTeX(std::ostream &f, const GodleyTable &g)
Definition: godleyExport.cc:84
Here is the call graph for this function:

◆ getCell()

string minsky::GodleyTable::getCell ( unsigned  row,
unsigned  col 
) const
inline

Definition at line 147 of file godleyTable.h.

Referenced by minsky::exportToCSV(), and minsky::exportToLaTeX().

147  {
148  if (row<rows() && col<cols())
149  return cell(row,col);
150  else
151  return "";
152  }
std::size_t cols() const
Definition: godleyTable.h:105
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
Here is the caller graph for this function:

◆ getColumn()

std::vector< std::string > GodleyTable::getColumn ( unsigned  col) const

get column data

Definition at line 248 of file godleyTable.cc.

References cell(), and rows().

Referenced by orderAssetClasses().

249 {
250  std::vector<std::string> r;
251  for (unsigned row=0; row<rows(); ++row)
252  r.push_back(cell(row,col));
253  return r;
254 }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getColumnVariables()

vector< string > GodleyTable::getColumnVariables ( ) const

get the set of column labels, in column order

Definition at line 146 of file godleyTable.cc.

References assetClass(), cell(), cols(), minsky::trimWS(), and minsky::var.

147 {
148  set<string> uvars; //set for uniqueness checking
149  vector<string> vars;
150  for (size_t c=1; c<cols(); ++c)
151  {
152  const string var=trimWS(cell(0,c));
153  if (!var.empty())
154  {
155  // disable duplicate column test on equity columns (feature #174)
156  if (assetClass(c)!=AssetClass::equity && !uvars.insert(var).second)
157  throw error("Duplicate column label detected");
158  vars.push_back(var);
159  }
160  }
161  return vars;
162 }
std::size_t cols() const
Definition: godleyTable.h:105
const vector< AssetClass > & assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:76
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::string trimWS(const std::string &s)
Definition: str.h:49
Here is the call graph for this function:

◆ getData()

const Data& minsky::GodleyTable::getData ( ) const
inline

accessor for schema access

Definition at line 182 of file godleyTable.h.

182 {return data;}

◆ getVariables()

vector< string > GodleyTable::getVariables ( ) const

get the vector of unique variable names from the interior of the table, in row, then column order

Definition at line 164 of file godleyTable.cc.

References cell(), cols(), initialConditionRow(), minsky::FlowCoef::name, and rows().

165 {
166  vector<string> vars;
167  set<string> uvars; //set for uniqueness checking
168  for (size_t r=1; r<rows(); ++r)
169  if (!initialConditionRow(r))
170  for (size_t c=1; c<cols(); ++c)
171  {
172  const FlowCoef fc(cell(r,c));
173  if (!fc.name.empty() && uvars.insert(fc.name).second)
174  vars.push_back(fc.name);
175  }
176  return vars;
177 }
std::size_t cols() const
Definition: godleyTable.h:105
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
Here is the call graph for this function:

◆ initialConditionRow()

bool GodleyTable::initialConditionRow ( unsigned  row) const

returns true if row is an "Initial Conditions" row

Definition at line 37 of file godleyTable.cc.

References cell(), initialConditions, and rows().

Referenced by getVariables(), rowSumAsMap(), and setDEmode().

38 {
39  if (row>=rows()) return false;
40  const string& label=cell(row,0);
41  static const size_t initialConditionsSz=strlen(initialConditions);
42  size_t i, j;
43  // trim any leading whitespaces
44  for (i=0; isspace(label[i]); ++i);
45  // compare case insensitively
46  for (j=0; j<initialConditionsSz && i<label.size() &&
47  toupper(label[i])==toupper(initialConditions[j]); ++i, ++j);
48  return j==initialConditionsSz;
49 }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
static const char * initialConditions
Definition: godleyTable.h:60
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertCol()

void GodleyTable::insertCol ( unsigned  col)

insert col at col

Definition at line 68 of file godleyTable.cc.

References cols(), data, m_assetClass, markEdited(), and minsky::GodleyAssetClass::noAssetClass.

69 {
70  if (col>=m_assetClass.size())
71  m_assetClass.resize(cols(), noAssetClass);
72  m_assetClass.insert(m_assetClass.begin()+col,
73  col==0? noAssetClass: m_assetClass[col-1]);
74  for (unsigned row=0; row<data.size(); ++row)
75  {
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, "");
79  }
80  markEdited();
81 }
std::size_t cols() const
Definition: godleyTable.h:105
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
static void markEdited()
mark model as having changed
Definition: godleyTable.cc:32
Here is the call graph for this function:

◆ insertRow()

void GodleyTable::insertRow ( unsigned  row)

insert row at row

In the following, C++ data structure is off by one with respect to the TCL table, as the TCL table has an extra row and column for the +/- buttons. So deleting the row/column before the index has the effect of deleting the row/column at the index in the TCL table, and inserting row/column at the index in C++ has the effect of inserting before the index in TCL

Definition at line 59 of file godleyTable.cc.

References cols(), data, and markEdited().

60 {
61  if (row<=data.size())
62  {
63  data.insert(data.begin()+row, vector<string>(cols()));
64  markEdited();
65  }
66 }
std::size_t cols() const
Definition: godleyTable.h:105
static void markEdited()
mark model as having changed
Definition: godleyTable.cc:32
Here is the call graph for this function:

◆ markEdited()

void GodleyTable::markEdited ( )
staticprivate

mark model as having changed

Definition at line 32 of file godleyTable.cc.

References minsky::Minsky::markEdited(), and minsky::minsky().

Referenced by deleteCol(), insertCol(), and insertRow().

33 {
35 }
void markEdited()
indicate model has been changed since last saved
Definition: minsky.h:161
Minsky & minsky()
global minsky object
Definition: addon.cc:545
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveCol()

void GodleyTable::moveCol ( int  col,
int  n 
)

Definition at line 109 of file godleyTable.cc.

References assetClass(), cols(), data, m_assetClass, orderAssetClasses(), rows(), and savedText.

110 {
111  if (n==0 || col<0 || col>=int(cols()) || col+n<0 || col+n>=int(cols()))
112  return;
113  auto targetAssetClass=assetClass(col+n);
114  for (size_t row=0; row<rows(); ++row)
115  {
116  string cellToMove;
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]);
121  }
122  auto ac=assetClass(col);
123  for (int i=n; abs(i)>0; i=i>0? i-1:i+1)
124  swap(ac, m_assetClass[col+i]);
125  swap(ac, m_assetClass[col]);
126 
127  assetClass(col+n, targetAssetClass);
128  // insert extra empty column if an asset class gets emptied out of this
130  // save text in currently highlighted column heading. For tickets 1058/1094/1122/1127.
131  savedText=data[0][col];
132 }
std::size_t cols() const
Definition: godleyTable.h:105
const vector< AssetClass > & assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:76
void orderAssetClasses()
reorders columns into assets/liabilities and equities. Adds empty columns if an asset class is not pr...
Definition: godleyTable.cc:311
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
std::size_t rows() const
Definition: godleyTable.h:104
std::string savedText
save text in currently highlighted column heading for renaming all variable instances and to enable u...
Definition: godleyTable.h:167
Here is the call graph for this function:

◆ moveRow()

void GodleyTable::moveRow ( int  row,
int  n 
)

move row row down by n places (up if -ve)

Definition at line 98 of file godleyTable.cc.

References data, and rows().

99 {
100  if (n==0 || row<0 || row>=int(rows()) || row+n<0 || row+n>=int(rows()))
101  return;
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]);
107 }
std::size_t rows() const
Definition: godleyTable.h:104
Here is the call graph for this function:

◆ nameUnique()

void GodleyTable::nameUnique ( )

Generates a unique name for this table.

Definition at line 277 of file godleyTable.cc.

References minsky::cminsky(), minsky::GroupItems::items, and title.

278 {
279  for (int i=1;;++i)
280  {
281  string trialName="Godley"+to_string(i);
282 
283  if (!cminsky().model->findAny
284  (&Group::items,
285  [&](const ItemPtr& i)
286  {
287  auto g=dynamic_cast<GodleyIcon*>(i.get());
288  return g && g->table.title == trialName;
289  }))
290  {
291  title = trialName;
292  break;
293  }
294  }
295 }
std::shared_ptr< Item > ItemPtr
Definition: item.h:55
const Minsky & cminsky()
const version to help in const correctness
Definition: minsky.h:538
std::string title
Definition: godleyTable.h:58
Here is the call graph for this function:

◆ operator==()

bool minsky::GodleyTable::operator== ( const GodleyTable other) const
inline

Definition at line 69 of file godleyTable.h.

References data, doubleEntryCompliant, m_assetClass, and title.

70  {
71  return (data==other.data && m_assetClass==other.m_assetClass &&
72  doubleEntryCompliant==other.doubleEntryCompliant && title==other.title);
73  }
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
std::string title
Definition: godleyTable.h:58

◆ orderAssetClasses()

void GodleyTable::orderAssetClasses ( )

reorders columns into assets/liabilities and equities. Adds empty columns if an asset class is not present.

Definition at line 311 of file godleyTable.cc.

References minsky::GodleyAssetClass::asset, assetClass(), cell(), cols(), minsky::GodleyAssetClass::equity, getColumn(), minsky::GodleyAssetClass::noAssetClass, resize(), and rows().

Referenced by deleteCol(), and moveCol().

312 {
313  const unsigned numRows=rows()>1? rows(): 1;
314  map<AssetClass,Data> tmpCols;
315  for (unsigned c=1; c<cols(); ++c)
316  if (assetClass(c)==noAssetClass)
317  tmpCols[asset].push_back(getColumn(c));
318  else
319  tmpCols[assetClass(c)].push_back(getColumn(c));
320 
321  // add empty column if asset class not present, and count number of cols
322  unsigned numCols=1;
323  for (int ac=asset; ac<=equity; ++ac)
324  {
325  auto& tc=tmpCols[AssetClass(ac)];
326  // strip out any blank columns
327  tc.erase(remove_if(tc.begin(), tc.end(), [](const vector<string>& x)
328  {return x.empty() || x[0].empty();}), tc.end());
329  // ensure at least one column is present in an asset class
330  if (tc.empty())
331  tc.emplace_back(numRows);
332 
333  numCols+=tc.size();
334  }
335 
336  resize(numRows, numCols);
337  unsigned col=1;
338  for (int ac=asset; ac<=equity; ++ac)
339  for (auto& colData: tmpCols[AssetClass(ac)])
340  {
341  for (unsigned row=0; row<rows(); ++row)
342  cell(row,col)=colData[row];
343  assetClass(col,AssetClass(ac));
344  col++;
345  }
346 }
std::size_t cols() const
Definition: godleyTable.h:105
const vector< AssetClass > & assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:76
std::vector< std::string > getColumn(unsigned col) const
get column data
Definition: godleyTable.cc:248
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
void resize(unsigned rows, unsigned cols)
Definition: godleyTable.h:108
GodleyAssetClass::AssetClass AssetClass
Definition: godleyTable.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rename()

void GodleyTable::rename ( const std::string &  from,
const std::string &  to 
)

rename all instances of a variable

Definition at line 348 of file godleyTable.cc.

References cell(), cols(), minsky::FlowCoef::name, rows(), and minsky::FlowCoef::str().

349 {
350  // if no stock vars found, check flow var cells.
351  for (size_t r=0; r<rows(); ++r)
352  for (size_t c=1; c<cols(); ++c)
353  {
354  FlowCoef fc(cell(r,c));
355  if (!fc.name.empty() && fc.name==from)
356  {
357  fc.name=to;
358  cell(r,c)=fc.str();
359  }
360  }
361 }
std::size_t cols() const
Definition: godleyTable.h:105
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
Here is the call graph for this function:

◆ renameFlows()

void GodleyTable::renameFlows ( const std::string &  from,
const std::string &  to 
)

rename all instances of a flow variable

Definition at line 363 of file godleyTable.cc.

References cell(), cols(), minsky::FlowCoef::name, rows(), and minsky::FlowCoef::str().

364 {
365  for (size_t r=1; r<rows(); ++r)
366  for (size_t c=1; c<cols(); ++c)
367  {
368  FlowCoef fc(cell(r,c));
369  if (!fc.name.empty() && fc.name==from)
370  {
371  fc.name=to;
372  cell(r,c)=fc.str();
373  }
374  }
375 }
std::size_t cols() const
Definition: godleyTable.h:105
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
Here is the call graph for this function:

◆ renameStock()

void GodleyTable::renameStock ( const std::string &  from,
const std::string &  to 
)

rename a stock variable

Definition at line 377 of file godleyTable.cc.

References cell(), cols(), minsky::FlowCoef::name, and minsky::FlowCoef::str().

378 {
379  for (size_t c=1; c<cols(); ++c)
380  {
381  FlowCoef fc(cell(0,c));
382  if (!fc.name.empty() && fc.name==from)
383  {
384  fc.name=to;
385  cell(0,c)=fc.str();
386  }
387  }
388 }
std::size_t cols() const
Definition: godleyTable.h:105
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
Here is the call graph for this function:

◆ resize()

void minsky::GodleyTable::resize ( unsigned  rows,
unsigned  cols 
)
inline

Definition at line 108 of file godleyTable.h.

Referenced by orderAssetClasses().

std::size_t cols() const
Definition: godleyTable.h:105
std::size_t rows() const
Definition: godleyTable.h:104
static void markEdited()
mark model as having changed
Definition: godleyTable.cc:32
void _resize(unsigned rows, unsigned cols)
Definition: godleyTable.h:47
Here is the caller graph for this function:

◆ rows()

std::size_t minsky::GodleyTable::rows ( ) const
inline

◆ rowSum()

std::string minsky::GodleyTable::rowSum ( int  row) const
inline

return the symbolic sum across a row

Definition at line 179 of file godleyTable.h.

179 {return stringify(rowSumAsMap(row));}
static std::string stringify(const std::map< std::string, double > &)
Definition: godleyTable.cc:225
std::map< std::string, double > rowSumAsMap(int row) const
Definition: godleyTable.cc:201

◆ rowSumAsMap()

map< string, double > GodleyTable::rowSumAsMap ( int  row) const

Definition at line 201 of file godleyTable.cc.

References cell(), minsky::FlowCoef::coef, cols(), initialConditionRow(), minsky::FlowCoef::name, and signConventionReversed().

Referenced by balanceEquity().

202 {
203  if (row==0)
204  throw runtime_error("rowSum not valid for stock var names");
205 
206  // accumulate the total for each variable
207  map<string,double> sum;
208 
209  for (size_t c=1; c<cols(); ++c)
210  {
211  const FlowCoef fc(cell(row,c));
212  if (!fc.name.empty()||initialConditionRow(row))
213  {
214  // apply accounting relation to the initial condition row
215  if (signConventionReversed(c))
216  sum[fc.name]-=fc.coef;
217  else
218  sum[fc.name]+=fc.coef;
219  }
220  }
221 
222  return sum;
223 }
std::size_t cols() const
Definition: godleyTable.h:105
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
represents a numerical coefficient times a variable (a "flow")
Definition: flowCoef.h:27
bool signConventionReversed(int col) const
The usual mathematical sign convention is reversed in double entry book keeping conventions if the as...
Definition: godleyTable.h:92
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setCell()

void minsky::GodleyTable::setCell ( unsigned  row,
unsigned  col,
const string &  data 
)
inline

Definition at line 153 of file godleyTable.h.

153  {
154  cell(row,col)=data;
155  }
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134

◆ setDEmode()

void GodleyTable::setDEmode ( bool  doubleEntryCompliant)

toggle flow signs according to double entry compliant mode

Definition at line 256 of file godleyTable.cc.

References cell(), cols(), doubleEntryCompliant, initialConditionRow(), rows(), and signConventionReversed().

257 {
258  if (mode==doubleEntryCompliant) return;
259  doubleEntryCompliant=true; // to allow signConventionReversed to work
260  for (size_t r=1; r<rows(); ++r)
261  if (!initialConditionRow(r))
262  for (size_t c=1; c<cols(); ++c)
263  if (signConventionReversed(c))
264  {
265  string& formula=cell(r,c);
266  unsigned start=0;
267  while (start<formula.length() && isspace(formula[start])) start++;
268  if (start==formula.length()) continue; // empty cell
269  if (formula[start]=='-')
270  formula.erase(start,1); // turns a negative into a positive
271  else
272  formula.insert(start,"-");
273  }
275 }
std::size_t cols() const
Definition: godleyTable.h:105
bool initialConditionRow(unsigned row) const
returns true if row is an "Initial Conditions" row
Definition: godleyTable.cc:37
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
std::size_t rows() const
Definition: godleyTable.h:104
bool signConventionReversed(int col) const
The usual mathematical sign convention is reversed in double entry book keeping conventions if the as...
Definition: godleyTable.h:92
Here is the call graph for this function:

◆ signConventionReversed()

bool minsky::GodleyTable::signConventionReversed ( int  col) const
inline

The usual mathematical sign convention is reversed in double entry book keeping conventions if the asset class is a liability or equity.

Definition at line 92 of file godleyTable.h.

Referenced by rowSumAsMap(), and setDEmode().

93  {
94  return doubleEntryCompliant &&
95  (assetClass(col)==liability || assetClass(col)==equity);
96  }
const vector< AssetClass > & assetClass() const
class of each column (used in DE compliant mode)
Definition: godleyTable.h:76
Here is the caller graph for this function:

◆ singleEquity()

bool GodleyTable::singleEquity ( ) const

Check whether more than one equity column is present irrespective of single or multiple equity column mode.

Definition at line 196 of file godleyTable.cc.

References cols(), minsky::GodleyAssetClass::equity, and m_assetClass.

196  {
197  assert(cols()>=3);
199 }
std::size_t cols() const
Definition: godleyTable.h:105
vector< AssetClass > m_assetClass
class of each column (used in DE compliant mode)
Definition: godleyTable.h:43
Here is the call graph for this function:

◆ singularRow()

bool GodleyTable::singularRow ( unsigned  row,
unsigned  col 
)

return true if row is empty apart from a value in column col

Definition at line 51 of file godleyTable.cc.

References cell(), and cols().

52 {
53  for (size_t c=0; c<cols(); ++c)
54  if (c!=col && !cell(row, c).empty())
55  return false;
56  return true;
57 }
std::size_t cols() const
Definition: godleyTable.h:105
string & cell(unsigned row, unsigned col)
Definition: godleyTable.h:134
Here is the call graph for this function:

◆ stringify()

string GodleyTable::stringify ( const std::map< std::string, double > &  sum)
static

Definition at line 225 of file godleyTable.cc.

Referenced by balanceEquity().

226 {
227  // create symbolic representation of each term
228  ostringstream ret;
229  for (auto i=sum.begin(); i!=sum.end(); ++i)
230  if (i->second!=0)
231  {
232  if (!ret.str().empty() &&i->second>0)
233  ret<<"+";
234  if (i->second==-1)
235  ret<<"-";
236  else if (i->second!=1)
237  abs(i->second)>5*std::numeric_limits<double>::epsilon()? ret<<i->second : ret<<0; // only display decimals if sum of row is larger than 5*2.22045e-16. for ticket 1244
238  abs(i->second)>5*std::numeric_limits<double>::epsilon()? ret<<i->first : ret<<"";
239  }
240 
241  //if completely empty, substitute a zero
242  if (ret.str().empty())
243  return "0";
244  return ret.str();
245 
246 }
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ GodleyIcon

friend class GodleyIcon
friend

Definition at line 38 of file godleyTable.h.

◆ SchemaHelper

friend struct SchemaHelper
friend

Definition at line 37 of file godleyTable.h.

Member Data Documentation

◆ data

Data minsky::GodleyTable::data
private

◆ doubleEntryCompliant

bool minsky::GodleyTable::doubleEntryCompliant

Definition at line 56 of file godleyTable.h.

Referenced by minsky::exportToCSV(), minsky::exportToLaTeX(), operator==(), and setDEmode().

◆ initialConditions

const char * GodleyTable::initialConditions ="Initial Conditions"
static

Definition at line 60 of file godleyTable.h.

Referenced by initialConditionRow().

◆ m_assetClass

vector<AssetClass> minsky::GodleyTable::m_assetClass {noAssetClass, asset, liability, equity}
private

class of each column (used in DE compliant mode)

Definition at line 43 of file godleyTable.h.

Referenced by deleteCol(), insertCol(), moveCol(), operator==(), minsky::SchemaHelper::setPrivates(), and singleEquity().

◆ savedText

std::string minsky::GodleyTable::savedText

save text in currently highlighted column heading for renaming all variable instances and to enable user to fix problems

Definition at line 167 of file godleyTable.h.

Referenced by moveCol().

◆ title

std::string minsky::GodleyTable::title

The documentation for this class was generated from the following files: