#ifndef SYMTAB_H_ #define SYMTAB_H_ #include #include #include #include #include #include /** * @short Symbol table * * The SymTab class stores the names of variables used in the BUGS * language representation of the model. * * @see NodeArray */ class SymTab : public NodeNameTab { std::map _varTable; std::map _names; public: /** * Constructs an empty symbol table */ SymTab(); /** * Adds an array variable to the symbol table. This creates a * NodeArray object of the given dimension and associates it * with the name, so it can be retrieved with a call to getVariable. * If no dimension is given, the variable is assumed to be scalar. */ void addVariable(std::string const &name, Index const &dim = Index(1)); /** * Returns a pointer to the NodeArray associated with the given * name, or a NULL pointer if there is no such NodeArray. */ NodeArray *getVariable(std::string const &name) const; /** * Inserts a node into the symbol table with the given name * (which must correspond to a previously added variable) * and range (which must be a valid sub-range for the variable). */ void insertNode(Node *node, std::string const &name, Range const &range); /** * Adds all the nodes contained in all the NodeArray objects * in the SymTab to the given vector */ void getNodes(std::vector &nodes); /** * Write values of stochastic nodes from the data table to the nodes * in SymTab with the same name. * * @param data_table Data table from which results will be read * * @param observed Logical flag. If true, then existing nodes will * have their value fixed after being written, and if there is no * node corresponding to a value in the data table, a constant node * will be created. */ void writeData(std::map const &data_table, bool observed); /** * Reads the current value of the stochastic nodes in the * symbol table and writes the result to the data table. * * @param data_table Data table to which results will be written. * * @param observed Logical flag. If true, then the values of the * fixed nodes are written to the data table. If false, then the * values of the non-fixed nodes are written (excluding deterministic * nodes). */ void readData(std::map &data_table, bool observed) const; /** * Reads the current value of all nodes (stochastic and * deterministic) in the symbol table and writes the result to the * data table * * @param data_table Data table to which results will be written */ void readData(std::map &data_table) const; /** * Returns the number of variables in the symbol table */ unsigned int size() const; /** * Deletes all the variables in the symbol table */ void clear(); /** * Gets the BUGS language name of the node if it has belongs to * any of the NodeArrays in the symbol table. Special rules for nested * indexing also allow the names of Mixture Nodes to be calculated. * If the node name is not found, an empty string is returned */ std::string getName(Node const *node) const; }; #endif /* SYMTAB_H_ */