Ice Sheet System Model  4.18
Code documentation
StringArrayParam.cpp
Go to the documentation of this file.
1 
5 /*header files: */
6 /*{{{*/
7 #ifdef HAVE_CONFIG_H
8  #include <config.h>
9 #else
10 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11 #endif
12 
13 #include "../classes.h"
14 #include "../../shared/shared.h"
15 /*}}}*/
16 
17 /*StringArrayParam constructors and destructor*/
19  return;
20 }
21 /*}}}*/
22 StringArrayParam::StringArrayParam(int in_enum_type,char** in_values, int in_numstrings){/*{{{*/
23 
24  this->enum_type=in_enum_type;
25  this->numstrings=in_numstrings;
26 
27  if(numstrings){
28  this->value=xNew<char*>(numstrings);
29  for(int i=0;i<numstrings;i++){
30  int size=strlen(in_values[i])+1;
31  char* string=xNew<char>(size);
32  xMemCpy<char>(string,in_values[i],size);
33  this->value[i]=string;
34  }
35  }
36  else{
37  this->value=NULL;
38  }
39 
40 }
41 /*}}}*/
43 
44  int i;
45 
46  char* string=NULL;
47  for(i=0;i<this->numstrings;i++){
48  string=value[i];
49  xDelete<char>(string);
50  }
51  xDelete<char*>(value);
52 }
53 /*}}}*/
54 
55 /*Object virtual functions definitions:*/
57 
58  return new StringArrayParam(this->enum_type,this->value,this->numstrings);
59 
60 }
61 /*}}}*/
62 void StringArrayParam::DeepEcho(void){/*{{{*/
63 
64  _printf_(setw(22)<<" StringArrayParam "<<setw(35)<<left<<EnumToStringx(this->enum_type)<<" {");
65  for(int i=0;i<this->numstrings;i++) _printf_(" '"<<this->value[i]<<"'");
66  _printf_("}\n");
67 }
68 /*}}}*/
69 void StringArrayParam::Echo(void){/*{{{*/
70  this->DeepEcho();
71 }
72 /*}}}*/
73 int StringArrayParam::Id(void){ return -1; }/*{{{*/
74 /*}}}*/
75 void StringArrayParam::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/
76 
77  int* sizes=NULL;
78 
79  if(marshall_direction==MARSHALLING_FORWARD || marshall_direction==MARSHALLING_SIZE){
80  if(numstrings)sizes=xNew<int>(numstrings);
81  for(int i=0;i<numstrings;i++)sizes[i]=strlen(value[i])+1;
82  }
83 
85 
88 
89  if(numstrings){
91  if(marshall_direction==MARSHALLING_BACKWARD) value=xNew<char*>(numstrings);
92  for(int i=0;i<numstrings;i++)MARSHALLING_DYNAMIC(value[i],char,sizes[i]);
93  }
94  else value=NULL;
95 
96  //cleanup sizes array
97  if(sizes) xDelete<int>(sizes);
98 
99 }
100 /*}}}*/
102 
103  return StringArrayParamEnum;
104 
105 }
106 /*}}}*/
107 
108 /*StringArrayParam virtual functions definitions: */
109 void StringArrayParam::GetParameterValue(char*** pstringarray,int* pM){/*{{{*/
110 
111  int i;
112  char** outstrings=NULL;
113  int M;
114  char* string=NULL;
115  char* string2=NULL;
116  int stringsize;
117 
118  M=this->numstrings;
119  if(this->numstrings){
120  outstrings=xNew<char*>(this->numstrings);
121 
122  for(i=0;i<this->numstrings;i++){
123  string=this->value[i];
124  stringsize=strlen(string)+1;
125 
126  string2=xNew<char>(stringsize);
127  xMemCpy<char>(string2,string,stringsize);
128 
129  outstrings[i]=string2;
130  }
131  }
132  else outstrings=NULL;
133 
134  /*Assign output pointers:*/
135  if(pM) *pM=M;
136  *pstringarray=outstrings;
137 }
138 /*}}}*/
139 void StringArrayParam::SetValue(char** stringarray,int M){/*{{{*/
140 
141  int i;
142  char *string = NULL;
143  char *string2 = NULL;
144  int stringsize;
145 
146  /*first, avoid leak: */
147  for(i=0;i<this->numstrings;i++){
148  string=this->value[i];
149  xDelete<char>(string);
150  }
151  xDelete<char*>(this->value);
152 
153  /*copy: */
154  this->numstrings=M;
155  this->value=xNew<char*>(this->numstrings);
156  for(i=0;i<this->numstrings;i++){
157  string=stringarray[i];
158  stringsize=strlen(string)+1;
159 
160  string2=xNew<char>(stringsize);
161  xMemCpy<char>(string2,string,stringsize);
162 
163  this->value[i]=string2;
164  }
165 }
166 /*}}}*/
Param
Definition: Param.h:21
_printf_
#define _printf_(StreamArgs)
Definition: Print.h:22
StringArrayParam::copy
Param * copy()
Definition: StringArrayParam.cpp:56
StringArrayParam::Echo
void Echo()
Definition: StringArrayParam.cpp:69
MARSHALLING_ENUM
#define MARSHALLING_ENUM(EN)
Definition: Marshalling.h:14
StringArrayParam::GetParameterValue
void GetParameterValue(bool *pbool)
Definition: StringArrayParam.h:42
MARSHALLING_SIZE
@ MARSHALLING_SIZE
Definition: Marshalling.h:11
StringArrayParam::ObjectEnum
int ObjectEnum()
Definition: StringArrayParam.cpp:101
StringArrayParam::~StringArrayParam
~StringArrayParam()
Definition: StringArrayParam.cpp:42
MARSHALLING_DYNAMIC
#define MARSHALLING_DYNAMIC(FIELD, TYPE, SIZE)
Definition: Marshalling.h:61
StringArrayParam::value
char ** value
Definition: StringArrayParam.h:24
StringArrayParam::DeepEcho
void DeepEcho()
Definition: StringArrayParam.cpp:62
StringArrayParam::enum_type
int enum_type
Definition: StringArrayParam.h:23
EnumToStringx
const char * EnumToStringx(int enum_in)
Definition: EnumToStringx.cpp:15
StringArrayParam::numstrings
int numstrings
Definition: StringArrayParam.h:25
MARSHALLING
#define MARSHALLING(FIELD)
Definition: Marshalling.h:29
MARSHALLING_BACKWARD
@ MARSHALLING_BACKWARD
Definition: Marshalling.h:10
StringArrayParamEnum
@ StringArrayParamEnum
Definition: EnumDefinitions.h:1290
MARSHALLING_FORWARD
@ MARSHALLING_FORWARD
Definition: Marshalling.h:9
StringArrayParam::SetValue
void SetValue(bool boolean)
Definition: StringArrayParam.h:60
StringArrayParam::StringArrayParam
StringArrayParam()
Definition: StringArrayParam.cpp:18
StringArrayParam::Marshall
void Marshall(char **pmarshalled_data, int *pmarshalled_data_size, int marshall_direction)
Definition: StringArrayParam.cpp:75
StringArrayParam::Id
int Id()
Definition: StringArrayParam.cpp:73