Changeset 308 for cpp/frams/_demos


Ignore:
Timestamp:
01/26/15 04:16:31 (5 years ago)
Author:
Maciej Komosinski
Message:

After loading, objects are printed ("saved") to standard output. Additional information and messages are printed to standard error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/loader_test_param.cpp

    r307 r308  
    33// See LICENSE.txt for details.
    44
    5 #include "genotypeloader.h"
     5#include <frams/param/multiparamload.h>
    66#include <frams/virtfile/stdiofile.h>
    77#include <frams/errmgr/stdouterr.h>
     
    99/**
    1010 @file
    11  Sample code: Loading framsticks "objects" (well... structs)
     11 Sample code: Loading Framsticks "objects" (structures).
     12
     13 After loading, objects are printed ("saved") to standard output.
     14 Additional information and messages are printed to standard error.
     15 You can redirect both streams if needed.
    1216
    1317 \include loader_test_param.cpp
     
    3034        { "longtext", 0, 0, "Long text", "s 1", FIELD(longtext), }, // 1 = multiline, 0 = unlimited
    3135        { "i1", 0, 0, "Integer 1", "d", FIELD(i1), },          // unrestricted integer
    32         { "i2", 0, 0, "Integer 1", "d -5 5 1", FIELD(i2), }, // [-5..5] integer, default=1
    33         { "i3", 0, 0, "Integer 1", "d 0 3 0 ~Zero~One~Two~Three", FIELD(i3), }, // [0..3] + text labels (Param::getText())
     36        { "i2", 0, 0, "Integer 2", "d -5 5 1", FIELD(i2), }, // [-5..5] integer, default=1
     37        { "i3", 0, 0, "Integer 3", "d 0 3 0 ~Zero~One~Two~Three", FIELD(i3), }, // [0..3] + text labels (Param::getText())
    3438        { "f1", 0, 0, "Float 1", "d", FIELD(f1), },          // unrestricted float
    3539        { "f2", 0, 0, "Float 2", "f -100 100 -100", FIELD(f2), }, // [-100..100] float, default=-100
     
    4852
    4953        StdioFILEDontClose virt_stderr(stderr);
     54        StdioFILEDontClose virt_stdout(stdout);
    5055        StdoutErrorHandler error_handler(0, &virt_stderr);
    5156        StdioFileSystem_autoselect stdiofilesys;
     
    6368                {
    6469                case MultiParamLoader::OnComment:
    65                         printf("comment: %s\n", (const char*)loader.getComment());
     70                        fprintf(stderr, "comment: %s\n", (const char*)loader.getComment());
    6671                        break;
    6772
    6873                case MultiParamLoader::AfterObject:
    69                         printf("loaded:\n");
     74                        fprintf(stderr, "loaded:\n");
    7075                        for (int i = 0; i < param.getPropCount(); i++)
    71                                 printf("%s=%s\n", param.id(i), (const char*)param.getText(i));
    72                         printf("type of 'x' is: %s\n", (const char*)data.x.typeDescription());
    73                         printf("-----\n\n");
     76                                fprintf(stderr, "%s=%s\n", param.id(i), (const char*)param.getText(i));
     77                        fprintf(stderr, "type of 'x' is: %s\n", (const char*)data.x.typeDescription());
     78                        fprintf(stderr, "-----\n\n");
     79                        param.save(&virt_stdout);
    7480                        break;
    7581
    7682                case MultiParamLoader::BeforeObject:
    77                         printf("----- object found, loading...\n");
     83                        fprintf(stderr, "----- object found, loading...\n");
    7884                        param.setDefault(); //reset (initialize) struct contents
    7985                        break;
    8086
    81                 case MiniGenotypeLoader::OnError:
     87                case MultiParamLoader::OnError:
    8288                        fprintf(stderr, "Error: %s", (const char*)loader.getError());
    8389                }
    8490        }
     91        return 0;
    8592}
Note: See TracChangeset for help on using the changeset viewer.