| 100 | |
| 101 | |
| 102 | Dimension::Id PointLayout::assignDim(const std::string& name, |
| 103 | Dimension::Type type) |
| 104 | { |
| 105 | if (!Dimension::nameValid(name)) |
| 106 | throw pdal_error("Can't create dimension with invalid name '" + name + "'."); |
| 107 | if (m_nextFree == Dimension::COUNT) |
| 108 | throw pdal_error("No dimension IDs remaining for assignment."); |
| 109 | Dimension::Id id = (Dimension::Id)m_nextFree; |
| 110 | |
| 111 | auto di = m_propIds.find(name); |
| 112 | if (di != m_propIds.end()) |
| 113 | id = di->second; |
| 114 | Dimension::Detail dd = m_detail[Utils::toNative(id)]; |
| 115 | dd.setType(resolveType(type, dd.type())); |
| 116 | if (update(dd, name)) |
| 117 | { |
| 118 | if (di == m_propIds.end()) |
| 119 | { |
| 120 | m_nextFree++; |
| 121 | m_propIds[name] = id; |
| 122 | } |
| 123 | return id; |
| 124 | } |
| 125 | return Dimension::Id::Unknown; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | Dimension::Id PointLayout::registerOrAssignDim(const std::string name, |