Hi Jan,
1) In regards to your first question, you said you're using
STAFMapClassDefinition::create() and addKey() to create a list of objects.
So, you're creating a list of map class objects? I assume you're using
the STAFMapClassDefinition class to define the map class definition and
then using the STAFObject class's createList() method to create a list of
map objects as the root object and then using the STAFObject class's
createMarshallingContext() method to create a marshalling context and
you're using the setMapClassDefinition() method to set a
STAFMapClassDefinition for the marshalling context and using the
setMarshalingContext() method to set the root object to be a list of map
class objects. Then you're using the marshall() method to marshall the
marshalling context and return it. Is this what you're doing? Did you
write a custom C++ STAF service and one of its requests returns marshalled
data for a list of map objects?
Here's an example of creating a marshalling context whose root object is a
list of map class objects and the map class definition has been set for
the marshalling context . You can look at most any STAF C++ service code
(e.g. src/staf/services/respool/STAFResPoolService.cpp) for examples of
creating marshalled data.
// Construct map class for a resource
STAFMapClassDefinitionPtr fResourceClass =
STAFMapClassDefinition::create("MyService/Resource");
fResourceClass->addKey("entry", "Entry");
fResourceClass->addKey("owner", "Owner");
// Create a list of 5 resource map class objects
STAFObjectPtr resourceList = STAFObject::createList();
// Append an entry to resourceList for each resource
for (unsigned int i = 1; i < 6; i++)
{
// Create a Resource map class object for each resource
STAFObjectPtr resourceMap = fResourceClass->createInstance();
resourceMap->put("entry", STAFString("Resource") + i);
resourceMap->put("owner", STAFString("Owner") + i);
// Add the entry in a marshalling context as a map to resourceList
resourceList->append(resourceMap);
}
// Create a marshalled list of resource map class objects
STAFObjectPtr mc = STAFObject::createMarshallingContext();
mc->setMapClassDefinition(fResourceClass->reference());
mc->setRootObject(resourceList);
// Return the marshalled result of the query
return STAFResultPtr(new STAFResult(kSTAFOk, mc->marshall()),
STAFResultPtr::INIT);
2) In regards to your second question, are you asking about how the STAF
command line executable formats marshalled data or how the STAF C++
STAFMarshallingContext class's asFormattedString() method formats
marshalled data? If you're asking about how the STAF command line
executable formats marshalled data, this is discussed in the STAF User's
Guide in section "5.2 STAF" at
http://staf.sourceforge.net/current/STAFUG.htm#HDRSTAFEXECMD. Note that
the STAF executable accepts an optional -verbose option to force the use
of the verbose mode for the output. For example:
STAF -verbose FS LIST DIRECTORY /tmp LONG
When structured data is returned in the result strings above, the STAF
command will automatically unmarshall the data and print it in the most
appropriate format. If the table format is used, the following
environment variables can be set to effect the formatting of the result in
a table format:
- STAF_TABLE_WIDTH: Set to the maximum width of the table. It defaults
to 79 if not specified.
- STAF_TABLE_LINES_PER_RECORD: Set to the maximum number of lines that
are displayed per record. It defaults to only display the first 20 lines
(the last line will show "(More...)" to indicate that there were more
lines in the record.
-STAF_PRINT_NO_TABLES: Set to any value to disable the output of tables.
If you disable the outpout of tables, the data will show up in the verbose
mode (same as specifying the -verbose option).
Or, if you're asking how to format marshalled data via a C++ program, you
can use the asFormattedString() method of the C++ STAFObject class.
There's an example in section "6.3.3 STAFObjectIterator" in the STAF
User's Guide. Note that the marshalling context from a STAF service
request is available in the 'resultContext' variable of the STAFResultPtr
and the root object for the marshalling context (e.g. a list, or a map, or
a string) is available in the 'resultObj' variable of the STAFResultPtr
(assuming auto-unmarshalling has not been disabled for the handle). You
can print the result in a "Pretty Print" format using the STAFObject
class's asFormattedString() method (which formats a result using the
verbose mode and does not support the table format). Note that when using
the verbose mode, there are no limits to the width of the output or the
number of lines per record (like there is when using the table format).
For example:
STAFString directory = "C:/temp/staf";
STAFResultPtr res = handlePtr->submit(
machine, "FS", "LIST DIRECTORY " +
STAFHandle::wrapData(directory) + " LONG DETAILS");
if (res->rc == kSTAFOk)
{
cout << res->resultContext->asFormattedString() << endl;
}
else
{
cout << "FS LIST DIRECTORY failed with RC=" << res->rc
<< ", Result=" << res->result << endl;
}
--------------------------------------------------------------
Sharon Lucas
IBM Austin, luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313
"jander...@talentex.co.uk" <jander...@talentex.co.uk>
05/12/2009 02:18 AM
To
staf <staf-users@lists.sourceforge.net>
cc
Subject
[staf-users] Two questions: STAFMapClassDefinition and line length
I have a couple of questions - the first is about returning formatted
lists:
At the moment I return a list of objects to the user by calling
STAFMapClassDefinition::create() and addKey(), which is very convenient.
Is it possible to do it on the fly? I want to be able to receive a
format string from the user and construct a new map - which I then
destroy at the end or when I need to contruct a new one.
The other question is - where can I change the line length at which STAF
changes from the line-mode display of lists to the "record-mode"
display, where each item in the map is represented as a C-like structure?
/jan
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK
i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users