[Home]BoostCon 2007/Container Printing Lib - Built-In Format Examples

BOOST WIKI | BoostCon 2007 | RecentChanges | Preferences | Page List | Links List

See the Sandbox

This page has been replaced with BoostTest? files in the boost sandbox. This page is no longer being updated.

- Jared

Test Examples for the default built in formatter

This page is an attempt to show default usage with a selection of built-in and standard library types to get an idea of what our default output should be. Once these have been hashed out, they should be put into test cases, and this page can go away.

Simple Types

int

  int i = 123;
  print(i);
  output: 123

float

  float f = 1.234f;
  print(f);
  output: 1.234

string

  string s = "some string";
  print(s);
  output: some string

bool

  bool b  = true;
  print(b);
  output: true

  b  = false;
  print(b);
  output: false

Container Types

pair

  pair<int,int> pi = make_pair(1,2);
  print(pi);
  output: [1, 2]

vector

  vector<int> vi;
  print(vi);
  output: []

  vi.push_back(1);
  print(vi);
  output: [1]

  vi.push_back(2);
  vi.push_back(3);
  print(vi);
  output: [1, 2, 3]

vector in vector

  vector<vector<int> > vvi;
  print(vvi);
  output: []

  vvi.push_back(vi);
  print(vvi);
  output: [[1, 2, 3]]

  vvi.push_back(vi);
  vvi.push_back(vi);
  print(vvi);
  output: [[1, 2, 3], [1, 2, 3], [1, 2, 3]]

vector with nasty string case

  vector<string> vs;
  vs.push_back("[1, 2, 3], [1, 2, 3], [1, 2, 3]");
  print(vs);
  output: [[1, 2, 3], [1, 2, 3], [1, 2, 3]]

vector of pairs

This is an interesting case as it shows a stylistic difference between a vector of pairs and a map. It also shows that if we allow this syntax, simple type and depth formatters will need to be enhanced to meet this requirement.

  vector<pair<int,int> > vpi;
  print(vpi);
  output: []

  pair<int,int> pi = make_pair(1,2);

  vpi.push_back(pi);
  print(vpi);
  output: [[1, 2]]

  vvi.push_back(pi);
  vvi.push_back(pi);
  print(vpi);
  output: [[1, 2], [1, 2], [1, 2]]

map

  map<int,string> mis;
  print(mis);
  output: []

  mis.insert(make_pair(1, "first"));
  print(mis);
  output: [1:first]

  mis.insert(make_pair(2, "second"));
  mis.insert(make_pair(3, "third"));
  print(mis);
  output: [1:first, 2:second, 3:third]

vector in map

  map<int,vector<int> > mivi;
  print(mivi);
  output: []

  mivi.insert(make_pair(1, vi));
  print(mivi);
  output: [1:[1,2,3]]

  mivi.insert(make_pair(2, vi));
  mivi.insert(make_pair(3, vi));
  print(mivi);
  output: [1:[1,2,3], 2:[1,2,3], 3:[1,2,3]]

Special Formats

  vector<string> vs;
  vs.push_back("first");
  vs.push_back("sec,ond");
  vs.push_back("th\"ird");

HTML List

  print(vs, HTMLListFormatter());
  output:
    <ul>
       <li>first
       <li>sec,ond
       <li>th&quot;ird
    </ul>

CSV

  Note: Does not deal with line breaks in strings.
  print(vs, CSVFormatter());
  output: first,"sec,ond","th""ird"

BOOST WIKI | BoostCon 2007 | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited May 18, 2007 11:08 pm (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers