home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1996, 1997 Meta Four Software. All rights reserved.
- //
- // Datafile dump utility sample code, adapted to use bound data
- //
- //! rev="$Id: kbdump.cpp,v 1.1 1997/05/27 10:42:34 jcw Rel $"
-
- #include "m4kit.h"
- #include "kbound.h"
-
- #include <stdio.h>
-
- /////////////////////////////////////////////////////////////////////////////
- // This code was taken from the DUMP sample program without any changes
-
- static void ViewDisplay(const c4_View& v_, int l_ =0)
- {
- c4_String types;
- bool hasData = false, hasSubs = false;
-
- // display header info and collect all data types
- printf("%*s VIEW %5d rows =", l_, "", v_.GetSize());
- for (int n = 0; n < v_.NumProperties(); ++n)
- {
- c4_Property prop = v_.NthProperty(n);
- char t = prop.Type();
-
- printf(" %s:%c", (const char*) prop.Name(), t);
-
- types += t;
-
- if (t == 'V')
- hasSubs = true;
- else
- hasData = true;
- }
- printf("\n");
-
- for (int j = 0; j < v_.GetSize(); ++j)
- {
- if (hasData) // data properties are all shown on the same line
- {
- printf("%*s %4d:", l_, "", j);
- c4_RowRef r = v_[j];
- c4_Bytes data;
-
- for (int k = 0; k < types.GetLength(); ++k)
- {
- c4_Property p = v_.NthProperty(k);
-
- switch (types[k])
- {
- case 'I':
- printf(" %ld", (long) ((c4_IntProp&) p) (r));
- break;
-
- case 'F':
- printf(" %g", (double) ((c4_FloatProp&) p) (r));
- break;
-
- case 'D':
- printf(" %.12g", (double) ((c4_DoubleProp&) p) (r));
- break;
-
- case 'S':
- printf(" '%s'", (const char*) (c4_String)
- ((c4_StringProp&) p) (r));
- break;
-
- case 'B':
- (p (r)).GetData(data);
- printf(" (%db)", data.Size());
- break;
-
- default:
- if (types[k] != 'V')
- printf(" (%c?)", types[k]);
- }
- }
-
- printf("\n");
- }
-
- if (hasSubs) // subviews are then shown, each as a separate block
- {
- for (int k = 0; k < types.GetLength(); ++k)
- {
- if (types[k] == 'V')
- {
- c4_Property prop = v_.NthProperty(k);
-
- printf("%*s %4d: subview '%s'\n", l_, "", j,
- (const char*) prop.Name());
-
- if (l_ > 0 || k > 0)
- {
- c4_ViewProp& vp = (c4_ViewProp&) prop;
-
- ViewDisplay(vp (v_[j]), l_ + 2);
- }
- }
- }
- }
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
-
- int main(int argc, char** argv)
- {
- // when called with a file, use that - else use the bound object
- c4_Storage* store = argc > 1 ? new c4_Storage (argv[1], false)
- : new c4_BoundStorage;
-
- // this is the same as in the DUMP example
- ViewDisplay(store->Contents().Container());
-
- delete store;
-
- return 0;
- }
-
- /////////////////////////////////////////////////////////////////////////////
-