Results 1 to 8 of 8

Thread: New Starter with Ice needs assistance on Slice syntax

  1. #1
    Ian Meyers is offline Registered User
    Name: Ian Meyers
    Organization: Barclays Capital
    Project: Managed Service for Data Grid Computing
    Join Date
    Aug 2011
    Posts
    4

    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

  2. #2
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    Only classes and interfaces support forward declaration. See Forward Declarations - Ice 3.4 - ZeroC

    For example:

    Code:
    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:

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

  3. #3
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    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.

  4. #4
    Ian Meyers is offline Registered User
    Name: Ian Meyers
    Organization: Barclays Capital
    Project: Managed Service for Data Grid Computing
    Join Date
    Aug 2011
    Posts
    4

    Arrow

    Understood. However, I'm still having issues with the compiler throwing

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

    given:

    Code:
    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?
    Last edited by Ian Meyers; 08-31-2011 at 04:16 AM. Reason: hard to read code without code block

  5. #5
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    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.

  6. #6
    Ian Meyers is offline Registered User
    Name: Ian Meyers
    Organization: Barclays Capital
    Project: Managed Service for Data Grid Computing
    Join Date
    Aug 2011
    Posts
    4

    Arrow

    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?

  7. #7
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    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.

  8. #8
    Ian Meyers is offline Registered User
    Name: Ian Meyers
    Organization: Barclays Capital
    Project: Managed Service for Data Grid Computing
    Join Date
    Aug 2011
    Posts
    4

    Thumbs up

    At last I see. Thanks very much Marc - that fixed the issue.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 05-28-2009, 11:05 PM
  2. Any editor with SLICE syntax highlight ?
    By hack in forum Help Center
    Replies: 2
    Last Post: 09-27-2004, 09:17 AM
  3. Glacier Starter not support in Windows?
    By yomi in forum Help Center
    Replies: 5
    Last Post: 04-23-2004, 06:42 PM
  4. sequences syntax
    By panic in forum Help Center
    Replies: 1
    Last Post: 12-04-2003, 08:55 AM
  5. What is the "proxy" Slice syntax for?
    By dthomson in forum Help Center
    Replies: 2
    Last Post: 03-07-2003, 08:04 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •