Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 11-13-2005
surfer surfer is offline
Registered User
 
 
Join Date: Jun 2005
Location: Germany
Posts: 38
Red face Slice and array???

Hello,

I've a question about Slice:
How is it possible to define a transmit or return value of an array?
In the documentation I didn't found some examples by using an array.


example how I would like to use it at XXX.java:
Code:
public String[] getArray(Ice.Current current){
    	String [] array = new String[100];
	array[0] = "test1";
	array[1] = "test2";
	array[2] = "test3";
	................
    	
    	return array 
}


public int getArraySize(String[] array, Ice.Current current){
	int iSize = array.length; 
    	return iSize 
}
but how is the definition in Slice XXX.ice:
Code:
#ifndef XXX_ICE
#define XXX_ICE

// here the array definitions ?????????????????

module YYY
{
interface xxx
{
    nonmutating string String[] getArray();
    nonmutating int getArraySize(String[] array);
};
};
#endif
Has somebody an solution or example ?


Thanks a lot greetings surfer
__________________
Philipp Henkel Brunel University London MSc student.
MSc dissertation: Centralized controlling of distributed application servers. Used tools: FC3, W2k, XP, Apache2, PHP5 , ICE-PHP and ICE-Java.

Last edited by surfer : 11-13-2005 at 10:33 AM.
Reply With Quote
  #2 (permalink)  
Old 11-13-2005
marc's Avatar
marc marc is offline
ZeroC Staff
 
Name: Marc Laukien
Organization: ZeroC, Inc.
Project: The Internet Communications Engine
 
Join Date: Feb 2003
Location: Florida
Posts: 1,781
You must use sequences. Please see the Ice manual for details.
Reply With Quote
  #3 (permalink)  
Old 11-14-2005
surfer surfer is offline
Registered User
 
 
Join Date: Jun 2005
Location: Germany
Posts: 38
Thumbs up My solution ??

Hallo Marc,

thanks a lot for your tip !!!

Here the code which works for me. Please correct me if something is wrong.


Hello.ice:
Code:
#ifndef HELLO_ICE
#define HELLO_ICE

module Demo
{
exception GenericError {
    	string reason;
    };

sequence<string> sa;

interface Hello
{

    nonmutating void sayHello();
    idempotent void shutdown();
    nonmutating sa getArray();
    nonmutating void sendArray(sa text);
};

};

#endif
HelloI.java:
Code:
public String[]
    getArray(Ice.Current current)
    {
	    array = new String[100];
	    array[0] = "Test0";
	    array[1] = "Test1";
	    array[2] = "Test2";
	    array[3] = "Test3";
	    
        return array;
    }
    
    public void
    sendArray(String[] arrayGet, Ice.Current current)
    {
	    array = arrayGet;
	    int iCounter = 0;
	    while(iCounter<4){
		    String s = array[iCounter];
		    System.out.println("Array content "+iCounter+":>"+s);		    
            iCounter++;
	    }
    }


Client.java:
Code:
if(line.equals("t"))
                {
                    twoway.sayHello();
			        String[] sa = twoway.getArray();
			        int iCounter = 0;
			        while(iCounter<4){
			            String s = sa[iCounter];
			            System.out.println("Client content "+iCounter+":>"+s);		    
                        iCounter++;
                    }
	        
			
                }
                else if(line.equals("o"))
                {
                    oneway.sayHello();
			        String[] array = new String[100];
			        array[0] = "C_Test0";
			        array[1] = "C_Test1";
			        array[2] = "C_Test2";
			        array[3] = "C_Test3";
			        twoway.sendArray(array);
                }
Thanks a lot
greetings surfer
__________________
Philipp Henkel Brunel University London MSc student.
MSc dissertation: Centralized controlling of distributed application servers. Used tools: FC3, W2k, XP, Apache2, PHP5 , ICE-PHP and ICE-Java.

Last edited by surfer : 11-14-2005 at 05:14 AM.
Reply With Quote
  #4 (permalink)  
Old 11-14-2005
michi's Avatar
michi michi is offline
ZeroC Staff
 
Name: Michi Henning
Organization: ZeroC
Project: Ice
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 912
[quote=surfer]
Quote:
Code:
public String[]
    getArray(Ice.Current current)
    {
	    array = new String[100];
	    array[0] = "Test0";
	    array[1] = "Test1";
	    array[2] = "Test2";
	    array[3] = "Test3";
	    
        return array;
    }
    
    public void
    sendArray(String[] arrayGet, Ice.Current current)
    {
	    array = arrayGet;
	    int iCounter = 0;
	    while(iCounter<4){
		    String s = array[iCounter];
		    System.out.println("Array content "+iCounter+":>"+s);		    
            iCounter++;
	    }
    }
Why allocate an array of 100 elements when you are sending only four elements? When you return this array, the Ice run time will marshal 4 non-empty strings, followed by 96 empty strings.

Quote:
Client.java:
Code:
                    twoway.sayHello();
			        String[] sa = twoway.getArray();
			        int iCounter = 0;
			        while(iCounter<4){
			            String s = sa[iCounter];
			            System.out.println("Client content "+iCounter+":>"+s);		    
                        iCounter++;
                    }
When receiving the array, use the array length to bound the loop:
Code:
String[] sa = twoway.getArray();
int iCounter = 0;
while(iCounter < sa.length)
    System.out.println(sa[iCounter]);
Cheers,

Michi.
Reply With Quote
  #5 (permalink)  
Old 11-14-2005
surfer surfer is offline
Registered User
 
 
Join Date: Jun 2005
Location: Germany
Posts: 38
Hello michi,

thanks for your answer,
I've just set the array size to 100 for testing not for special use.
But I will attend that in my application.

Thanks a lot
greetings surfer
__________________
Philipp Henkel Brunel University London MSc student.
MSc dissertation: Centralized controlling of distributed application servers. Used tools: FC3, W2k, XP, Apache2, PHP5 , ICE-PHP and ICE-Java.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
effects of C++ Array Mapping for Sequences smu Help Center 6 01-12-2007 04:35 PM
Memory problem using dictionary or array as parameters enrico Help Center 6 03-27-2006 12:35 PM
how to pass binary char array to remote host efficiatively? socketref Help Center 7 09-18-2005 11:15 AM
slice array type mapping to c++ yomi Help Center 2 04-05-2004 12:32 AM


All times are GMT -4. The time now is 10:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2008 ZeroC, Inc.