Menu

#3 User defined member type (*array).a()

Unstable (example)
closed
None
5
2018-09-22
2002-10-18
No

I read the blitz documentation on user defined types.

For example let's take a

struct Foo {
enum { value_a =0 , value_b = 1...}
int a;
int b;
int c;
}

Its seems in blitz currently that if a user decided to
access a single member of the entire array of Foo,

the user has to resort to something like

Array<Foo, 2> test;

Array<int,2> test_a = test[ Foo::value_a] , while a
better C++ style of member return would be
Array<int,2> test_a= (*test).a();

Well, i think the following suggestion may help over the
current problem of test[ Foo::value_a] and sucessful
replacement by (*test).a()

// Well the better thing to shoot for would be

test->a()

however, it need creation of a pointer object that needs
to be automatically disposed.

may be adding "delete *this; " to a() function would
help :-/

Here's are some new defines

#define BEGIN_EXPORT_BLOCK(structure,
component_type) template<int n> \
struct Exporter< structure , n > { \
public: \
struct T_Export { \
typedef structure T_structure; \
typedef component_type T_component;\
Array<T_structure, n> & main; \
T_structure t; \
T_Export(Array<T_structure, n>& _input) : main
(_input) { }

#define EXPORT_MEMBER(member) \
Array<T_component, n> member() { \
int move = 0; \
while( (((T_component *) & t. ## member ) - (
((T_component*) &t) + move) ) !=0) move++; \
return main.extractComponent( T_component(),
\
move , sizeof(T_structure)/ sizeof
(T_component) ); }

#define END_EXPORT_BLOCK }; \
};

struct Sample {
int a;
int b;
int c;
};

BEGIN_EXPORT_BLOCK(Sample, int)
EXPORT_MEMBER(a)
END_EXPORT_BLOCK

// This would be implmented in Array<T, rank>

template<class T, int rank>
struct Test {
typedef Exporter<T,rank> T_Exportor;
typedef T_Exportor::T_Export T_Export;

T_Export operator*()
{
return T_Export(simplearray);
}

Array<T,1> simplearray;
};

// sample program to use them

int main()
{

Test<Sample, 1> q;
Array<int, 1> arr_a = (*q).a();
}

I have also included func.cpp with this post so that u
can test my ideas and see that this code will compile.

Just replace the old func.cpp file with this one. And if
you run into problems, just contact me. :-)

Cheers
-Suresh

Discussion

  • Suresh kumar

    Suresh kumar - 2002-10-18

    compilation test file

     
  • Julian Cummings

    Julian Cummings - 2003-10-23
    • assigned_to: nobody --> julianc
     
  • Sylwester Arabas

    • status: open --> closed
    • Group: --> Unstable (example)
     
  • Sylwester Arabas

     

Log in to post a comment.

MongoDB Logo MongoDB