Archived

This forum has been archived. Please start a new discussion on GitHub.

New Starter with Ice needs assistance on Slice syntax

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

  • marc
    marc Florida
    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;
    }
    
  • marc
    marc Florida
    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.
  • 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?
  • marc
    marc Florida
    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.
  • 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?
  • marc
    marc Florida
    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.
  • At last I see. Thanks very much Marc - that fixed the issue.