All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Event.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file Event.cpp
22 
23  \brief This file contains a class to represent an event.
24 */
25 
26 // TerraLib
27 #include "../../../datatype/DateTime.h"
28 #include "../../../datatype/DateTimePeriod.h"
29 #include "../../../datatype/DateTimeInstant.h"
30 #include "../../../datatype/SimpleData.h"
31 #include "../../../datatype/AbstractData.h"
32 #include "../../../geometry/Geometry.h"
33 #include "../../../common/STLUtils.h"
34 
35 //ST
36 #include "Event.h"
37 #include "Object.h"
38 
39 
41  : m_id(id),
42  m_time(t),
43  m_location(g)
44 {
45 }
46 
47 te::st::Event::Event( const std::string& id, te::dt::DateTime* t, te::gm::Geometry* g,
48  std::vector<te::st::Object*> objs)
49  : m_id(id),
50  m_time(t),
51  m_location(g),
52  m_objects(objs)
53 {
54 }
55 
57  : m_id(ev.m_id)
58 {
59  if(ev.m_time.get()==0)
60  m_time.reset(static_cast<te::dt::DateTime*>(ev.m_time->clone()));
61  if(ev.m_location.get()==0)
62  m_location.reset(static_cast<te::gm::Geometry*>(ev.m_location->clone()));
63  for(unsigned int i=0; i<ev.m_objects.size(); ++i)
64  m_objects.push_back(ev.m_objects[i]->clone());
65 }
66 
68 {
69  if(this != &other)
70  {
71  m_id = other.m_id;
72  if(other.m_time.get()==0)
73  m_time.reset(static_cast<te::dt::DateTime*>(other.m_time->clone()));
74  if(other.m_location.get()==0)
75  m_location.reset(static_cast<te::gm::Geometry*>(other.m_location->clone()));
76  te::common::FreeContents(m_objects);
77  for(unsigned int i=0; i<other.m_objects.size(); ++i)
78  m_objects.push_back(other.m_objects[i]->clone());
79  }
80  return *this;
81 }
82 
84 {
85  return new Event(*this);
86 }
87 
88 std::string te::st::Event::getId() const
89 {
90  return m_id;
91 }
92 
93 void te::st::Event::setId(const std::string& id)
94 {
95  m_id = id;
96 }
97 
99 {
100  return m_time.get();
101 }
102 
104 {
105  m_time.reset(t);
106 }
107 
109 {
110  return m_location.get();
111 }
112 
114 {
115  m_location.reset(g);
116 }
117 
118 void te::st::Event::getObjects(std::vector<te::st::Object*>& output) const
119 {
120  output = m_objects;
121 }
122 
123 void te::st::Event::setObjects(std::vector<te::st::Object*>& objs)
124 {
125  m_objects.clear();
126  m_objects = objs;
127 }
128 
130 {
131  m_objects.clear();
132 }
133 
134 
std::auto_ptr< te::gm::Geometry > m_location
The location where the event happened.
Definition: Event.h:186
Event & operator=(const Event &other)
Copy assignment operator.
Definition: Event.cpp:67
void setObjects(std::vector< te::st::Object * > &objs)
It sets the objects involved to the event.
Definition: Event.cpp:123
void setTime(te::dt::DateTime *t)
It sets the time when the event happened.
Definition: Event.cpp:103
std::auto_ptr< te::dt::DateTime > m_time
The time when the event happened.
Definition: Event.h:185
std::string m_id
The identification of the event.
Definition: Event.h:184
Event(const std::string &id, te::dt::DateTime *t, te::gm::Geometry *g)
Constructor.
Definition: Event.cpp:40
void setId(const std::string &id)
It sets the object identification.
Definition: Event.cpp:93
Event * clone() const
It returns a clone of this event.
Definition: Event.cpp:83
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:73
void getObjects(std::vector< te::st::Object * > &output) const
It returns the objects involved to the event.
Definition: Event.cpp:118
This file contains a class to represent an object.
te::gm::Geometry * getLocation() const
It returns the location where the event happened.
Definition: Event.cpp:108
void setLocation(te::gm::Geometry *g)
It sets the location where the event happened.
Definition: Event.cpp:113
te::dt::DateTime * getTime() const
It returns the time when the event happened.
Definition: Event.cpp:98
std::vector< te::st::Object * > m_objects
The objects involved to the event.
Definition: Event.h:187
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
Definition: BoostUtils.h:55
A class to represent an event.
Definition: Event.h:59
virtual ~Event()
Virtual destructor.
Definition: Event.cpp:129
std::string getId() const
It returns the object identification.
Definition: Event.cpp:88