Skip to content
Mister Mjir edited this page Dec 23, 2019 · 5 revisions

Table

The table class, which is the API to do all the pTable stuff.

Header (table.h) Source (table.cpp)

This is a static class, make sure to call Table::init() before any other Table method and Table::close() before your program end. There should not be any memory leaks.

Public Members

static void init()

This method should be called before any other table methods. It calls addElements() and addMethods() to initialize and fill in data.

static void close()

This method should be called before the program terminates. It calls destroy() to clean up memory.

static void handleCommand(const std::string &command)

This method takes a string command which includes a command name and arguments and calls the corresponding command. It will handle a command not being found, the first argument being help and if the command is missing arguments. It uses the methods provided by addMethods().

Parameters

  • const std::string &command
    • The string of the entire command, including the command name and command arguments

template <typename T> static Element* getElement(T query, bool (*expression)(Element*, T))

This method will return an Element given a query and an expression to check the query. This function will return NULL if the element is not found.

Parameters

  • T query
    • An integer or string to query.
  • bool (*expression)(Element*, T)
    • A function (it is recommended to use lambdas, not dedicated functions) that will check if the element property is equal to T
    • Parameters
      • Element*
        • An element pointer. During your equality check when you return the bool, you access the element's property (remember to name the Element* parameter) and check it against you T value.
      • T
        • Make sure this parameter actually has a type, and T should be the same type as the getElement<T> that you are using the expression for (Look at the source code for queryElement() for an example on how to use this.
    • Return
      • A boolean equal to whether the check was true or false.

Return

A pointer to an Element struct stored in Table or NULL if the element is not found.

static Element* queryElement(const std::string &arg)

An easier to use function to query an Element. The string argument can be a string number, an element symbol (case-sensitive), or an element name (case-insensitive).

Parameters

  • const std::string &arg
    • A string which can be a number, an element symbol, or an element name

Return

  • A pointer to an Element struct stored in Table or NULL if the element is not found.

static void printElement(Element*)

Outputs an Element's name, symbol, atomicNumber, period, group, and electronegativity to std::cout.

Parameters

  • Element*
    • A pointer to an Element

static void printElements()

Prints out every element and its attributes to std::cout by using printElement().

static void helpHelp(const std::vector<std::string> &args)

Displays all the commands and the info for the commands.

Parameters

  • const std::vector<std::string> &args
    • The args parameter needed by every Method struct

Private Members

Table()

Constructor, does nothing.

~Table()

Destructor, does nothing.

static void destroy()

static void addElements()

static void addElement(const std::string &name, const std::string &symbol, int atomicNumber, int period, int group, float electronegativity, int radius)

static void addMethod(const std::string &name, void (*method)(const std::vector<std::string> &), int argc, const std::string &info, void (*help)())

static void addMethods()

static void displayElement(const std::vector<std::string> &args)

static void compareElements(const std::vector<std::string> &args)

static std::vector<Element*> table

static std::vector<Method*> methods


V 2.1.1