I hae tried searching the web for the answer, but, man is there a lot of
pages ... :(
in the language I develop in, if I have a structure I can dynamically
refer to the contents of a field of the structure like so:
MESSAGE SomeStructure:Field(SomeFieldName):Value
where SomeFieldName is either a quoted constant or a variable expressions
In "C", I beleive that you can refer to the contents of a
"field" in a
"structure" like so:
chan->context or
chan->exten
Is is possible to refer to these fields like
chan->(variable) where variable is either "context" or
"exten" or an
expression that resolves to a valid fieldname of the structure ?
My reason for asking is that I want to create an application that would
take a channel and a field name and return the value of the field.
for example
GetChannelData("context")
GetChannelData("exten")
and I didn't want to have to declare a massive case statement, and have
to modify the app everytime some new fields were added to the structure.
I know that some of these variables are already exposed, but was wanting
to get some other values.
Julian
Greetings,
First, you are hereby admonished for asking programming/development
questions on the user list.
C does not have a way to do this directly. Yes, you could use some
preprocessing macro but the code would be a nightmare.
You actually gave yourself the answer in your questions.
You can use a "map" data structure to do this.
GetChannelData( char* Variable )
{
return( mapX[variable] );
}
A "map" is a two dimensional array where the first column holds a
character string and the second column holds the data associated with
the array.
http://www.sgi.com/tech/stl/Map.html -- SGI gives a good reference and
some great tutorial like information on advanced data structures.
A less intense tutorial is here
http://www.cprogramming.com/tutorial/stl/stlmap.html
The STL, standard template library, is a C/C++ library that allows you
to create a map for your particular code.
You enter each "variable" and its associated value into the map.
Then you call y = mapX[ variable ] and it gives you back the value you
assigned to it.
mapX[] is not really an array, so you can do mapx[1] because there is
not really a mapX[1] value since all the indexing is done privately you
don't really know the real location of where your "variable" value
went
in the array.
For ( y = variable[x]; x < 10; x++ )
{
mapX[ y ] = x;
}
While this may look like an array of 10 items it is not, the "[]"
brackets are overloaded to make retrieving stuff eaiser.
Race "The Tyrant" Vanderdecken
An next time you have a code question be sure to use asterisk-dev list
or others my flame you.
-----Original Message-----
From: asterisk-users-bounces@lists.digium.com
[mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Asterisk
Sent: Thursday, February 24, 2005 11:42 AM
To: asterisk-users@lists.digium.com
Subject: [Asterisk-Users] OT - C structure question
I hae tried searching the web for the answer, but, man is there a lot of
pages ... :(
in the language I develop in, if I have a structure I can dynamically
refer to the contents of a field of the structure like so:
MESSAGE SomeStructure:Field(SomeFieldName):Value
where SomeFieldName is either a quoted constant or a variable
expressions
In "C", I beleive that you can refer to the contents of a
"field" in a
"structure" like so:
chan->context or
chan->exten
Is is possible to refer to these fields like
chan->(variable) where variable is either "context" or
"exten" or an
expression that resolves to a valid fieldname of the structure ?
My reason for asking is that I want to create an application that would
take a channel and a field name and return the value of the field.
for example
GetChannelData("context")
GetChannelData("exten")
and I didn't want to have to declare a massive case statement, and have
to modify the app everytime some new fields were added to the structure.
I know that some of these variables are already exposed, but was wanting
to get some other values.
Julian
_______________________________________________
Asterisk-Users mailing list
Asterisk-Users@lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users
Hi,
This is something that I tought of BEFORE I had my morning cofee.
You can use array where your 'variable" points to an array element.
You can have array of 'void *'. In this case, an array element can point
to anything.
for example:
int field1;
char *filed2;
struct MyData field3;
void * array[NUMBER_OF_ELEMENTS];
array[0] = (void *)&field1;
array[1] = (void *)field2;
array[2] = (void *)&field3;
Now you can have functions to select data:
int GetFiled1()
{
return *((int *)array[0]);
}
char * GetFiled2()
{
return (char *)array[1];
}
You got the idea.
Rudolf
-----Original Message-----
From: asterisk-users-bounces@lists.digium.com
[mailto:asterisk-users-bounces@lists.digium.com]On Behalf Of Asterisk
Sent: Friday, February 25, 2005 3:42 AM
To: asterisk-users@lists.digium.com
Subject: [Asterisk-Users] OT - C structure question
I hae tried searching the web for the answer, but, man is there a lot of
pages ... :(
in the language I develop in, if I have a structure I can dynamically
refer to the contents of a field of the structure like so:
MESSAGE SomeStructure:Field(SomeFieldName):Value
where SomeFieldName is either a quoted constant or a variable expressions
In "C", I beleive that you can refer to the contents of a
"field" in a
"structure" like so:
chan->context or
chan->exten
Is is possible to refer to these fields like
chan->(variable) where variable is either "context" or
"exten" or an
expression that resolves to a valid fieldname of the structure ?
My reason for asking is that I want to create an application that would
take a channel and a field name and return the value of the field.
for example
GetChannelData("context")
GetChannelData("exten")
and I didn't want to have to declare a massive case statement, and have
to modify the app everytime some new fields were added to the structure.
I know that some of these variables are already exposed, but was wanting
to get some other values.
Julian
_______________________________________________
Asterisk-Users mailing list
Asterisk-Users@lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users