1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
20 #include "Trajectory.h"
25 // ServiceInfo Class member Function define.
26 ServiceInfo::ServiceInfo( void ) : timestamp(""), things_ea(0) { validThings.clear(); }
28 ServiceInfo::~ServiceInfo()
37 MAP_TYPE::iterator ServiceInfo::ThingBegin( void )
39 return validThings.begin();
42 MAP_TYPE::iterator ServiceInfo::ThingEnd( void )
44 return validThings.end();
47 void ServiceInfo::insert( ThingInfo &thing )
49 if ( find(thing.ID) == NULL )
51 validThings[thing.ID] = thing;
56 ThingInfo *ServiceInfo::find( std::string thingID )
58 MAP_TYPE::iterator itr = validThings.find( thingID );
60 if ( itr == validThings.end() )
66 int ServiceInfo::getThingsEA( void )
72 // CurrentService Class member Function define.
73 CurrentService::CurrentService( void )
78 CurrentService::CurrentService( std::string trackeeID, std::string time)
80 trackee.ID = trackeeID;
81 service.timestamp = time;
84 CurrentService::~CurrentService()
90 // Trajectory Class member Function define.
91 Trajectory::Trajectory( void )
95 latestServiceNum = ServiceList.size();
99 Trajectory::Trajectory( std::string trackeeID )
101 trackee.ID = trackeeID;
103 latestServiceNum = ServiceList.size();
107 Trajectory::~Trajectory( void )
110 latestServiceNum = ServiceList.size();
118 std::string Trajectory::getTrackeeID( void )
123 int Trajectory::getTrajectoryDeepSize( void )
125 return latestServiceNum;
128 int Trajectory::TrajectoryUpdate( CurrentService &CurrentSvc )
130 if ( latestServiceNum <= 0 )
133 if ( trackee.ID.compare( CurrentSvc.trackee.ID ) == 0 )
135 // if trackee.ID of CurrentSvc == trackee.ID ,
136 ServiceInfo *recentSvc = &ServiceList[latestServiceNum - 1];
137 ServiceInfo *crtSvc = &CurrentSvc.service;
139 if ( recentSvc->getThingsEA() != crtSvc->getThingsEA() )
140 goto INSERT_ELEMENT ;
142 MAP_TYPE::iterator itr = crtSvc->ThingBegin();
143 for ( ; itr != crtSvc->ThingEnd() ; itr++ )
145 if ( recentSvc->find( itr->second.ID ) == NULL )
149 return latestServiceNum;
153 ServiceList.push_back( CurrentSvc.service );
154 latestServiceNum = ServiceList.size();
156 return latestServiceNum;
159 std::vector<ServiceInfo> *Trajectory::getTrajectoryList( int latestNum, int ListSize )
161 if ( latestServiceNum <= 0 || latestServiceNum <= latestNum )
169 resultList = new std::vector<ServiceInfo>;
172 if ( latestServiceNum >= (latestNum + ListSize) && ListSize > 0 )
174 endIndex = latestServiceNum - latestNum - ListSize;
177 for ( int i = (latestServiceNum - 1 - latestNum) ; i >= endIndex ; i-- )
178 resultList->push_back( ServiceList[i] );