Пример #1
0
idl_tag_info *pgsql_get_idl_tag_info(IDL_STRUCT_TAG_DEF *tagdefs)
{
    idl_tag_info *ti;
    int32 i, tag;
    char *tagName;

    ti = (idl_tag_info *) calloc(1, sizeof(idl_tag_info));

    ti->sdef = (IDL_StructDefPtr) IDL_MakeStruct(0, tagdefs);

    /* get offsets and descriptions */
    ti->ntags = IDL_StructNumTags(ti->sdef);

    ti->tagOffsets = calloc(ti->ntags, sizeof(IDL_MEMINT));
    ti->tagDesc    = calloc(ti->ntags, sizeof(IDL_VPTR));
    ti->tagNelts   = calloc(ti->ntags, sizeof(int32));

    i=0;
    for (tag=0; tag< ti->ntags; tag++)
    {
        tagName = 
            IDL_StructTagNameByIndex(ti->sdef, tag, 
                    IDL_MSG_INFO, NULL);

        ti->tagOffsets[tag] = 
            IDL_StructTagInfoByIndex(ti->sdef, 
                    tag, 
                    IDL_MSG_LONGJMP,
                    &(ti->tagDesc[tag]) );

        if (VERBOSE)
            printf("    Tag %d = \"%s\" ", tag, tagName);

        /* Is this an array? */
        if ( (ti->tagDesc[tag]->flags & IDL_V_ARR) != 0)
        {
            ti->tagNelts[tag] = ti->tagDesc[tag]->value.arr->n_elts;
            if (VERBOSE)
                printf(" ARRAY[%d] ", ti->tagNelts[tag]);
        }
        else
        {
            ti->tagNelts[tag] = 1;
            if (VERBOSE)
                printf(" SCALAR ");
        }
        if (VERBOSE)
            printf("\n");

    }

    return(ti);

}
Пример #2
0
int IDLStruct::assign(IDL_VPTR st) { // constructor
  
  int i;
  IDL_VPTR desc;
  char *struct_name;

  // point at the idl structure
  idlStruct = st;
  n_elements = idlStruct->value.arr->n_elts;
  
  num_tags = IDL_StructNumTags(idlStruct->value.s.sdef);
  
  // allocate the vectors
  tag_names.resize(num_tags); 
  tag_offsets.resize(num_tags);
  tag_desc.resize(num_tags);

  for(i=0;i<num_tags;i++)
    {

      tag_names[i] = IDL_StructTagNameByIndex(idlStruct->value.s.sdef, i, 
					     IDL_MSG_LONGJMP, &struct_name);

      tagIndexHash[tag_names[i]] = i;

      tagOffsetsHash[tag_names[i]] = 
	IDL_StructTagInfoByIndex(idlStruct->value.s.sdef, i, IDL_MSG_LONGJMP,
				 &desc);
      tagDescHash[tag_names[i]] = desc; 
     
      tag_offsets[i] = tagOffsetsHash[tag_names[i]];
      tag_desc[i] = desc;

    }

  idlStructName = struct_name;

  //aoffset = 
  //  getTagInfoFromIDLStruct(idlStruct, "A", IDL_TYP_FLOAT, 
  //			    adesc);

  return(1);

}
Пример #3
0
void getobjectdetails( IDL_VPTR var, void *data, char *taglist[],
                       char hdstype[], int *numtags,
                       int *ndims, int dims[], int *elt_len, int *status ) {

    UCHAR idltype;     /* Type of variable */
    int i;             /* counter */
    int *vardim;
    IDL_VPTR tmpvar;
    IDL_LONG offset;
    char *dimptr;
    char *tok;

    if ( *status != SAI__OK ) return;
    /* Type */
    idltype = var->type;
    strcpy(hdstype, gethdstype( idltype ));

    if ( var->flags & IDL_V_STRUCT ) {
        /* Structure */
        *numtags = IDL_StructNumTags( var->value.s.sdef );
        *elt_len = var->value.s.arr->elt_len;
        if ( var->value.s.arr->n_elts == 1 )
            *ndims = 0;
        else
            *ndims = (int)var->value.s.arr->n_dim;
        vardim = (int *)var->value.s.arr->dim;
        for ( i=0; i<*ndims; i++ ) dims[i] = vardim[i];

        if ( !strcmp( *taglist, "HDSSTRUCTYPE" ) ) {
            /* Get the tag info */
            offset = IDL_StructTagInfoByIndex(
                         var->value.s.sdef, 0, IDL_MSG_LONGJMP, &tmpvar );
            strcpy( hdstype, IDL_STRING_STR((IDL_STRING *)data+offset) );
        }

        /* If it's an array structure -    */
        if ( dimptr=strpbrk(hdstype,"(") ) {
            /*    terminate hdstype at the (   */
            *dimptr++ = '\0';
            /*    and get the array dimensions */
            for ( i=0; tok=strtok(i?NULL:dimptr,",)"); i++ ) {
                dims[i] = atoi(tok);
            }
        }
        *ndims = i;

    } else if ( var->flags & IDL_V_ARR ) {
        /* Primitive Array */
        *numtags = 0;;
        *ndims = (int)var->value.arr->n_dim;
        vardim = (int *)var->value.s.arr->dim;
        for ( i=0; i<*ndims; i++ ) dims[i] = vardim[i];

    } else {
        /* Primitive scalar */
        *numtags = 0;
        *ndims = 0;
    }

    /*    if it's IDL_STRING find the largest string size */
    if ( idltype == 7 ) {
        strcat(hdstype,"*");
        i = getidlstringsize(var,(IDL_STRING *)data);
        sprintf(hdstype+6,"%d",i);
    }

    return;
}
Пример #4
0
int IDLStruct::MakeTagInfo(
        IDL_VPTR structvptr, 
        TAG_INFO_STRUCT& taginfo)
{

    int status=0;
    if (structvptr->type != IDL_TYP_STRUCT)
    {
        IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_INFO,
                "The input variable must be a structure");
        return(status);
    }

    IDL_STRING *tptr;


    //------------------------------------------------------------------
    // Initialize the tag info structure
    // structvptr points to the input structdef
    //------------------------------------------------------------------


    taginfo.NumTags = IDL_StructNumTags(structvptr->value.s.sdef);
    mNtags = taginfo.NumTags;

    taginfo.TagNames.resize(taginfo.NumTags);
    taginfo.TagOffsets.resize(taginfo.NumTags);
    taginfo.TagDesc.resize(taginfo.NumTags);
    taginfo.TagBytes.resize(taginfo.NumTags);
    taginfo.TagNelts.resize(taginfo.NumTags);

    taginfo.BytesPerRow = 0;
    taginfo.NStrings=0;

    //---------------------------------------------------------------------------
    // Get the tag info
    //---------------------------------------------------------------------------



    for (IDL_MEMINT tag=0; tag<taginfo.NumTags; tag++)
    {
        // Get tag name
        taginfo.TagNames[tag] = IDL_StructTagNameByIndex(structvptr->value.s.sdef, tag, 
                IDL_MSG_INFO, NULL);
        taginfo.TagMap[taginfo.TagNames[tag]] = tag;

        // Get tag offsets and the tag description variable (a copy?)
        taginfo.TagOffsets[tag] = IDL_StructTagInfoByIndex(structvptr->value.s.sdef, 
                tag, 
                IDL_MSG_LONGJMP,
                &(taginfo.TagDesc[tag]) );
        if (M_DEBUG) 
        {
            cout <<"    Tag "<<tag<<" = "<<taginfo.TagNames[tag].c_str();
            cout <<"    TagMap[\"" 
                << taginfo.TagNames[tag] << "\"] = " <<
                taginfo.TagMap[ taginfo.TagNames[tag] ] << endl;
        }

        // Deal with arrays
        if ( (taginfo.TagDesc[tag]->flags & IDL_V_ARR) != 0)
        {
            // this is just for convenience
            taginfo.TagNelts[tag] = taginfo.TagDesc[tag]->value.arr->n_elts;
            if (M_DEBUG) cout<<" ARRAY["<<taginfo.TagNelts[tag]<<"] ";
        }
        else
        {
            taginfo.TagNelts[tag] = 1;
            if (M_DEBUG) cout<<" SCALAR ";
        }


        // Number of bytes for this variable type.
        if (taginfo.TagDesc[tag]->type == IDL_TYP_STRING) 
        {

            // WARNING: This assumes that the elements in string arrays are all
            // the same size
            tptr = (IDL_STRING *) (structvptr->value.s.arr->data + taginfo.TagOffsets[tag]);
            taginfo.TagBytes[tag] = tptr->slen;

            taginfo.NStrings++;

        }
        else 
            taginfo.TagBytes[tag] = IDLTypeNbytes(taginfo.TagDesc[tag]->type);

        // Bytes in each row
        taginfo.BytesPerRow += taginfo.TagBytes[tag]*taginfo.TagNelts[tag];

        if (M_DEBUG) 
        {
            PrintIdlType(taginfo.TagDesc[tag]->type);
            cout<<" "<<taginfo.TagBytes[tag]<<" bytes";
        }


        if (M_DEBUG) cout<<endl;


    }

    // Add the tag defs for use creating a new struct or substruct
    MakeTagDefs(structvptr, taginfo, taginfo.stagdefs);
    status=1;
    return(status);

}