Skip to content

Commit 32ab4d3

Browse files
committed
プルリク指摘に対応
プルリク指摘対応中 プルリク指摘に対応中 isWithin削除 プルリク指摘修正
1 parent dc3eab4 commit 32ab4d3

File tree

20 files changed

+83
-114
lines changed

20 files changed

+83
-114
lines changed

include/plateau/dataset/grid_code.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ namespace plateau::dataset {
2828
*/
2929
virtual geometry::Extent getExtent() const = 0;
3030

31-
/**
32-
* \brief このコードが他のコードに内包されるかどうかを計算します。
33-
*/
34-
virtual bool isWithin(const GridCode& other) const = 0;
35-
3631
/**
3732
* \brief コードが適切な値かどうかを返します。
3833
*/
@@ -42,6 +37,10 @@ namespace plateau::dataset {
4237
* \brief 1段階上のレベルのグリッドコードに変換します。
4338
*/
4439
virtual std::shared_ptr<GridCode> upper() const = 0;
40+
41+
/**
42+
* \brief upper()のP/Invokeから呼び出す版です。newして返すので、利用者が適切に廃棄する必要があります。
43+
*/
4544
virtual GridCode* upperRaw() const = 0;
4645

4746
/**
@@ -50,13 +49,12 @@ namespace plateau::dataset {
5049
virtual int getLevel() const = 0;
5150

5251
/**
53-
* \brief コードのレベル(詳細度)が、PLATEAUの仕様上考えられる中でもっとも大きいものであるときにtrueを返します。
54-
* @return
52+
* \brief コードのレベル(詳細度)が、PLATEAUの仕様上考えられる中でもっとも広域であるときにtrueを返します。
5553
*/
5654
virtual bool isLargestLevel() const = 0;
5755

5856
/**
59-
* \brief コードのレベル(詳細度)が、PLATEAUの典型的な建物のGMLファイルのレベルよりも小さい場合にtrueを返します
57+
* \brief コードのレベル(詳細度)が、PLATEAUの典型的な建物のGMLファイルのレベルよりも詳細である場合にtrueを返します
6058
*/
6159
virtual bool isSmallerThanNormalGml() const = 0;
6260

@@ -86,7 +84,9 @@ namespace plateau::dataset {
8684

8785
struct GridCodeComparator {
8886
bool operator()(const std::shared_ptr<GridCode>& lhs, const std::shared_ptr<GridCode>& rhs) const {
89-
if(lhs == nullptr || rhs == nullptr) return false;
87+
if(lhs == nullptr && rhs == nullptr) return false;
88+
if(lhs != nullptr && rhs == nullptr) return false;
89+
if(lhs == nullptr) return true;
9090
return lhs->get() < rhs->get();
9191
}
9292
};

include/plateau/dataset/invalid_grid_code.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ namespace plateau::dataset {
3232
};
3333
}
3434

35-
/**
36-
* \brief このコードが他のコードに内包されるかどうかを計算します。
37-
* \return 常にfalseを返します。
38-
*/
39-
bool isWithin(const GridCode& other) const override { return false; }
40-
4135
/**
4236
* \brief コードが適切な値かどうかを返します。
4337
* \return 常にfalseを返します。

include/plateau/dataset/mesh_code.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ class LIBPLATEAU_EXPORT MeshCode : public plateau::dataset::GridCode {
4848
*/
4949
static std::shared_ptr<std::vector<MeshCode>> getThirdMeshes(const geometry::Extent& extent);
5050

51-
/**
52-
* \brief 地域メッシュが内包されるかどうかを計算します。
53-
*/
54-
bool isWithin(const GridCode& other) const override;
55-
5651
/**
5752
* \brief 地域メッシュを2次メッシュとして取得します。
5853
*/

include/plateau/dataset/standard_map_grid.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ namespace plateau::dataset {
2727
*/
2828
geometry::Extent getExtent() const override;
2929

30-
/**
31-
* \brief 図郭が他の図郭に内包されるかどうかを計算します。
32-
*/
33-
bool isWithin(const GridCode& other) const override;
34-
3530
/**
3631
* \brief 図郭コードが適切な値かどうかを返します。
3732
*/
@@ -56,7 +51,6 @@ namespace plateau::dataset {
5651
bool isNormalGmlLevel() const override;
5752

5853
bool operator==(const StandardMapGrid& other) const;
59-
bool operator<(StandardMapGrid& other) const;
6054
bool operator<(const StandardMapGrid& other) const;
6155

6256
private:

src/c_wrapper/grid_code_c.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ extern "C" {
1313
const char* code,
1414
GridCode** out_grid_code
1515
) {
16-
*out_grid_code = GridCode::createRaw(code);
17-
return APIResult::Success;
16+
API_TRY {
17+
if(code == nullptr) return APIResult::ErrorInvalidArgument;
18+
if(out_grid_code == nullptr) return APIResult::ErrorInvalidArgument;
19+
*out_grid_code = GridCode::createRaw(code);
20+
return APIResult::Success;
21+
}
22+
API_CATCH;
23+
return APIResult::ErrorUnknown;
24+
1825
}
1926

2027
LIBPLATEAU_C_EXPORT APIResult LIBPLATEAU_C_API plateau_grid_code_get_extent(
2128
const GridCode* grid_code, Extent* extent
2229
) {
2330
API_TRY{
2431
if (grid_code == nullptr) return APIResult::ErrorInvalidArgument;
32+
if (extent == nullptr) return APIResult::ErrorInvalidArgument;
2533
*extent = grid_code->getExtent();
2634
return APIResult::Success;
2735
}

src/dataset/grid_code.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ namespace plateau::dataset {
1515
bool has_digit = false;
1616
bool has_upper = false;
1717

18-
// コードの文字を検査
18+
// コードの文字を検査(数字と大文字英字の有無をチェック)
1919
for (char c : code) {
2020
if (std::isdigit(c)) has_digit = true;
2121
if (std::isupper(c)) has_upper = true;
22+
if (!std::isalnum(c)) { // 無効な文字
23+
return new InvalidGridCode();
24+
}
2225
}
2326

2427
try {

src/dataset/grid_code_utils.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,4 @@ namespace plateau::dataset::utils {
2626
}
2727
return grid_codes_str_set;
2828
}
29-
30-
3129
}

src/dataset/grid_code_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ namespace plateau::dataset::utils {
1414
*/
1515
std::set<std::string> createExpandedGridCodeSet(const std::vector<GridCode*>& grid_codes);
1616

17-
}
17+
} // namespace plateau::dataset::utils

src/dataset/local_dataset_accessor.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace plateau::dataset {
1313
namespace fs = std::filesystem;
1414
using namespace geometry;
15-
using namespace utils;
1615

1716
//! 建築物、建築物部分、建築物付属物及びこれらの境界面
1817
const std::string UdxSubFolder::bldg = "bldg";
@@ -157,9 +156,8 @@ namespace plateau::dataset {
157156
for (const auto& gml_file: gml_files) {
158157
auto grid_code = gml_file.getGridCode();
159158
if (!gml_file.isValid()) continue;
160-
if (collection.files_by_code_.count(grid_code->get()) == 0) {
161-
collection.files_by_code_.emplace(grid_code->get(), std::vector<GmlFile>());
162-
}
159+
if (!grid_code->isValid()) continue;
160+
collection.files_by_code_.try_emplace(grid_code->get(), std::vector<GmlFile>());
163161
collection.files_by_code_[grid_code->get()].push_back(gml_file);
164162
}
165163
}
@@ -195,7 +193,7 @@ namespace plateau::dataset {
195193
// これがないとフィルターの結果に対して fetch を実行するときにパスがずれます。
196194
out_collection_ptr->setUdxPath(udx_path_);
197195
// 検索用に、引数の grid_codes を文字列のセットにします。
198-
auto grid_codes_str_set = createExpandedGridCodeSet(grid_codes);
196+
auto grid_codes_str_set = utils::createExpandedGridCodeSet(grid_codes);
199197

200198
// ファイルごとに grid_codes_str_set に含まれるなら追加していきます。
201199
for (const auto& [code, files] : files_by_code_) {
@@ -286,6 +284,7 @@ namespace plateau::dataset {
286284
double lon_sum = 0;
287285
double height_sum = 0;
288286
for (const auto& grid_code : grid_codes_) {
287+
if(grid_code == nullptr && !grid_code->isValid()) continue;
289288
const auto& center = grid_code->getExtent().centerPoint();
290289
lat_sum += center.latitude;
291290
lon_sum += center.longitude;
@@ -307,23 +306,19 @@ namespace plateau::dataset {
307306
for (const auto& file: files) {
308307
auto grid_code = file.getGridCode();
309308
if (!grid_code->isValid()) continue;
310-
grid_codes_.insert(GridCode::create(file.getGridCode()->get()));
309+
grid_codes_.insert(grid_code);
311310
}
312311
}
313312
}
314313
return grid_codes_;
315314
}
316315

317316
void LocalDatasetAccessor::addFile(PredefinedCityModelPackage sub_folder, const GmlFile& gml_file_info) {
318-
if (files_.count(sub_folder) <= 0) {
319-
files_.emplace(sub_folder, std::vector<GmlFile>());
320-
}
317+
files_.try_emplace(sub_folder, std::vector<GmlFile>());
321318
files_.at(sub_folder).push_back(gml_file_info);
322319

323320
const auto grid_code = gml_file_info.getGridCode()->get();
324-
if (files_by_code_.count(grid_code) == 0) {
325-
files_by_code_.emplace(grid_code, std::vector<GmlFile>());
326-
}
321+
files_by_code_.try_emplace(grid_code, std::vector<GmlFile>());
327322
files_by_code_[grid_code].push_back(gml_file_info);
328323
}
329324

src/dataset/mesh_code.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,6 @@ namespace plateau::dataset {
234234
return result;
235235
}
236236

237-
bool MeshCode::isWithin(const GridCode& other) const {
238-
// 型チェック
239-
const auto* other_mesh = dynamic_cast<const MeshCode*>(&other);
240-
if (other_mesh == nullptr) {
241-
return false; // 異なる型の場合は内包関係にないとみなす
242-
}
243-
244-
if (get() == other_mesh->get())
245-
return true;
246-
247-
return get().substr(0, 6) == other_mesh->get();
248-
}
249-
250237
MeshCode MeshCode::asSecond() const {
251238
auto result = *this;
252239
result.level_ = 2;

0 commit comments

Comments
 (0)