dataaccess/PrintDataSets.cpp
Go to the documentation of this file.
1 // Examples
2 #include "DataAccessExamples.h"
3 
4 // STL
5 #include <iostream>
6 
8 {
9  if(ds == 0 || !ds->isOpened())
10  {
11  std::cout << "The informed data source is NULL or is closed!" << std::endl;
12  return;
13  }
14 
15 // get a transactor to interact to the data source
16  te::da::DataSourceTransactor* transactor = (ds->getTransactor()).release();
17  //assert(transactor.get());
18 
19 // now retrieve the name of the datasets
20  std::vector<std::string> datasets = ds->getDataSetNames();
21 
22 // and then iterate over dataset names to retrieve its information
23  std::cout << "There is(are) "<< datasets.size() << " dataset(s) in the datasource:" << std::endl;
24 
25  for(unsigned int i=0; i<datasets.size(); ++i)
26  {
27  try {
28 // retrieve the dataset by its name
29  te::da::DataSet* dataset = (ds->getDataSet(datasets[i])).release();
30 
31 // print its date to standard output
32  std::cout << i << ": ";
33  PrintDataSet(datasets[i], dataset);
34 
35 // release the dataset: you are the owner
36  delete dataset;
37  }
38  catch(te::common::Exception& ex)
39  {
40  std::cout << "\n\tCan not print dataset " << datasets[i] << ": " << ex.what() << std::endl;
41  }
42  catch(...)
43  {
44  std::cout << "\n\tCan not print dataset " << datasets[i] << std::endl;
45  }
46  }
47 // release the transactor: you are the owner
48  delete transactor;
49 }
50 
virtual std::unique_ptr< DataSourceTransactor > getTransactor()=0
It returns the set of parameters used to set up the access channel to the underlying repository...
void PrintDataSets(te::da::DataSource *ds)
It prints datasets in a given data source.
virtual const char * what() const
It outputs the exception message.
virtual bool isOpened() const =0
It returns true if the data source is opened, otherwise it returns false.
static te::dt::Date ds(2010, 01, 01)
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Examples on how to access/manipulate DataSources in TerraLib.
virtual std::vector< std::string > getDataSetNames()
It gets the dataset names available in the data source.
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual std::unique_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
void PrintDataSet(std::string datasetName, te::da::DataSet *dataset)
It prints the data in a given dataset.
Definition: PrintDataSet.cpp:7