Jpp  18.6.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JVectorize.cc File Reference

Example program to test JLANG::make_array method. More...

#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include "JLang/JVectorize.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test JLANG::make_array method.

Author
mdejong

Definition in file JVectorize.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 63 of file JVectorize.cc.

64 {
65  using namespace std;
66 
67  int debug;
68 
69  try {
70 
71  JParser<> zap("Example program to test converions of array of objects to array of data members.");
72 
73  zap['d'] = make_field(debug) = 3;
74 
75  zap(argc, argv);
76  }
77  catch(const exception &error) {
78  FATAL(error.what() << endl);
79  }
80 
81 
82  using namespace JPP;
83 
84  vector<__A__> buffer;
85 
86  int numberOfElements = 5;
87 
88  for (int i = 0; i != numberOfElements; ++i) {
89  buffer.push_back(__A__(i + 1));
90  }
91 
92  if (debug >= debug_t) {
93  print(cout, numberOfElements, buffer.data());
94  print(cout, numberOfElements, make_array(buffer.begin(), buffer.end(), &__A__::get).data());
95  print(cout, numberOfElements, make_array(buffer.begin(), buffer.end(), &__A__::i) .data());
96  cout << "max " << getMaximum(make_array(buffer.begin(), buffer.end(), &__A__::i), numeric_limits<int>::min()) << endl;
97  cout << "min " << getMinimum(make_array(buffer.begin(), buffer.end(), &__A__::i), numeric_limits<int>::max()) << endl;
98  }
99 
100  {
101  const int* p = make_array(buffer.begin(), buffer.end(), &__A__::get).data();
102 
103  for (int i = 0; i != numberOfElements; ++i, ++p) {
104  ASSERT(buffer[i].get() == *p);
105  }
106  }
107 
108  {
109  const int* p = make_array(buffer.begin(), buffer.end(), &__A__::i).data();
110 
111  for (int i = 0; i != numberOfElements; ++i, ++p) {
112  ASSERT(buffer[i].i == *p);
113  }
114  }
115  {
116  ASSERT(getMaximum(make_array(buffer.begin(), buffer.end(), &__A__::i), numeric_limits<int>::min()) == numberOfElements);
117  ASSERT(getMinimum(make_array(buffer.begin(), buffer.end(), &__A__::i), numeric_limits<int>::max()) == 1);
118  }
119 
120  return 0;
121 }
Utility class to parse command line options.
Definition: JParser.hh:1711
debug
Definition: JMessage.hh:29
T getMinimum(const array_type< T > &buffer, const T value)
Get minimum of values.
Definition: JVectorize.hh:240
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2158
const array_type< JValue_t > & make_array(const JValue_t(&array)[N])
Method to create array of values.
Definition: JVectorize.hh:54
print
Definition: JConvertDusj.sh:44
#define FATAL(A)
Definition: JMessage.hh:67
T getMaximum(const array_type< T > &buffer, const T value)
Get maximum of values.
Definition: JVectorize.hh:218
int debug
debug level