473,486 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

dynamcially created data structure

Is it possible to dynamically create a data structure?

Not that it matters, but just for understanding, I am working with
video shaders, these shaders use thier own language (HLSL) which you
compile at runtime and run for rendering. The HLSL can contain many
differant types of variables and expect your application to set them.

The library provides the ability to query for
number of variables
thier names
thier types
and provides a method for setting them that is depedent on the type

My goal is to package them, no matter what they are, into a single
material class, that can be used no matter what the HLSL it
corresponds to looks like.

So, I want the same data structure that is capable of setting, for
example, two floats in one case, a float and a string in another case,
7 floats and an array of UDTs in another case, etc.
My first thought was to create a class that had a one map for every
possible type, but I am not sure that is the best.

I was also thinking of making seperate "Material Property" classes
that could be added and removed from a "Material", but its fuzzy.

Any ideas?

Oct 9 '08 #1
3 1578
Christopher wrote:
Is it possible to dynamically create a data structure?
Not really. You can implement your own mechanism for type information
and then use it, but C++ is *statically typed* language, which means
that all types participating in the program are known at the compile
time. The only "exception" to that is the dynamic binding mechanism
that allows you to supply a pointer to the base class and expect the
derived class' virtual function to be called. But you already know
about this one.
Not that it matters, but just for understanding, I am working with
video shaders, these shaders use thier own language (HLSL) which you
compile at runtime and run for rendering. The HLSL can contain many
differant types of variables and expect your application to set them.

The library provides the ability to query for
number of variables
thier names
thier types
and provides a method for setting them that is depedent on the type

My goal is to package them, no matter what they are, into a single
material class, that can be used no matter what the HLSL it
corresponds to looks like.

So, I want the same data structure that is capable of setting, for
example, two floats in one case, a float and a string in another case,
7 floats and an array of UDTs in another case, etc.
My first thought was to create a class that had a one map for every
possible type, but I am not sure that is the best.

I was also thinking of making seperate "Material Property" classes
that could be added and removed from a "Material", but its fuzzy.

Any ideas?
I suspect that something like that has already been done. Perhaps
asking in 'comp.graphics.algorithms' or searching on the Web might help.
What you're describing looks essentially like a system for managing
types in a compiler or an interpreter. There are plenty of examples of
those on the Web, I'm certain of it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 9 '08 #2
Christopher wrote:
Is it possible to dynamically create a data structure?

Not that it matters, but just for understanding, I am working with
video shaders, these shaders use thier own language (HLSL) which you
compile at runtime and run for rendering. The HLSL can contain many
differant types of variables and expect your application to set them.

The library provides the ability to query for
number of variables
thier names
thier types
and provides a method for setting them that is depedent on the type

My goal is to package them, no matter what they are, into a single
material class, that can be used no matter what the HLSL it
corresponds to looks like.

So, I want the same data structure that is capable of setting, for
example, two floats in one case, a float and a string in another case,
7 floats and an array of UDTs in another case, etc.
Assuming you have a fixed set of operations, you could look at wrapping
the base types in a container class with a fixed set of operators and
working with those.
My first thought was to create a class that had a one map for every
possible type, but I am not sure that is the best.

I was also thinking of making seperate "Material Property" classes
that could be added and removed from a "Material", but its fuzzy.
That sounds a bit like my suggestion, investigate it further.

--
Ian Collins
Oct 9 '08 #3
Christopher <cp***@austin.rr.comwrites:
Is it possible to dynamically create a data structure?
Yes.

Not that it matters, but just for understanding, I am working with
video shaders, these shaders use thier own language (HLSL) which you
compile at runtime and run for rendering. The HLSL can contain many
differant types of variables and expect your application to set them.

The library provides the ability to query for
number of variables
thier names
thier types
and provides a method for setting them that is depedent on the type
Then you already have it here. What other data structure do you want,
beyond what that library provides?

My goal is to package them, no matter what they are, into a single
material class, that can be used no matter what the HLSL it
corresponds to looks like.
Ok so you want to write some wrapper, to be able to use it abstractly,
because that library doesn't already provide the abstract layer.

So, I want the same data structure that is capable of setting, for
example, two floats in one case, a float and a string in another case,
7 floats and an array of UDTs in another case, etc.
Well, having a single abstract class for the interface doesn't remove
that it will be simplier to treat each of the case in a different
concrete subclass, so the implementation of your wrapper won't be a
single class.
My first thought was to create a class that had a one map for every
possible type, but I am not sure that is the best.

I was also thinking of making seperate "Material Property" classes
that could be added and removed from a "Material", but its fuzzy.

Any ideas?

So here is your single abstract data structure capable of setting:

class Data{
virtual void setHLSLData(hslshandle*)=0;
};
Now you can define subclasses for each of the C++ data types you need
to set.

class IntData{
protected: int value;
public: IntData(int aValue):value(aValue){};
public: virtual void setHLSLData(hslshandle* hslsdata){
if(hslsType(hslsdata)==hslsInteger){
hslsSetInteger(hslsdata,value);
}else{
throw TypeError("Cannot assign an int to a "+hslsTypeName(hslsdata));;
}
}
};

and so on for the other data types. You can also use templates to
define a bunch of then.

If you have structures or vectors, you can easily define a subclass of
Data with a map of fieldName to Data items, or a vector of Data items,
etc.

--
__Pascal Bourguignon__
Oct 10 '08 #4

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

Similar topics

1
2783
by: Reed Law | last post by:
I have the exact same data in two arrays, but only the array created like so will work: $spaw_imglibs = array( array( 'value' => '/youth/pics/Member pics/', 'text' => 'Member pics', ),...
2
1899
by: Dariusz | last post by:
I have written a database that counts the number of times a file has been accessed, so I can then later display the results on what is "hot" and what is not. At the moment all it does is count the...
14
3515
by: Peter Olcott | last post by:
I want to be able to efficiently build data structures at run-time. These data structures need to be accessed with minimal time. The only a few ways that come immediately to mind would be some...
3
2348
by: Mike Jones | last post by:
need help with data structures.Looking for ways to start, sample code, anything Program description: Design and implement a Visual C++ .NET program that inserts values into a data...
2
6445
by: yee young han | last post by:
I need a fast data structure and algorithm like below condition. (1) this data structure contain only 10,000 data entry. (2) data structure's one entry is like below typedef struct _DataEntry_...
16
2413
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables...
3
2178
by: David | last post by:
Hello, I have a datagrid populated with rows from a view. Because they are from a view, the rows are not actual database records, and therefore lack unique identifiers. So I have a command...
9
7093
by: Tushar | last post by:
Followup-To: microsoft.public.dotnet.general Does anyone know when is this event raised, is it: 1) When the file is created but may not have been closed 2) When the file is created AND it has...
8
1778
by: =?ISO-8859-1?Q?m=E9choui?= | last post by:
Problem: - You have tree structure (XML-like) that you don't want to create 100% in memory, because it just takes too long (for instance, you need a http request to request the information from...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.