PrintDataSet.cpp
Go to the documentation of this file.
1 // Examples
2 #include "DataAccessExamples.h"
3 
4 // STL
5 #include <iostream>
6 
7 void PrintDataSet(std::string datasetName, te::da::DataSet* dataset)
8 {
9  if(dataset == 0)
10  {
11  std::cout << "The informed dataset is NULL!" << std::endl;
12  return;
13  }
14 
15 // this will be used just to count the items in the dataset
16  int item = 0;
17 
18 // traverse the dataset and print each dataset item
19  dataset->moveBeforeFirst();
20  std::cout << "DATASET: " << datasetName;
21  while(dataset->moveNext())
22  {
23  std::cout << std::endl << "ITEM NUMBER: " << item++ << " =======================" << std::endl;
24 
25  for(std::size_t i = 0; i < dataset->getNumProperties(); ++i)
26  {
27  std::cout << dataset->getPropertyName(i) << ": " ;
28  if(dataset->isNull(i))
29  {
30  std::cout << std::endl;
31  continue;
32  }
33  std::cout << dataset->getAsString(i) << std::endl;
34  }
35  }
36  dataset->moveBeforeFirst();
37 }
38 
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
Examples on how to access/manipulate DataSources in TerraLib.
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
void PrintDataSet(std::string datasetName, te::da::DataSet *dataset)
It prints the data in a given dataset.
Definition: PrintDataSet.cpp:7