Changeset 8564


Ignore:
Timestamp:
06/08/11 14:09:17 (14 years ago)
Author:
jschierm
Message:

Option objects: Added Get method for vector of strings to OptionChar.

Location:
issm/trunk/src/c/objects/Options
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/objects/Options/Option.h

    r8535 r8564  
    4848                virtual void  Get(bool* pvalue)=0;
    4949                virtual void  Get(char** pvalue)=0;
     50                virtual void  Get(char*** ppvalue,int *pnumel)=0;
    5051                virtual void  Get(double** pvalue,int *pnumel)=0;
    5152                virtual void  Get(Options** pvalue)=0;
    52                 virtual void  Get(Options*** pvalue,int *pnumel)=0;
     53                virtual void  Get(Options*** ppvalue,int *pnumel)=0;
    5354
    5455};
  • issm/trunk/src/c/objects/Options/OptionCell.h

    r8535 r8564  
    4545                void  Get(bool* pvalue){  _error_("An OptionCell object cannot return a bool");};
    4646                void  Get(char** pvalue){ _error_("An OptionCell object cannot return a string");};
     47                void  Get(char*** ppvalue,int *pnumel){ _error_("An OptionCell object cannot return a string vec");};
    4748                void  Get(double** pvalue,int *pnumel){ _error_("An OptionCell object cannot return a double vec");};
    4849                void  Get(Options** pvalue);
    49                 void  Get(Options*** pvalue,int *pnumel){ _error_("An OptionCell object cannot return an Options DataSet vec");};
     50                void  Get(Options*** ppvalue,int *pnumel){ _error_("An OptionCell object cannot return an Options DataSet vec");};
    5051
    5152};
  • issm/trunk/src/c/objects/Options/OptionChar.cpp

    r7746 r8564  
    7272void  OptionChar::DeepEcho(char* indent){
    7373
    74         int   i;
     74        int   i,nstr,ipt=0;
    7575        int*  dims;
    7676        char  indent2[81];
     
    8585
    8686        if (values) {
    87 //              if (numel == 1) {
    88                 if (1) {
    89 //                      _printf_(flag,"%s        values: \"%s\"\n" ,indent,values[0]);
     87                if (ndims == 2 && size[0] == 1) {
    9088                        _printf_(flag,"%s        values: \"%s\"\n" ,indent,values);
    9189                }
    9290                else {
     91                        nstr=size[0];
     92                        for (i=2; i<ndims; i++) nstr*=size[i];
     93
    9394                        dims=(int *) xmalloc(ndims*sizeof(int));
    94                         for (i=0; i<numel; i++) {
    95                                 RowWiseDimsFromIndex(dims,i,size,ndims);
     95                        for (i=0; i<nstr; i++) {
     96                                RowWiseDimsFromIndex(dims,ipt,size,ndims);
    9697                                StringFromDims(cstr,dims,ndims);
    97                                 _printf_(flag,"%s        values%s: \"%s\"\n" ,indent,cstr,values[i]);
     98                                _printf_(flag,"%s        values%s: \"%.*s\"\n" ,indent,cstr,size[1],&(values[ipt]));
     99                                ipt+=size[1];
    98100                        }
    99101                        xfree((void**)&dims);
     
    141143}
    142144/*}}}*/
     145/*FUNCTION OptionChar::Get(char*** ppvalue,int *pnumel) {{{1*/
     146void OptionChar::Get(char*** ppvalue,int *pnumel){
     147
     148        char* outstring=NULL;
     149        int   stringsize;
     150        int   i,nstr,ipt=0;
     151
     152        /*We should first check that the size is at least one*/
     153        if(this->NumEl()<=0){
     154                _error_("option \"%s\" is empty and cannot return a string vector",this->name);
     155        }
     156
     157        /*Calculate the size and number of strings*/
     158        stringsize=this->size[1]+1;
     159        nstr=this->size[0];
     160        for (i=2; i<this->ndims; i++) nstr*=this->size[i];
     161
     162        /*Break concatenated string into individual strings*/
     163        *ppvalue=(char **) xmalloc(nstr*sizeof(char *));
     164        for (i=0; i<nstr; i++) {
     165                outstring=(char*)xmalloc(stringsize*sizeof(char));
     166                memcpy(outstring,&(this->values[ipt]),(stringsize-1)*sizeof(char));
     167                outstring[stringsize-1]='\0';
     168                (*ppvalue)[i]=outstring;
     169                ipt+=stringsize-1;
     170        }
     171
     172        /*Assign output pointer*/
     173        if(numel) *pnumel=nstr;
     174}
     175/*}}}*/
  • issm/trunk/src/c/objects/Options/OptionChar.h

    r8535 r8564  
    4545                void  Get(bool* pvalue){  _error_("An OptionChar object cannot return a bool");};
    4646                void  Get(char** pvalue);
     47                void  Get(char*** ppvalue,int *pnumel);
    4748                void  Get(double** pvalue,int *pnumel){ _error_("An OptionChar object cannot return a double vec");};
    4849                void  Get(Options** pvalue){ _error_("An OptionChar object cannot return an Options DataSet");};
    49                 void  Get(Options*** pvalue,int *pnumel){ _error_("An OptionChar object cannot return an Options DataSet vec");};
     50                void  Get(Options*** ppvalue,int *pnumel){ _error_("An OptionChar object cannot return an Options DataSet vec");};
    5051
    5152};
  • issm/trunk/src/c/objects/Options/OptionDouble.h

    r8535 r8564  
    4545                void  Get(bool* pvalue){  _error_("An OptionDouble object cannot return a bool");};
    4646                void  Get(char** pvalue){ _error_("An OptionDouble object cannot return a string");};
     47                void  Get(char*** ppvalue,int *pnumel){ _error_("An OptionDouble object cannot return a string vec");};
    4748                void  Get(double** pvalue,int* pnumel);
    4849                void  Get(Options** pvalue){ _error_("An OptionDouble object cannot return an Options DataSet");};
    49                 void  Get(Options*** pvalue,int *pnumel){ _error_("An OptionDouble object cannot return an Options DataSet vec");};
     50                void  Get(Options*** ppvalue,int *pnumel){ _error_("An OptionDouble object cannot return an Options DataSet vec");};
    5051
    5152};
  • issm/trunk/src/c/objects/Options/OptionLogical.h

    r8535 r8564  
    4545                void  Get(bool* pvalue);
    4646                void  Get(char** pvalue){ _error_("An OptionLogical object cannot return a string");};
     47                void  Get(char*** ppvalue,int *pnumel){ _error_("An OptionLogical object cannot return a string vec");};
    4748                void  Get(double** pvalue,int *pnumel){ _error_("An OptionLogical object cannot return a double vec");};
    4849                void  Get(Options** pvalue){ _error_("An OptionLogical object cannot return an Options DataSet");};
    49                 void  Get(Options*** pvalue,int *pnumel){ _error_("An OptionLogical object cannot return an Options DataSet vec");};
     50                void  Get(Options*** ppvalue,int *pnumel){ _error_("An OptionLogical object cannot return an Options DataSet vec");};
    5051
    5152};
  • issm/trunk/src/c/objects/Options/OptionStruct.cpp

    r8535 r8564  
    138138}
    139139/*}}}*/
    140 /*FUNCTION OptionStruct::Get(Options*** pvalue,int* numel) {{{1*/
    141 void OptionStruct::Get(Options*** pvalue,int* numel){
     140/*FUNCTION OptionStruct::Get(Options*** ppvalue,int* numel) {{{1*/
     141void OptionStruct::Get(Options*** ppvalue,int* numel){
    142142
    143143        /*We should first check that the size is at least one*/
     
    147147
    148148        /*Assign output pointer*/
    149         *pvalue=this->values;
     149        *ppvalue=this->values;
    150150        if(numel) *numel=this->NumEl();
    151151}
  • issm/trunk/src/c/objects/Options/OptionStruct.h

    r8535 r8564  
    4545                void  Get(bool* pvalue){  _error_("An OptionStruct object cannot return a bool");};
    4646                void  Get(char** pvalue){ _error_("An OptionStruct object cannot return a string");};
     47                void  Get(char*** ppvalue,int *pnumel){ _error_("An OptionStruct object cannot return a string vec");};
    4748                void  Get(double** pvalue,int *pnumel){ _error_("An OptionStruct object cannot return a double vec");};
    4849                void  Get(Options** pvalue);
    49                 void  Get(Options*** pvalue,int *pnumel);
     50                void  Get(Options*** ppvalue,int *pnumel);
    5051
    5152};
Note: See TracChangeset for help on using the changeset viewer.