--- val.pod 2002/01/17 12:19:09 1.7
+++ val.pod 2002/01/17 13:01:58 1.8
@@ -239,51 +239,106 @@
=head1 EXAMPLES
-=over 4
-
-=item simple create, reg, get, destroy
-
- #include <stdio.h>
- #include "val.h"
-
- int main(void)
- {
- val_rc_t rc;
- val_t *v;
- int example;
- int pullout;
-
- if ((rc = val_create(&v)) != VAL_OK) exit(-1);
- if ((rc = val_reg(v, "foo", VAL_TYPE_INT, "foo variable", (void *)&example)) != VAL_OK) exit(-1);
- example = 123;
- if ((rc = val_get(v, "foo", &pullout)) != VAL_OK) exit(-1);
- printf("pulled example and got %d\n", pullout);
- if ((rc = val_destroy(v)) != VAL_OK) exit(-1);
- return 0;
- }
-
-=item reg inline data, structured name, set
-
- #include <stdio.h>
- #include "val.h"
-
- int main(void)
- {
- val_rc_t rc;
- val_t *v1, *v2;
- int pullout;
-
- if ((rc = val_create(&v1)) != VAL_OK) exit(-1);
- if ((rc = val_create(&v2)) != VAL_OK) exit(-1);
- if ((rc = val_reg(v1, "bar", VAL_TYPE_VAL, "child", (void *)&v2)) != VAL_OK) exit(-1);
- if ((rc = val_reg(v1, "bar.foo", VAL_TYPE_INT, "foo variable", NULL)) != VAL_OK) exit(-1);
- if ((rc = val_set(v2, "foo", 456)) != VAL_OK) exit(-1);
- if ((rc = val_get(v1, "bar.foo", &pullout)) != VAL_OK) exit(-1);
- printf("pulled example and got %d\n", pullout);
- if ((rc = val_destroy(v2)) != VAL_OK) exit(-1);
- if ((rc = val_destroy(v1)) != VAL_OK) exit(-1);
- return 0;
- }
+A few simple examples on how to use B<OSSP val> are following. For
+easier reading all error checks are omitted. In a production program you
+have to check every val_xxx() call against C<VAL_OK>, of course.
+
+=head2 Simple Internal Value
+
+Source:
+
+ #include <stdio.h>
+ #include "val.h"
+
+ int main(void)
+ {
+ val_rc_t rc;
+ val_t *v;
+ int tmp;
+
+ val_create(&v);
+ val_reg(v, "foo", VAL_TYPE_INT, "foo variable", NULL);
+ val_set(v, "foo", 123);
+ val_get(v, "foo", &tmp);
+ printf("foo=%d\n", tmp);
+ val_destroy(v);
+ return 0;
+ }
+
+Output:
+
+ foo=123
+
+=head2 Simple External Value
+
+Source:
+
+ #include <stdio.h>
+ #include "val.h"
+
+ int main(void)
+ {
+ val_rc_t rc;
+ val_t *v;
+ int foo;
+ int tmp;
+
+ val_create(&v);
+ val_reg(v, "foo", VAL_TYPE_INT, "foo variable", (void *)&foo);
+ foo = 123;
+ val_get(v, "foo", &tmp);
+ printf("1. foo=%d tmp=%d\n", foo, tmp);
+ val_set(v, "foo", 456);
+ val_get(v, "foo", &tmp);
+ printf("2. foo=%d tmp=%d\n", foo, tmp);
+ example = 789;
+ val_get(v, "foo", &tmp);
+ printf("3. foo=%d tmp=%d\n", foo, tmp);
+ val_destroy(v);
+ return 0;
+ }
+
+Output:
+
+ 1. foo=123 tmp=123
+ 2. foo=456 tmp=456
+ 3. foo=789 tmp=789
+
+=head2 Structured Internal Values
+
+Source:
+
+ #include <stdio.h>
+ #include "val.h"
+
+ int main(void)
+ {
+ val_rc_t rc;
+ val_t *v1, *v2;
+ int tmp;
+
+ val_create(&v1);
+ val_create(&v2);
+ val_reg(v1, "bar", VAL_TYPE_VAL, "v2", (void *)&v2);
+ val_reg(v1, "bar.foo", VAL_TYPE_INT, "foo variable", NULL);
+ val_set(v2, "foo", 123);
+ val_get(v2, "foo", &tmp);
+ printf("1. foo=%d\n", tmp);
+ val_get(v1, "bar.foo", &tmp);
+ printf("2. bar.foo=%d\n", tmp);
+ val_set(v1, "bar.foo", 456);
+ val_get(v2, "foo", &tmp);
+ printf("3. foo=%d\n", tmp);
+ val_destroy(v2);
+ val_destroy(v1);
+ return 0;
+ }
+
+Output:
+
+ 1. foo=123
+ 2. bar.foo=123
+ 3. foo=456
=back
|