~ubuntu-branches/ubuntu/raring/glibmm2.4/raring

« back to all changes in this revision

Viewing changes to tests/glibmm_variant/main.cc

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2013-03-06 13:03:41 UTC
  • mfrom: (1.2.79)
  • Revision ID: package-import@ubuntu.com-20130306130341-02m9gb1ahbdcgbn5
Tags: 2.35.8-0ubuntu1
New upstream release based on GLib 2.35.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
  vec_strings.push_back("a");
56
56
  Glib::Variant<std::vector<std::string> > variant_vec_strings =
57
57
    Glib::Variant<std::vector<std::string> >::create(vec_strings);
58
 
  
 
58
 
59
59
  //Dict:
60
60
 
61
61
  typedef std::pair<Glib::ustring, Glib::ustring> TypeDictEntry;
120
120
      " in the variant are: " << value << '.' << std::endl;
121
121
  }
122
122
 
 
123
  //std::vector< std::map< Glib::ustring, Glib::Variant<int> > >
 
124
  typedef std::map< Glib::ustring, Glib::Variant<int> > ComplexDictType;
 
125
 
 
126
  ComplexDictType complex_dict1;
 
127
  ComplexDictType complex_dict2;
 
128
 
 
129
  for(int i = 0; i < 10; i++)
 
130
  {
 
131
    // Convert integer i to string.
 
132
    std::stringstream ss;
 
133
    ss << i;
 
134
 
 
135
    Glib::ustring s = "String " + ss.str();
 
136
 
 
137
    Glib::Variant<int> v = Glib::Variant<int>::create(i);
 
138
 
 
139
    complex_dict1.insert(
 
140
      std::pair< Glib::ustring, Glib::Variant<int> >("Map 1 " + s, v));
 
141
 
 
142
    complex_dict2.insert(
 
143
      std::pair< Glib::ustring, Glib::Variant<int> >("Map 2 " + s, v));
 
144
  }
 
145
 
 
146
  typedef std::vector< std::map< Glib::ustring, Glib::Variant<int> > >
 
147
    ComplexVecType;
 
148
 
 
149
  ComplexVecType complex_vector;
 
150
  complex_vector.push_back(complex_dict1);
 
151
  complex_vector.push_back(complex_dict2);
 
152
 
 
153
  Glib::Variant<ComplexVecType> complex_variant =
 
154
    Glib::Variant<ComplexVecType>::create(complex_vector);
 
155
 
 
156
  // This will output the type string aa{sv}.
 
157
  ostr << "The type string of the variant containing a vector of "
 
158
    "dictionaries is: " << std::endl << complex_variant.get_type_string() <<
 
159
    "." << std::endl << std::endl;
 
160
 
 
161
  ComplexVecType copy_complex_vector = complex_variant.get();
 
162
 
 
163
  for(guint i = 0; i < copy_complex_vector.size(); i++)
 
164
  {
 
165
    ostr << "Printing dictionary # " << i + 1 << ":" << std::endl;
 
166
 
 
167
    ComplexDictType map = copy_complex_vector[i];
 
168
 
 
169
    for(ComplexDictType::const_iterator iter = map.begin();
 
170
      iter != map.end(); iter++)
 
171
    {
 
172
      std::pair< Glib::ustring, Glib::Variant<int> > entry = *iter;
 
173
      ostr << entry.first << " -> " << entry.second.get() << "." << std::endl;
 
174
    }
 
175
    ostr << std::endl;
 
176
  }
 
177
  
123
178
  test_variant_floating();
124
179
  test_dynamic_cast();
125
180