Archived
This forum has been archived. Please start a new discussion on GitHub.
slice definition for type ID?
Just wonder if one can access the type Id of a class or struct right in slice? The reason is to use type id as indexes in Freeze store. With this index, one can easily enumerate all instances of a given slice type in the store.
Take an example "food.ice":
Suppose there is a Freeze map created by:
How can one add a Freeze Index to this map so that one can easily find all the instances of "BakedFood"? Seems there is no "ice_id" or "type_id" fields defined in Ice::Object ...
Thanks,
Peter
Take an example "food.ice":
module FoodStore
{
class Food
{
string name;
}
class BakedFood extends Food
{
int temperature;
int mintues;
}
class MyFaviouriteBread extends Food
{
}
}
Suppose there is a Freeze map created by:
slice2freeze --dict FoodStoreMap,string,FoodStore::Food FoodStoreMap food.ice
How can one add a Freeze Index to this map so that one can easily find all the instances of "BakedFood"? Seems there is no "ice_id" or "type_id" fields defined in Ice::Object ...
Thanks,
Peter
0
Comments
-
Ice::Object has an ice_id method that returns the Slice type ID. Does this help with your problem?
Cheers,
Michi.0 -
Hi michi, thanks very much for the prompt follow up.
Yes I knew that Ice::Object has a method "ice_id()", but that method is only available to C++/C#/Java programs, not available to the slice2freeze tool. In fact, the "--dict-index" option of the slice2freeze tool requires the index key to be a data member of a slice class or struct, how can one create an index using the Ice::Object::ice_id() in Freeze?
Suppose there is a "ice_id" member available for Ice::Object in slice, one can easily useslice2freeze --dict foodStoreMap,string,FoodStore::Food --dict-index foodStoreMap,ice_id food.ice
Do u know if there is already a similar thing in ICE or Freeze now? Is there any other alternatives?0 -
Sorry, but there is currently now way to do what you want because the index key has to be a member of the Slice class.
We'll consider adding this feature to a future release.
Cheers,
Michi.0 -
Note that you can achieve what you need by adding a typeID member to your FoodStore class:
module FoodStore { class Food { string typeID; string name; }; };
This will allow you to use the typeID member as the key of the index.
Cheers,
Michi.0 -
Yea, that is the workaround for now, though it is not natural since the information in the "ice_id()" method must be manually populated to that member field before an instance is writing to Freeze.
Just for ur information, maybe the slice2freeze tool can be added a new option like"--dict-index-by-type xxxMap"
Anyway, hope ICE can get even more popular this way, and best wishes...0