473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

storing a map of inhomogeneous container types.

Hi everyone. I would like to consider the following problem: I want to
provide the ability to store and manipulate numeric container classes
that provide
1) element wise access
2) size
but maybe not with the same interface. For example
MatrixType1 provides [i][j] element access, and size1() and size2() for
size access. MatrixType2 provide (i,j) element access.

Now, these matrix classes might contain doubles, floats, integers,
complex numbers, whatever... The way I currently have things
implemented, I store maps of each different possiblity, like this:

class WrapperClass{
public:
....
private:
std::map<string, MatrixType1<double> m_doubleMatrix1s;
std::map<string, MatrixType2<double> m_doubleMatrix2s;
std::map<string, MatrixType1<complex> m_complexMatrix1s;
std::map<string, MatrixType2<complex> m_complexMatrix2s;
....
}

As you can imagine there's a whole lot of code duplication, becuase I
have to provide an overloaded add_matrix(string, Matrixtype) member, not
to mention overloaded members that do the kind of output I'm interested
in for each of these matrix types.

I'd like to do this instead via templating, but the problem I have is
storing the different matrix types. It would even be sufficient if I
could reduce the above example down to something like:

class WrapperClass{
public:
....
private:
std::map<string, MatrixType1<numeric_type> m_Matrix1s;
std::map<string, MatrixType2<numeric_type> m_Matrix2s;
}
where numeric_type can be double, float, int, or complex.

Unfortunately the only way I can think of to do something like this
would be to cast the container types to types of void*, which seems like
bad programming style to me.

does anyone know of a clever solution to this? Have I made my proble clear?

Thanks for your time.

Glen
Feb 4 '06 #1
1 1656
I would utilise a templated class which contains a reference (or
pointer) to whatever element it is you are attempting to put into the
matrix. That way your matrix can be coded as a concrete class and it
stores these wrapped up elements. This will allow you truly
inhomogenous behaviour in that your matrix could now hold wrappers to
any type. i.e. you *can* add apples and oranges

Feb 4 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: m | last post by:
Hello I need to use sth. like container for different types of variables. Is sth like this in c++ STL? ----|----------|--|----|------|etc. var1| var2 |v3|var4| var5 |etc. int | float...
17
by: tuvok | last post by:
How can objects of different types be stored in a collection? For example: struct S1 { /*...*/ }; struct S2 { /*...*/ }; struct Sn { /*...*/ }; template<typename T> class X { public:
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
2
by: Manish Naik | last post by:
Hi, Using ASP.Net, I want to store and retrive documents (Word, excel, etc) from SQL Server 2000 database. I have tried image type data field, but could not succed. Can any one help me please. ...
3
by: Valeriu Catina | last post by:
Hi, I have an array class (the blitz library actually) which looks like this: template<typename P_numtype, int N_rank> class Array : public MemoryBlockReference<P_numtype> , public...
11
by: toton | last post by:
Hi, all of the containers in STL stores object itself (thus copy contsructability & assignability is needed), while NTL or boost ptr_container stores pointer to the object in the container (either...
5
by: toton | last post by:
Hi, I have a deque of Point class,. Point class have two fields x, and y. Now I want another class Character should point to a portion of the deque, and allow iteration only on the portion. Thus...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
55
by: tonytech08 | last post by:
How valuable is it that class objects behave like built-in types? I appears that the whole "constructor doesn't return a value because they are called by the compiler" thing is to enable...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.