Operator Console
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
jsonhelpers.cpp File Reference
#include <iostream>
#include <exception>
#include <string>
#include "libjson.h"
Include dependency graph for jsonhelpers.cpp:

Functions

int sumArrayInt (JSONNode node, int count)
 
int getIntFromArray (JSONNode node, char *name)
 
void getStringArray (JSONNode &array, int len, std::string *s)
 
void getFloatArray (JSONNode &array, double *data, int len)
 
void prepareTestSettings (int width, int height, int ncolors, const char *extension, const char *fileroot, const char *serial_number, const char *part_number, int crop_borders[4], json_string &test_settings)
 

Function Documentation

void getFloatArray ( JSONNode array,
double *  data,
int  len 
)

References JSONNode::as_float().

49 {
50  int i;
51 
52  if (data != NULL)
53  {
54  for (i = 0; i < len; i++)
55  {
56  data[i] = array[i].as_float();
57  }
58  }
59 }
json_number as_float(void) const json_nothrow json_read_priority
Definition: JSONNode.h:688

Here is the call graph for this function:

int getIntFromArray ( JSONNode  node,
char *  name 
)

References JSONNode::as_array(), and JSONNode::as_int().

16  {
17  try {
18  return node.at(name).as_array()[0].as_int();
19 
20  } catch(exception& e) {
21  cout << " Parse error" << e.what() << endl;
22  }
23  return -65535;
24 }
json_int_t as_int(void) const json_nothrow json_read_priority
Definition: JSONNode.h:683
JSONNode as_array(void) const json_nothrow json_read_priority
Definition: JSONNode.cpp:84

Here is the call graph for this function:

void getStringArray ( JSONNode array,
int  len,
std::string *  s 
)
30 {
31  int i;
32 
33  for (i = 0; i < len; i++)
34  {
35  if (i > 0)
36  {
37  s->append(", ");
38  }
39 
40  s->append(array[i].as_string());
41  }
42 }
void prepareTestSettings ( int  width,
int  height,
int  ncolors,
const char *  extension,
const char *  fileroot,
const char *  serial_number,
const char *  part_number,
int  crop_borders[4],
json_string &  test_settings 
)

References JSON_ARRAY, JSON_NODE, JSONNode::push_back(), JSONNode::set_name(), and JSONNode::write_formatted().

68  {
69  // Construct JSON that Serial # and Model # info to the JSON options string
70 
72  n.push_back(JSONNode("width", width));
73  n.push_back(JSONNode("height", height));
74  n.push_back(JSONNode("extension", extension));
75  n.push_back(JSONNode("fileroot", fileroot));
76  n.push_back(JSONNode("serial_number", serial_number));
77  n.push_back(JSONNode("part_number", part_number));
78  n.push_back(JSONNode("ncolors", ncolors));
79  JSONNode cbn(JSON_ARRAY);
80  cbn.set_name("crop_borders");
81  cbn.push_back(JSONNode("",crop_borders[0]));
82  cbn.push_back(JSONNode("",crop_borders[1]));
83  cbn.push_back(JSONNode("",crop_borders[2]));
84  cbn.push_back(JSONNode("",crop_borders[3]));
85  n.push_back(cbn);
86  n.set_name("jstr");
88  j.push_back(n);
89  test_settings = j.write_formatted();
90  // std::cout << "TEST SETTINGS:" << std::endl;
91  // std::cout << test_settings << std::endl;
92 }
Definition: JSONNode.h:132
#define JSON_NODE
Definition: JSONDefs.h:26
width
Definition: calculation_checks.m:1
height
Definition: calculation_checks.m:2
#define JSON_ARRAY
Definition: JSONDefs.h:25

Here is the call graph for this function:

int sumArrayInt ( JSONNode  node,
int  count 
)

References JSONNode::as_int().

9  {
10  int sum=0;
11  for (int i=0; i<count; ++i) {
12  sum += node[i].as_int();
13  }
14  return sum;
15 }
json_int_t as_int(void) const json_nothrow json_read_priority
Definition: JSONNode.h:683

Here is the call graph for this function: