Sophie

Sophie

distrib > Mandriva > 8.1 > i586 > by-pkgid > 700475c8ae73fb4d57b6df4485c29e1c > files > 203

slang-doc-1.4.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE> S-Lang Run-Time Library Reference: Version 1.4.0: Functions that Manipulate Structures</TITLE>
 <LINK HREF="slangfun-5.html" REL=next>
 <LINK HREF="slangfun-3.html" REL=previous>
 <LINK HREF="slangfun.html#toc4" REL=contents>
</HEAD>
<BODY>
<A HREF="slangfun-5.html">Next</A>
<A HREF="slangfun-3.html">Previous</A>
<A HREF="slangfun.html#toc4">Contents</A>
<HR>
<H2><A NAME="s4">4. Functions that Manipulate Structures</A></H2>

<P>
<H2><A NAME="_push_struct_field_values"></A> <A NAME="ss4.1">4.1 <B>_push_struct_field_values</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Push the values of a structure's fields onto the stack
<DT><B> Usage </B><DD><P><CODE>Integer_Type num = _push_struct_field_values (Struct_Type s)</CODE>
<DT><B> Description </B><DD><P>The <CODE>_push_struct_field_values</CODE> function pushes the values of
all the fields of a structure onto the stack, returning the
number of items pushed.  The fields are pushed such that the last
field of the structure is pushed first.
<DT><B> See Also </B><DD><P><CODE>get_struct_field_names, get_struct_field</CODE>
</DL>
<P>
<P>
<H2><A NAME="get_struct_field"></A> <A NAME="ss4.2">4.2 <B>get_struct_field</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Get the value associated with a structure field
<DT><B> Usage </B><DD><P><CODE>x = get_struct_field (Struct_Type s, String field_name)</CODE>
<DT><B> Description </B><DD><P>The <CODE>get_struct_field</CODE> function gets the value of the field
whose name is specified by <CODE>field_name</CODE> of the structure <CODE>s</CODE>.
<DT><B> Example </B><DD><P>The following example illustrates how this function may be used to 
to print the value of a structure.
<BLOCKQUOTE><CODE>
<PRE>
      define print_struct (s)
      {
         variable name;

         foreach (get_struct_field_names (s))
           {
             name = ();
             value = get_struct_field (s, name);
             vmessage ("s.%s = %s\n", name, string(value));
           }
      }
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> See Also </B><DD><P><CODE>set_struct_field, get_struct_field_names, array_info</CODE>
<P>
</DL>
<P>
<P>
<H2><A NAME="get_struct_field_names"></A> <A NAME="ss4.3">4.3 <B>get_struct_field_names</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Retrieve the field names associated with a structure
<DT><B> Usage </B><DD><P><CODE>String_Type[] = get_struct_field_names (Struct_Type s)</CODE>
<DT><B> Description </B><DD><P>The <CODE>get_struct_field_names</CODE> function returns an array of
strings whose elements specify the names of the fields of the
struct <CODE>s</CODE>.
<DT><B> Example </B><DD><P>The following example illustrates how the
<CODE>get_struct_field_names</CODE> function may be used to print the
value of a structure.
<BLOCKQUOTE><CODE>
<PRE>
      define print_struct (s)
      {
         variable name, value;

         foreach (get_struct_field_names (s))
           {
             name = ();
             value = get_struct_field (name);
             vmessage ("s.%s = %s\n", name, string (value));
           }
      }
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> See Also </B><DD><P><CODE>_push_struct_field_values, get_struct_field</CODE>
</DL>
<P>
<P>
<H2><A NAME="is_struct_type"></A> <A NAME="ss4.4">4.4 <B>is_struct_type</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Determine whether or not an object is a structure
<DT><B> Usage </B><DD><P><CODE>Integer_Type is_struct_type (X)</CODE>
<DT><B> Description </B><DD><P>The <CODE>is_struct_type</CODE> function returns <CODE>1</CODE> if the the parameter
refers to a structure or a user-defined type.  If the object is
neither, <CODE>0</CODE> will be returned.
<DT><B> See Also </B><DD><P><CODE>typeof, _typeof</CODE>
</DL>
<P>
<P>
<H2><A NAME="set_struct_field"></A> <A NAME="ss4.5">4.5 <B>set_struct_field</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Set the value associated with a structure field
<DT><B> Usage </B><DD><P><CODE>set_struct_field (s, field_name, field_value)</CODE>
<BLOCKQUOTE><CODE>
<PRE>
   Struct_Type s;
   String_Type field_name;
   Generic_Type field_value;
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> Description </B><DD><P>The <CODE>set_struct_field</CODE> function sets the value of the field
whose name is specified by <CODE>field_name</CODE> of the structure
<CODE>s</CODE> to <CODE>field_value</CODE>.
<DT><B> See Also </B><DD><P><CODE>get_struct_field, get_struct_field_names, set_struct_fields, array_info</CODE>
</DL>
<P>
<P>
<H2><A NAME="set_struct_fields"></A> <A NAME="ss4.6">4.6 <B>set_struct_fields</B></A>
</H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Set the fields of a structure
<DT><B> Usage </B><DD><P><CODE>set_struct_fields (Struct_Type s, ...)</CODE>
<DT><B> Description </B><DD><P>The <CODE>set_struct_fields</CODE> function may be used to set zero or more
fields of a structure.  The fields are set in the order in which
they were created when the structure was defined.
<DT><B> Example </B><DD><P>
<BLOCKQUOTE><CODE>
<PRE>
    variable s = struct { "name", "age", "height" };
    set_struct_fields (s, "Bill", 13, 64);
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> See Also </B><DD><P><CODE>set_struct_field, get_struct_field_names</CODE>
</DL>
<P>
<P>
<P>
<HR>
<A HREF="slangfun-5.html">Next</A>
<A HREF="slangfun-3.html">Previous</A>
<A HREF="slangfun.html#toc4">Contents</A>
</BODY>
</HTML>