Dispatch Challenge
Syncmultiplethreadssharingaresource
Static Public Member Functions | Static Private Member Functions | List of all members
Controller Class Reference

controller class of functions to "dispatch" from Command Dispatcher More...

Static Public Member Functions

static bool help (rapidjson::Value &payload)
 command handler for help More...
 
static bool exit (rapidjson::Value &payload)
 command handler for exit More...
 
static bool query_payload (rapidjson::Value &payload)
 command handler for query_payload More...
 
static bool sum_ints (rapidjson::Value &payload)
 command handler for sum_ints More...
 
static bool mean_ints (rapidjson::Value &payload)
 command handler for mean_ints More...
 

Static Private Member Functions

template<typename T >
static auto summation (vector< T > collection) -> T
 summation function for sum_ints() and mean_ints() More...
 

Detailed Description

controller class of functions to "dispatch" from Command Dispatcher

Definition at line 218 of file main.cpp.

Member Function Documentation

◆ exit()

static bool Controller::exit ( rapidjson::Value &  payload)
inlinestatic

command handler for exit

Parameters
payloada JSON string possibly containing a reason
Returns
true if command handled successfully
Todo:
change cout call to shared_print?

Definition at line 263 of file main.cpp.

◆ help()

static bool Controller::help ( rapidjson::Value &  payload)
inlinestatic

command handler for help

Parameters
payloada JSON string possibly containing a "usage" message
Exceptions
exceptionif JSON contains no value "usage"
Returns
true if command handled successfully
Todo:
change cout call to shared_print?

Definition at line 232 of file main.cpp.

◆ mean_ints()

static bool Controller::mean_ints ( rapidjson::Value &  payload)
inlinestatic

command handler for mean_ints

Todo:
mean_int is an almost identical function to sum_ints. May be more efficient to break large amount of functionality out into a private member function. Will need to figure out division of labor if so.
Parameters
payloada JSON string possibly containing an array value
Returns
true if command handled successfully, otherwise generate exception
Exceptions
exceptionwhen payload contains no value "addends"
exceptionwhen addends is not an array
exceptionwhen no integers in array

This function looks for an array named "addends". If it exists, it traverses it, and prints the mean of all integers present in the array. All non-integer members of the array are ignored.

Bug:
verify that this cannot convert int to float

Definition at line 429 of file main.cpp.

◆ query_payload()

static bool Controller::query_payload ( rapidjson::Value &  payload)
inlinestatic

command handler for query_payload

Parameters
payloada JSON string possibly containing any allowed JSON value(s)
Returns
true if command handled successfully, otherwise generate exception
See also
derived from: http://rapidjson.org/md_doc_tutorial.html#QueryObject

Definition at line 303 of file main.cpp.

◆ sum_ints()

static bool Controller::sum_ints ( rapidjson::Value &  payload)
inlinestatic

command handler for sum_ints

Parameters
payloada JSON string possibly containing an array value
Returns
true if command handled successfully, otherwise generate exception
Exceptions
exceptionwhen payload contains no value "addends"
exceptionwhen addends is not an array
exceptionwhen no integers in array

This function looks for an array named "addends". If it exists, it traverses it and prints the sum of all integers present in the array. All non-integer members of the array are ignored.

Definition at line 345 of file main.cpp.

◆ summation()

template<typename T >
static auto Controller::summation ( vector< T >  collection) -> T
inlinestaticprivate

summation function for sum_ints() and mean_ints()

Todo:
write additional member functions to handle other number types such as float, double, or Uint64.
Parameters
collectiona vector of numbers to add together
Returns
sum of numbers of same type as vector passed in.

This function takes in a vector of numbers and addes them together. It supports all number types in C++ including int, float, etc. It was written to accomodate future functions like sum_int and mean_int that take in other types of numbers.

Todo:
maybe change cerr call to shared error print?

Definition at line 516 of file main.cpp.


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