Demonstrates one way to access bottle objects.
#include <cstdio>
void showBottle(Bottle& anUnknownBottle, int indentation = 0)
{
for (size_t i = 0; i < anUnknownBottle.size(); i++) {
for (int j = 0; j < indentation; j++) {
printf(" ");
}
printf("[%zu]: ", i);
Value& element = anUnknownBottle.get(i);
switch (element.getCode()) {
printf("int %d\n", element.asInt32());
break;
printf("float %g\n", element.asFloat64());
break;
printf("string \"%s\"\n", element.asString().c_str());
break;
printf("binary blob of length %zd\n", element.asBlobLength());
break;
break;
default:
if (element.isList()) {
Bottle* lst = element.asList();
printf("list of %zu elements\n", lst->size());
showBottle(*lst, indentation + 2);
} else {
printf("unrecognized type\n");
}
break;
}
}
}
int main(int argc, char* argv[])
{
Bottle anUnknownBottle("equals 7 (add (add 2 3) 2)");
showBottle(anUnknownBottle);
return 0;
}
#define BOTTLE_TAG_FLOAT64
#define BOTTLE_TAG_STRING
#define BOTTLE_TAG_VOCAB32
A simple collection of objects that can be described and transmitted in a portable way.
A single value (typically within a Bottle).
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.