|
(Using VS 2008 C++)
Is it safe to use a size specifier in enum declaration ?
typedef enum MyEnum : int
{
e1,
e2,
e3
} MyEnum;
This will generate a warning :
C4480 : nonstandard extension used: specifying underlying type for enum 'enum'.
Is this just an informative warning that it will not do what it is supposed to do or will it really type my enum values as int values ?
For what I can read it looks kosher and when/if we switch to VS2010/2011
Thanks.
Watched code never compiles.
|
|
|
|
|
Yes it is safe, unless you switch to a compiler that doesn't support it. In pre-VC11 compilers, I believe it has no meaning and is essentially ignored.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
what is ignored ? I assume the warning.
I tested with different size specifier and it returns the appropriate size; so I assume it's safe.
Thanks.
Watched code never compiles.
|
|
|
|
|
Sorry about the long post but its a bit of complex subject matter.
I'm trying to do a data-binding system in C++ similar to that found in WPF.
WPF uses the built-in C# reflection mechanism to map an XML data binding tag to a method or field in a object. It can also binding collection classes to list controls.
I want to do the same but in C++. I'm writing the back-end system so I need to provide a data-binding/reflection type system for other programmers to use.
Requirements:
Here is an example usage for the system.
The programmers will define their own classes and somehow expose their classes functions and member variables to the the data binding system. They could then create a collection class, containing instances of those classes.
They specify the UI elements in a XML format, and include the data binding reference for certain widget types.
They would then expose the collection class to the widget, probably using data-binding, which will bind the collection class a list widget. The list widget would then iterate through the list and for each element would invoke a function call, by mapping the binding name to a class function or reading the data directly out of the object structure.
What I have so far:
I've created an interface class (IReflection) which provides a number of pure virtual methods. A programmer wanting to expose their classes methods/member variables would inherit for the interface.
I've managed to expose the member variables by using a static class which takes a static function pointer that belongs to the class. This then creates a temporary instance of the class, which is then used to build a table of byte offsets for each member variable. This static array belongs to the class. One of the IReflection methods, takes a string lookup name, finds it in the array, gets the byte offset back and reads the data at that point. The lookup table also contains the size of the type of data to prevent buffer overruns.
This works OK, except its pretty nasty and feels like a bit of hack. Also it gets around private access
as the code is just reading a piece of memory.
I have a slightly harder problem when it comes to executing member functions. I want to be able to create function pointers to call the methods that are exposed. However I don't want to create member function pointers as I would need to create them for every instance and I think that would be a waste of memory. Therefore I need to provide static functions which as essentially proxy functions that take a pointer to the instance and then call the member function on it.
This is making the code look messy and unmanageable and I'm not happy with any of the solutions I have.
I have found lots of information on-line for providing reflection in C++, but none of them provide the ability to invoke methods or read/write properties, which is essential for a UI to display and change values.
I am starting to think I should provide a method in the IReflection interface that takes a string and returns the type of data required. It would then be up to the programmer to define this function. They could simply just write 'if-else if' code and do the necessary string compares and execute the correct code.
That feels like the easy option for me, but I'm concerned how much work I'm generating for others by taking the easy option.
It would be nice to be able to expose the data binding using a set of macros, similar to RTTI to make it easier for the programmer to define the code. However I'm not a fan of macro code as it is impossible to debug.
I should say this is a UI system for a game engine, so I can't go around allocating lots of memory, I don't want lots of small allocations as this is bad for memory fragmentation and the data cache. It also needs to work quickly. I'll probably eventual turn the strings into hashes and do hash table lookup but that is a implementation detail for performance reasons and doesn't have to be done straight away.
Does anyone know how this could be done or know of any examples of this type of system. Not sure if you would call this problem 'dynamic data-binding' or 'reflection'.
Any advice would be appreciated.
Thanks
|
|
|
|
|
For dynamically invoking methods, you could take an approach similar to the COM dual interfaces: take a look at
IDispatch[^].
Basically, there's a method called GetTypeInfo, which describes your current object. Then there is GetIDsOfNames, which maps a method to an ID, and finally, Invoke, which -tadaaaah- invokes que method, passing the ID as parameter.
This is how languages such as VB6 used to work with COM interfaces. Not sure, however, on whether you should use good ol' IDispatch or implement your own interfaces, suited to your needs. But I think the approach could help you: by knowing how many methods are available, and being able to invoke them through an ID or index.
Cheers!
|
|
|
|
|
Thanks, I'll take a look at how the IDispatch interface works.
I should have said also mentioned this system needs to work across multiple platforms, like PC, XBOX360 and PS3 and many others. So I can copy the solution from existing technologies but I won't be able to use them directly, as for example COM doesn't exist on a PS3.
Thanks again.
|
|
|
|
|
Fair enough, but you could try the approach, which by the way is pretty much how .NET Reflection works (retrieves the method info throught the MethodInfo collection, and then call Invoke). The only difference is that in .NET the runtime provides the Type information, while here you should implement it on your own. Other than that, IDispatch only provides a way of accessing the methods through an index, which you could also implement, rather than creating your own MethodInfo and so methods.
Cheers!
|
|
|
|
|
C++ has no built-in mechanism for reflection.
You'd have to role your own or use a third party toolset.
Googling reflection C++[^] yields a lot of relevant results.
Good luck!
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
Game Programming Gems 5[^]
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun
|
|
|
|
|
Looking for suggestions here. In Asp.net, I was able to use the SqlDataSourceEnumerator object to look for SQL Servers on the network.
I've been doing research, and it looks like in c++, you have to write something yourself to do the job.
So I'm thinking that I have to write a winsock function that broadcasts a UDP packet on port 1434, and waits for a response packet.
I saw the article in the Code Project, but it was for C#. And my skill is far from being able to translate all of it into c++. I understand what it does, I just cant figure out how to broadcast, instead of sending a packet to a know destination.
Anyways,
Any Suggestions or pointers are welcomed.
|
|
|
|
|
Is this of any help?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
It looks good so far, let me work with it.
I need to get better at search words in code project, I tried SQLBrowser, Enumerating SQL Servers, and some other words, didn't try find SQL Server
|
|
|
|
|
it's MFC, my stdafx conflicts with afx, I have a straight VS2010 win32 app.
oh well, thanks
|
|
|
|
|
My mistake, the NetServerEnum does work in c++, and is what I was looking for.
Thanks
|
|
|
|
|
I have a CRC code for particuler string. I need to get the string corssspoding to CRC.
My mean to say I need to generate all possible combination of string from lenght 1 to n untill I get the desired CRC value. I know, string may be different from original one.
How can I acoomplish this in a fast way?
|
|
|
|
|
You can't, CRC is one way only: see here[^].
|
|
|
|
|
I am getting the desired string which generate given CRC but it slow because I am generating string from length 1 to n. Is there a way to make it faster?
Or Can I get the string legnth from CRC?
|
|
|
|
|
john5632 wrote: Is there a way to make it faster?
It's unlikely, given that you have to try every possible combination.
john5632 wrote: Can I get the string legnth from CRC?
No, it's a one-way value.
|
|
|
|
|
But I read somwhat like this somewhere that do some opeartion with calculated CRC untill we get zero?
Is there something like this?
|
|
|
|
|
john5632 wrote: But I read somwhat like this somewhere
Well I guess you need to use Google to find the reference again.
|
|
|
|
|
It sounds the same to me the same as trying to take a 128 bit md5 hash and regenerate the data that this hash corresponds to. You quite simply cannot do it accurately.
a md5 may be used to hash anything from a 5 character password to a 700MB iso file - yet in both instances the hash will still be 128 bits long. While you can generate sequences of characters that will produce the same result when hashed/CRCed, there's no relaiable way without context of choosing the original string.
|
|
|
|
|
Do you know what CRCs are for?
They are for checking the validity of the data, to make sure it hasnt got corrupted. It is not a representation of the data, it is merely a numerical sum of the data.
Therefore you cannot reconstruct the data from the CRC.
If you wanted to know all the strings that could create a particular check sum you would have to run through all the permutations and calculate the sum.
==============================
Nothing to say.
|
|
|
|
|
I know I can not construct data from CRC, my aim is to get the string which generate the same CRC value
|
|
|
|
|
I don't know if it is just a typo but ... your aim is impossible to get.
There are infinite strings that can give the same CRC.
So first start to think as "plural", then ... the only way is "try/retry/retry ...." until you retain to have enough of them.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
john5632 wrote: ...my aim is to get the string which generate the same CRC value
So are you wanting help with permutations or creating a CRC? Those are two unrelated tasks.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
modified 17-Oct-11 10:37am.
|
|
|
|