Home Help Center

New Starter with Ice needs assistance on Slice syntax

Ian MeyersIan Meyers Member Ian MeyersOrganization: Barclays CapitalProject: Managed Service for Data Grid Computing
Hello,

This question has probably been answered before on the forum, but due to the broad nature of the query I was unable to find exactly the right post. I am just getting started with Ice and am trying to create the Slice file. My object model is similar to the following:

struct a {
string someValue;
sequence<b> setOfBs;
}

struct b {
string otherValue;
a parentA;
}

interface doSomething {
void doX(a value);
void doY(b value);
}

I have attempted to model the above as interfaces with forward declarations, as structs, putting each struct in its own file, putting all the structs together and then referencing it with an include, and non of this is working.

Can the kind forum members please advise on the best Slice file format for the above? Should the structures be struct, class, or interface? Should I use forward delcarations to get around the mutual dependency or is there another mechanism? Should each object be in a single file for the common module, or do they have to be separate with includes?

Thanks in advance,

Ian Meyers

Comments

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Only classes and interfaces support forward declaration. See Forward Declarations - Ice 3.4 - ZeroC

    For example:
    class a;
    
    class b { // This could also be a struct
        string otherValue;
        a parentA;
    }
    
    sequence<b> bSeq;
    
    class a {
        string someValue;
        bSeq setOfBs;
    }
    

    You could also use:
    class b;
    sequence<b> bSeq;
    
    class a { // This could also be a struct
        string someValue;
        bSeq setOfBs;
    }
    
    class b {
        string otherValue;
        a parentA;
    }
    
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Should the structures be struct, class, or interface? Should I use forward delcarations to get around the mutual dependency or is there another mechanism?

    Of course, if you can write your code without circular dependencies, then I would do so, but sometimes this is not possible.
  • Ian MeyersIan Meyers Member Ian MeyersOrganization: Barclays CapitalProject: Managed Service for Data Grid Computing
    Understood. However, I'm still having issues with the compiler throwing

    Operator.ice
    :49: `softwareVersions' has changed meaning

    given:
    module service {
    	class Cluster;				
    	class SoftwareVersions;
    	class Cluster {
    			string name;
    			int size;
    			long startTime;
    			string status;
    			string environmentType;
    			bool debugMode;
    			bool requireSecurity;
    			SoftwareVersions softwareVersions;
    			sequence<Member> members;
    			
    	};
    };
    

    where line 49 is 'SoftwareVersions softwareVersions;' for example. I appreciate I need to sort the sequence of Member type, which has been omitted for brevity. Can you please advise on what the above error means?
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    With Ice, Identifiers are case-insensitive but must be capitalized consistently. See: Lexical Rules - Ice 3.4 - ZeroC

    In your example, the identifier "SoftwareVersions" is used first as a class name and then redefined as a data member. To make the error go away, use identifiers that do not differ by capitalization only.
  • Ian MeyersIan Meyers Member Ian MeyersOrganization: Barclays CapitalProject: Managed Service for Data Grid Computing
    Not sure I understand. What I'm trying to indicate is that a Cluster has a data member of type SoftwareVersions. Is this not the correct syntax to indicate this concept?
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    It is correct, you just cannot name the data member "softwareVersions" if you use "SoftwareVersions" as a class name already. You could for example use "softwareVers" or similar.
  • Ian MeyersIan Meyers Member Ian MeyersOrganization: Barclays CapitalProject: Managed Service for Data Grid Computing
    At last I see. Thanks very much Marc - that fixed the issue.
Sign In or Register to comment.