Jens Kallup
unread,Apr 13, 2012, 5:00:27 PM4/13/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
#include "boost/multi_array.hpp"
#include "boost/multi_array/base.hpp"
#include "boost/multi_array/collection_concept.hpp"
#include "boost/multi_array/copy_array.hpp"
#include "boost/multi_array/iterator.hpp"
#include "boost/multi_array/subarray.hpp"
#include "boost/multi_array/multi_array_ref.hpp"
#include "boost/multi_array/algorithm.hpp"
#include "boost/array.hpp"
#include "boost/mpl/if.hpp"
#include "boost/type_traits.hpp"
#include <stdio.h>
#include <QString>
#include <QMap>
#include <QList>
#include <iostream>
using namespace std;
#define TMAX_DIMENSIONS 16
class TArrayType
{
private:
int type;
typedef boost::multi_array<double, 1> array_type_double;
typedef boost::multi_array<string, 1> array_type_string;
array_type_double Adouble;
array_type_string Astring;
int MemoryArray[TMAX_DIMENSIONS];
void setArray(int dim[], int dimsize)
{
for (int c = 0; c < dimsize-1; c++)
MemoryArray[c] = dim[c];
for (int i = dimsize-1; i < TMAX_DIMENSIONS-dimsize; i++)
MemoryArray[i] = 0;
}
public:
TArrayType(void) { }
TArrayType(int dim[], int dimsize, double val):
Adouble(boost::extents[3])
{
setArray(dim,dimsize);
this->type = 1;
boost::array<array_type_double::index, TMAX_DIMENSIONS> idx {{
*MemoryArray }};
Adouble(idx) = val;
}
TArrayType(int dim[], int dimsize, string text):
Astring(boost::extents[3])
{
setArray(dim,dimsize);
this->type = 2;
boost::array<array_type_string::index, TMAX_DIMENSIONS> idx {{
*MemoryArray }};
Astring(idx) = text;
}
double getDouble(void)
{
boost::array<array_type_double::index, TMAX_DIMENSIONS> idx {{
*MemoryArray }};
return Adouble(idx);
}
string getString(void)
{
boost::array<array_type_string::index, TMAX_DIMENSIONS> idx {{
*MemoryArray }};
return Astring(idx);
}
};
QMap<QString, TArrayType> ArrayList;
int main(int argc, char **argv)
{
int arrdim[3] = { 1, 3, 2 };
ArrayList.insert("Array1",TArrayType(arrdim,3,(double)42));
ArrayList.insert("Array1",TArrayType(arrdim,3,"Hello")); //
Runtime lib error
double val = ArrayList["Array1"].getDouble();
cout << val << endl;
//cout << ArrayList["Array1"].getString().toStdString().c_str();
return 0;
// This rest works fine ...
/*
TArrayType at
typedef boost::multi_array<double, 1> array_type;
array_type A(boost::extents[3]);
boost::array<array_type::index, 3> idx1 = { {0,0,0} };
boost::array<array_type::index, 3> idx2 = { {1,2,1} };
A(idx1) = 3.14;
A(idx2) = 42;
cout << A(idx1) << endl << A(idx2) << endl;
boost::array<array_type::index, 5> idx3 = { {1,2,1,2,0} };
A(idx3) = 1234;
cout << A(idx3) << endl;
*/
return 0;
}