-
Notifications
You must be signed in to change notification settings - Fork 593
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
Add Support for Printing Generated Slice Types in C++ through operator<<
#3324
Comments
Proposed Implementation:ClassesThe printed representation of a class will look like:
For example, printing an instance of a class generated from this: class Device
{
int uid;
string modelName;
} could look like:
One interesting note about classes is that they could possibly be recursive.
To achieve this, we'll generate 2 additional methods for classes:
ProxiesProxies should already be fine. All user-generated proxies inherit from ostream&
Ice::operator<<(ostream& os, const Ice::ObjectPrx& p)
{
return os << p.ice_toString();
} StructsStructs would work in the exact same way as classes. Same representation, and we'd generate the same 2 functions. Sequences & DictionariesStill thinking of what to do here. EnumFor enums we would generate the enumerator name (if possible), and the raw underlying value otherwise. enum Foo { Hello, There }; we would generate this implementation directly under the enum's generated definition:
|
As I mentioned on the discussion, I would use the same formatting as the ToString synthesized for records in C#: |
Should we still make the slight adjustment of printing the memory address after the name?:
Otherwise it will be impossible to tell when 2 classes are the same instance as opposed to copies, I know that we're basing it on C#, but other languages like Python do include memory addresses when printing non-primitive types like these. |
No, we should not print pointers / memory addresses.
That's not important. In C++, you should disallow cyclic classes. I am in favor of not worrying about this hedge case at all, like the ToString synthesized by C# records. |
As discussed in https://github.com/orgs/zeroc-ice/discussions/2980, we should add support for printing generated Slice types.
We should add support for printing the following:
What should we do for exceptions?
Since exceptions are not types, they can't be held in any of the above Slice definitions.
Additionally, all the generated exceptions inherit support for
operator<<
fromIce::Exception
:ice/cpp/src/Ice/Exception.cpp
Lines 503 to 524 in 7b37d63
and we have the
cpp:ice_print
metadata, allowing users to provide their ownice_print
implementations.The text was updated successfully, but these errors were encountered: