-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
classByType<std::string> throws classNotFound #107
Comments
I am able to reproduce this by modifying
Then compiling
This compilation error can be avoid by declaring However running egtest with this code would throw the classNotFound exception on class type
Not that this is the only way to do pass by reference for a string. As reported in a one of the previous issues, using string& would not work because it acts like pass by value in both CAMP and PONDER. I am trying to port a project which used CAMP to PONDER. Because of this, I am basically stuck. |
Ok, I'll have some time this weekend. I'll take a look. 👍 |
Thanks, Billy. Another note. In CAMP, to get rid of this runtime error, I had to also add the following line. Class::declarestd::string("String"); But this did not work for PONDER. Basically I need a metaclass function to be able to do call by reference, either by string& or string*. Otherwise the function defined becomes useless for me. |
Which platform, compiler, and versions please. I am currently unable to reproduce this. |
Red Hat Linux g++ 4.8.5. |
Ok, on the CI tests, gcc 4.8.4 passes: https://travis-ci.org/billyquith/ponder/jobs/456345131 |
Are you able to test on a more recent version of the compiler? 4.8.5 is from 2015. I have experienced bugs with GCC before. |
Sure. I will give it a try. Thanks |
One question. Is using ninja to build ponder absolutely required? I had a hard time installing ninja and dnf on my system. I simply used "cmake . && make" to make ponder and it completed with no error. |
No you can use any build system. I just used Ninja for the example. |
I reproduced this on OSX (Mac) using ninja to build as well. My changes in test/examples/simple.cpp are as follows:
Platform and compiler are OSX Apple LLVM version 9.1.0 (clang-902.0.39.2). |
I attached my modified complete simple.cpp above. Please help to see if it reproduces in your system. Thanks, |
Why are you trying to register |
As I mentioned earlier, if I did not register it, the code would not compile. If the function's argument type is the basic pass by value type std::string, I did not have to register. For the pointer type std::string*, I had to for some reason. For the reference type std::string&, it was a whole different issue and the registration did not help either. |
I think I figure out where the issue is. It comes down to the difference in declaring a metaclass between CAMP and PONDER. In CAMP, it is defined as follows. static ClassBuilder declare(const std::string& name) A metaclass declared can be given an arbitrary name as long as it is unique. Ponder declares it as follows. static ClassBuilder ponder::Class::declare (IdRef id = ponder::Id()) It does not allow a metaclass declared to be given an arbitrary name. Based on the implementation of detail::ClassManager::addClass(), the name given should be either empty or be the same as the C++ class typename. That is, if I declare the metaclass std::string as ponder::Class::declarestd::string(""); or ponder::Class::declarestd::string("std::string"); The simple.cpp code I attached above would run fine. |
It ran fine after I registered and metaclass declared std::string. But after that the ponder::Value::kind() for std::string return type ponder::User instead of ponder::String. Do you know why and a workaround? Thanks, |
I wonder if you have reproduced this problem and know a solution for it? |
Sorry, I was on holiday. ⛅️ I did have a look and I think the problem is that Your workaround is to register
In the above call, at the point of setting the argument, we can dereference |
Welcome back and thanks for your help as always. For CAMP, if I need to use any reference simple type, such as int or string, as a function argument, I also need to register the simple type. However CAMP is able to preserve the simple type in Value. The simple type after registration is lost in Ponder. It becomes the User type and as a result I am not able to convert it back to the simple type. The conversion would throw an exception, similar to the following: value of type user couldn't be converted to type int |
I want to add that once I registered the simple type, any property getter which returns this simple type becomes a User type. This seems to already happen at the class declaration time when the property is added to the class builder. If I do not register the simple type, then the property getter returning type is correct. But I had to do the registration to get the code compiled and run. With a User type, I won't be able to retrieve the property value back to the simple type. This is the dilemma that I am facing. |
I spent some time to track down the reason for this behavior to the following
This says if a type, including any basic type, is registered as a ponder type, it is automatically considered as a user defined type. I guess we could exclude some C++ basic types in the Boolean expression of enable_if(). |
I think I would rather not allow basic types (handled by The change you are suggesting would allow basic types to be passed as UserTypes, but I think there would be complications where this turns out to be ambiguous. One solution is to add pointer versions of the basic types to value (assuming that they are all references, and not owned). |
I agree . The best fix is to allow to use pointer to a basic type without having to register that basic type as a User type. I am not sure if defining ValueMapper<T*> would make that happen. But I am happy to find a solution by modifying the AccessTraits. Note that CAMP works exactly like this. To use a pointer type to a basic type, you need to register that basic type and declare it as a metaclass. |
I created two new issues which summarize the discussions in this thread. |
I'll close this issue as we created two other issues. V3.1 is now released which fixes one of those issues. The other issue is covered in #109. |
My code tries to declare a class which has a std::string property.
The code compiled but it threw classNotFound exception on classByTypestd::string() at runtime for some reason.
Does anyone know what was going on here? The call was called by ponder implicitly. I added the following line in the example program simple.cpp and it threw the same runtime exception.
simple.cpp's Person class also has a std::string property but it runs fine. What have I missed?
Thanks,
The text was updated successfully, but these errors were encountered: