All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Utils.cpp
Go to the documentation of this file.
1 // Terralib Data Source Info tool
2 #include <Utils.h>
3 
4 bool Utils::getDataSource(std::string dsType, std::string connStr, te::da::DataSource* & dataSource, std::string & errorMessage)
5 {
6  if(dsType == "OGR")
7  {
8  dataSource = te::da::DataSourceFactory::make("OGR");
9  }
10  else if(dsType == "POSTGIS")
11  {
12  dataSource = te::da::DataSourceFactory::make("POSTGIS");
13  }
14  else if(dsType == "GDAL")
15  {
16  dataSource = te::da::DataSourceFactory::make("GDAL");
17  }
18  else
19  return 0;
20 
21  dataSource->open(connStr);
22 
23  return true;
24 
25 }
26 
27 std::string Utils::getIdxTypeName(int id)
28 {
29  if(id == 0)
30  return "Btree";
31  else if(id == 1)
32  return "RTree";
33  else if(id == 2)
34  return "QuadTree";
35  else if(id == 3)
36  return "Hash";
37  else
38  return "unknown index";
39 }
40 
41 std::vector<std::string> Utils::getPKPropertiesNames(te::da::PrimaryKey* pk)
42 {
43  std::vector<std::string> propertiesNames;
44 
45  std::vector<te::dt::Property*> properties = pk->getProperties();
46 
47  for(unsigned int i = 0; i < properties.size(); i++)
48  {
49  propertiesNames.push_back(properties[i]->getName());
50  }
51 
52  return propertiesNames;
53 }
54 
55 std::vector<std::string> Utils::getFKPropertiesNames(te::da::ForeignKey* fk)
56 {
57  std::vector<std::string> propertiesNames;
58 
59  std::vector<te::dt::Property*> properties = fk->getProperties();
60 
61  for(unsigned int i = 0; i < properties.size(); i++)
62  {
63  propertiesNames.push_back(properties[i]->getName());
64  }
65 
66  return propertiesNames;
67 }
68 
69 std::vector<std::string> Utils::getUKPropertiesNames(te::da::UniqueKey* uk)
70 {
71  std::vector<std::string> propertiesNames;
72 
73  std::vector<te::dt::Property*> properties = uk->getProperties();
74 
75  for(unsigned int i = 0; i < properties.size(); i++)
76  {
77  propertiesNames.push_back(properties[i]->getName());
78  }
79 
80  return propertiesNames;
81 }
82 
83 std::vector<std::string> Utils::getIdxPropertiesNames(te::da::Index* idx)
84 {
85  std::vector<std::string> propertiesNames;
86 
87  std::vector<te::dt::Property*> properties = idx->getProperties();
88 
89  for(unsigned int i = 0; i < properties.size(); i++)
90  {
91  propertiesNames.push_back(properties[i]->getName());
92  }
93 
94  return propertiesNames;
95 }
96 
97 te::da::DataSet* Utils::getDataSet(te::da::DataSource* dataSource, std::string dataSetName)
98 {
99  std::map<std::string, te::da::DataSet*> dataSets;
100 
101  te::da::DataSourceTransactor* transactor = dataSource->getTransactor();
102 
103  te::da::DataSet* dataset = transactor->getDataSet(dataSetName);
104 
105  delete transactor;
106 
107  return dataset;
108 }
109 
110 bool Utils::loadModules(std::string & errorMessage)
111 {
112 
113  {
115 
116  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
117  info.m_type = "dll";
118  #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
119  info.m_type = "s.o.";
120  #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
121  info.m_type = "dylib";
122  #else
123  #error "Platform not supported yet"
124  #endif
125 
126  info.m_name = "OGR DataSource Driver";
127  info.m_description = "This data source driver supports...";
128 
129  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
130  #ifdef NDEBUG
131  info.m_mainFile = "terralib_ogr.dll";
132  #else
133  info.m_mainFile = "terralib_ogr_d.dll";
134  #endif
135  #endif
136 
137  #if TE_PLATFORM == TE_PLATFORMCODE_LINUX
138  #ifdef NDEBUG
139  info.m_mainFile = "libterralib_ogr.so";
140  #else
141  info.m_mainFile = "libterralib_ogr_d.so";
142  #endif
143  #endif
144 
145  #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
146  #ifdef NDEBUG
147  info.m_mainFile = "terralib_ogr.dylib"; // should it be different????
148  #else
149  info.m_mainFile = "terralib_ogr.dylib";
150  #endif
151  #endif
152 
153  te::plugin::PluginManager::getInstance().loadPlugin(info);
154  }
155 
156  {
158 
159  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
160  info.m_type = "dll";
161  #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
162  info.m_type = "s.o.";
163  #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
164  info.m_type = "dylib";
165  #else
166  #error "Platform not supported yet"
167  #endif
168 
169  info.m_name = "GDAL DataSource Driver";
170  info.m_description = "This data source driver supports...";
171 
172  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
173  #ifdef NDEBUG
174  info.m_mainFile = "terralib_gdal.dll";
175  #else
176  info.m_mainFile = "terralib_gdal_d.dll";
177  #endif
178  #endif
179 
180  #if TE_PLATFORM == TE_PLATFORMCODE_LINUX
181  #ifdef NDEBUG
182  info.m_mainFile = "libterralib_gdal.so";
183  #else
184  info.m_mainFile = "libterralib_gdal_d.so";
185  #endif
186  #endif
187 
188  #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
189  #ifdef NDEBUG
190  info.m_mainFile = "terralib_gdal.dylib";
191  #else
192  info.m_mainFile = "terralib_gdal.dylib";
193  #endif
194  #endif
195 
196  te::plugin::PluginManager::getInstance().loadPlugin(info);
197  }
198 
199  {
201 
202  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
203  info.m_type = "dll";
204  #elif TE_PLATFORM == TE_PLATFORMCODE_LINUX
205  info.m_type = "s.o.";
206  #elif TE_PLATFORM == TE_PLATFORMCODE_APPLE
207  info.m_type = "dylib";
208  #else
209  #error "Platform not supported yet"
210  #endif
211 
212  info.m_name = "PostGIS DataSource Driver";
213  info.m_description = "This data source driver supports...";
214 
215  #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
216  #ifdef NDEBUG
217  info.m_mainFile = "terralib_postgis.dll";
218  #else
219  info.m_mainFile = "terralib_postgis_d.dll";
220  #endif
221  #endif
222 
223  #if TE_PLATFORM == TE_PLATFORMCODE_LINUX
224  #ifdef NDEBUG
225  info.m_mainFile = "libterralib_postgis.so";
226  #else
227  info.m_mainFile = "libterralib_postgis_d.so";
228  #endif
229  #endif
230 
231  #if TE_PLATFORM == TE_PLATFORMCODE_APPLE
232  #ifdef NDEBUG
233  info.m_mainFile = "terralib_postgis.dylib";
234  #else
235  info.m_mainFile = "terralib_postgis.dylib";
236  #endif
237  #endif
238 
239  te::plugin::PluginManager::getInstance().loadPlugin(info);
240 
241  }
242 
243  return true;
244 }
std::string m_name
The plugin name: an internal value used to identify the plugin in the system. Must be a unique value...
Definition: PluginInfo.h:66
virtual void open()=0
It opens the data source and makes it ready for using.
static std::vector< std::string > getFKPropertiesNames(te::da::ForeignKey *fk)
Getting Foreign Key Properties Names.
Definition: Utils.cpp:55
virtual std::auto_ptr< DataSourceTransactor > getTransactor()=0
It returns an object that can execute transactions in the context of a data source.
static bool loadModules(std::string &errorMessage)
Load Terralib modules.
Definition: Utils.cpp:110
static std::vector< std::string > getIdxPropertiesNames(te::da::Index *idx)
Getting Index Properties Names.
Definition: Utils.cpp:83
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:118
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
static PluginManager & getInstance()
It returns a reference to the singleton instance.
static std::auto_ptr< DataSource > make(const std::string &dsType)
static bool getDataSource(std::string dsType, std::string connStr, te::da::DataSource *&dataSource, std::string &errorMessage)
Method to connect with a Data Source.
Definition: Utils.cpp:4
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
static std::vector< std::string > getPKPropertiesNames(te::da::PrimaryKey *pk)
Getting Primary Key Properties Names.
Definition: Utils.cpp:41
A DataSourceTransactor can be viewed as a connection to the data source for reading/writing things in...
static std::vector< std::string > getUKPropertiesNames(te::da::UniqueKey *uk)
Getting Unique Key Properties Names.
Definition: Utils.cpp:69
static te::da::DataSet * getDataSet(te::da::DataSource *dataSource, std::string dataSetName)
Definition: Utils.cpp:97
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:112
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
Definition: UniqueKey.h:110
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the index.
Definition: Index.h:183
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
std::string m_description
A brief explanation about the plugin.
Definition: PluginInfo.h:68
virtual std::auto_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)=0
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
static std::string getIdxTypeName(int id)
Definition: Utils.cpp:27
The basic information about a plugin.
Definition: PluginInfo.h:61
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the foreign key constraint.
Definition: ForeignKey.h:103
It describes an index associated to a DataSetType.
Definition: Index.h:54