Home Comments

slice definition for type ID?

peterlspotpeterlspot Member Peter LauOrganization: SelfProject: Study
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":
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 ... :confused:

Thanks,
Peter

Comments

  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    Ice::Object has an ice_id method that returns the Slice type ID. Does this help with your problem?

    Cheers,

    Michi.
  • peterlspotpeterlspot Member Peter LauOrganization: SelfProject: Study
    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 use
    slice2freeze --dict foodStoreMap,string,FoodStore::Food --dict-index foodStoreMap,ice_id food.ice
    to create an index to the Freeze map.

    Do u know if there is already a similar thing in ICE or Freeze now? Is there any other alternatives?
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    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.
  • michimichi Member Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-) ✭✭✭
    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.
  • peterlspotpeterlspot Member Peter LauOrganization: SelfProject: Study
    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"
    so that a typeId index is added to a map. This way, the change is limited to the "slice2freeze" tool only and no need to change the current SLICE spec.

    Anyway, hope ICE can get even more popular this way, and best wishes...
Sign In or Register to comment.