473,549 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ 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 1585
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.r r.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(hsl shandle*)=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(a Value){};
public: virtual void setHLSLData(hsl shandle* hslsdata){
if(hslsType(hsl sdata)==hslsInt eger){
hslsSetInteger( hslsdata,value) ;
}else{
throw TypeError("Cann ot 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
2787
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', ), array( 'value' => '/youth/pics/Group pictures/',
2
1903
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 total hits, it does not log per-month the results, which is what I'd like to try. So suppose I have a database that on initial creation (in month...
14
3527
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 sort of dynamically allocated array of : (1) void pointers, that must be cast into the desired types. (2) union of the desired pointers. (3) An...
3
2364
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 structure and then removes them as described below.
2
6450
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_ { char szInput; char szOutput; int iSum;
16
2423
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 (se below) then I run a query giving me a running total, which give me the first stock in the batch purchased by an individual, then I use this...
3
2184
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 button for each row. When the button is pressed, I want to go to another page with all the information in that selected row. Normally I would do...
9
7107
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 been closed I am using this control in a Windows-Service I've developed. It works hoever the problem I'm having is that the file does not seem to be...
8
1789
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 a slow distant site). - But you want to be able to request data from it, such has "give me all nodes that are under a "//foo/bar" tree, and have a...
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7967
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3505
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3488
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.