Helios++
Helios software for LiDAR simulations
ScanningStrip.h
1 #pragma once
2 
3 #include <Leg.h>
4 #include <HeliosException.h>
5 
6 #include <string>
7 #include <sstream>
8 #include <unordered_map>
9 
25 public:
26  // *** CONSTANTS *** //
27  // ******************* //
28  static std::string const NULL_STRIP_ID;
29 protected:
30  // *** ATTRIBUTES *** //
31  // ******************** //
35  std::string stripId;
40  std::unordered_map<int, Leg*> legs;
41 
42 public:
43  // *** CONSTRUCTION / DESTRUCTION *** //
44  // ************************************ //
48  ScanningStrip(std::string const stripId=NULL_STRIP_ID) :
50  {}
51  virtual ~ScanningStrip() {}
52 
53  // *** METHODS *** //
54  // ***************** //
61  inline bool has(int const serialId){
62  return legs.find(serialId) != legs.end();
63  }
64 
70  inline bool has(Leg &leg){return has(leg.getSerialId());}
76  inline void emplace(int const serialId, Leg *leg){
77  legs.emplace(serialId, leg);
78  }
82  inline void emplace(Leg *leg){emplace(leg->getSerialId(), leg);}
88  inline void safeEmplace(int const serialId, Leg *leg){
89  if(has(serialId)){
90  std::stringstream ss;
91  ss << "ScanningStrip::safeEmplace will not emplace leg "
92  << serialId << " because a leg with same identifier "
93  << "already belongs to the strip";
94  throw HeliosException(ss.str());
95  }
96  emplace(serialId, leg);
97  }
101  inline void safeEmplace(Leg *leg){safeEmplace(leg->getSerialId(), leg);}
102 
103 
104  // *** GETTERS and SETTERS *** //
105  // ***************************** //
110  inline std::string getStripId() const {return stripId;}
115  inline void setStripId(std::string const stripId)
116  {this->stripId = stripId;}
123  inline Leg * getLeg(int const serialId) {
124  return has(serialId) ? legs[serialId] : nullptr;
125  }
132  inline bool isLastLegInStrip() const
133  {
134  for (const auto & it : legs)
135  if (!it.second->wasProcessed)
136  return false;
137  return true;
138  }
139 
140 };
Base class for Helios exceptions.
Definition: HeliosException.h:12
Class representing a survey leg.
Definition: Leg.h:17
int getSerialId() const
Obtain the serial identifier of the leg.
Definition: Leg.h:124
A scanning strip is a set of legs which belong to the same strip. Thus, it is an abstract group of le...
Definition: ScanningStrip.h:24
bool has(Leg &leg)
Check whether given leg belongs to the strip or not.
Definition: ScanningStrip.h:70
void emplace(int const serialId, Leg *leg)
Insert/emplace given leg into the scanning strip.
Definition: ScanningStrip.h:76
void setStripId(std::string const stripId)
Set the new strip identifier.
Definition: ScanningStrip.h:115
void safeEmplace(Leg *leg)
Definition: ScanningStrip.h:101
void safeEmplace(int const serialId, Leg *leg)
Like ScanningStrip::emplace(int const, Leg *) but with security checks.
Definition: ScanningStrip.h:88
std::string stripId
String identifying the scanning strip.
Definition: ScanningStrip.h:35
bool isLastLegInStrip() const
Checks if all the legs in the strip were processed in order to know if the associated SyncFileWriter ...
Definition: ScanningStrip.h:132
std::unordered_map< int, Leg * > legs
Map with leg serial id as key and pointer to leg as value.
Definition: ScanningStrip.h:40
ScanningStrip(std::string const stripId=NULL_STRIP_ID)
Default constructor for scanning strip.
Definition: ScanningStrip.h:48
bool has(int const serialId)
Check whether given serial id belongs to the strip or not.
Definition: ScanningStrip.h:61
Leg * getLeg(int const serialId)
Obtain leg with given serial identifier.
Definition: ScanningStrip.h:123
std::string getStripId() const
Obtain the strip identifier.
Definition: ScanningStrip.h:110
void emplace(Leg *leg)
Definition: ScanningStrip.h:82