Skip to content

Commit 92a8635

Browse files
style: apply clang-format
1 parent a418f2f commit 92a8635

5 files changed

Lines changed: 141 additions & 146 deletions

File tree

external/tinyply.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,14 @@ namespace tinyply {
629629
std::memcpy(listSize, &p.listCount, sizeof(uint32_t));
630630
write_property_binary(os, listSize, dummyCount, f.list_stride);
631631
write_property_binary(os, (helper->data->buffer.get_const() + helper->cursor->byteOffset), helper->cursor->byteOffset, f.prop_stride * p.listCount);
632-
} else {
633-
write_property_binary(os, (helper->data->buffer.get_const() + helper->cursor->byteOffset), helper->cursor->byteOffset, f.prop_stride);
634-
}
635-
if (!os.good())
636-
return;
637-
property_index++;
638-
}
639-
}
632+
} else {
633+
write_property_binary(os, (helper->data->buffer.get_const() + helper->cursor->byteOffset), helper->cursor->byteOffset, f.prop_stride);
634+
}
635+
if (!os.good())
636+
return;
637+
property_index++;
638+
}
639+
}
640640
element_idx++;
641641
}
642642
}
@@ -661,19 +661,19 @@ namespace tinyply {
661661
for (size_t j = 0; j < p.listCount; ++j) {
662662
write_property_ascii(p.propertyType, os, (helper->data->buffer.get() + helper->cursor->byteOffset), helper->cursor->byteOffset);
663663
}
664-
} else {
665-
write_property_ascii(p.propertyType, os, (helper->data->buffer.get() + helper->cursor->byteOffset), helper->cursor->byteOffset);
666-
}
667-
if (!os.good())
668-
return;
669-
property_index++;
670-
}
671-
os << "\n";
672-
if (!os.good())
673-
return;
674-
}
675-
element_idx++;
676-
}
664+
} else {
665+
write_property_ascii(p.propertyType, os, (helper->data->buffer.get() + helper->cursor->byteOffset), helper->cursor->byteOffset);
666+
}
667+
if (!os.good())
668+
return;
669+
property_index++;
670+
}
671+
os << "\n";
672+
if (!os.good())
673+
return;
674+
}
675+
element_idx++;
676+
}
677677
}
678678

679679
void PlyFile::PlyFileImpl::write_header(std::ostream& os) noexcept {

src/io/formats/ply.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "io/ply_export_internal.hpp"
1111
#include "tinyply.hpp"
1212
#include <algorithm>
13-
#include <cassert>
1413
#include <atomic>
14+
#include <cassert>
1515
#include <cctype>
1616
#include <charconv>
1717
#include <chrono>
@@ -412,10 +412,10 @@ namespace lfs::io {
412412
__cpuid(cpuInfo, 7);
413413
has_avx2 = (cpuInfo[1] & (1 << 5)) != 0;
414414
#elif defined(__GNUC__) || defined(__clang__)
415-
__builtin_cpu_init();
416-
has_avx2 = __builtin_cpu_supports("avx2");
415+
__builtin_cpu_init();
416+
has_avx2 = __builtin_cpu_supports("avx2");
417417
#else
418-
has_avx2 = false;
418+
has_avx2 = false;
419419
#endif
420420
});
421421

src/io/include/io/atomic_output.hpp

Lines changed: 98 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -18,127 +18,126 @@
1818

1919
namespace lfs::io {
2020

21-
enum class AtomicOutputTempName {
22-
AppendSuffix,
23-
PreserveExtension
24-
};
25-
26-
inline std::filesystem::path make_atomic_temp_output_path(
27-
const std::filesystem::path& output_path,
28-
AtomicOutputTempName name_style = AtomicOutputTempName::AppendSuffix) {
29-
static std::atomic_uint64_t counter{0};
30-
31-
const auto ticks = std::chrono::steady_clock::now().time_since_epoch().count();
32-
const auto unique_suffix = std::format(".{}.{}.tmp", ticks, counter.fetch_add(1, std::memory_order_relaxed));
33-
34-
if (name_style == AtomicOutputTempName::PreserveExtension && output_path.has_extension()) {
35-
const auto temp_name = output_path.stem().string() + unique_suffix + output_path.extension().string();
36-
return output_path.parent_path() / temp_name;
37-
}
21+
enum class AtomicOutputTempName {
22+
AppendSuffix,
23+
PreserveExtension
24+
};
3825

39-
return output_path.string() + unique_suffix;
40-
}
26+
inline std::filesystem::path make_atomic_temp_output_path(
27+
const std::filesystem::path& output_path,
28+
AtomicOutputTempName name_style = AtomicOutputTempName::AppendSuffix) {
29+
static std::atomic_uint64_t counter{0};
4130

42-
inline Result<void> ensure_output_parent_directory(const std::filesystem::path& output_path) {
43-
if (output_path.parent_path().empty()) {
44-
return {};
45-
}
31+
const auto ticks = std::chrono::steady_clock::now().time_since_epoch().count();
32+
const auto unique_suffix = std::format(".{}.{}.tmp", ticks, counter.fetch_add(1, std::memory_order_relaxed));
4633

47-
std::error_code ec;
48-
std::filesystem::create_directories(output_path.parent_path(), ec);
49-
if (ec) {
50-
return std::unexpected(Error{
51-
ErrorCode::WRITE_FAILURE,
52-
std::format("Failed to create output directory '{}': {}", output_path.parent_path().string(), ec.message())});
34+
if (name_style == AtomicOutputTempName::PreserveExtension && output_path.has_extension()) {
35+
const auto temp_name = output_path.stem().string() + unique_suffix + output_path.extension().string();
36+
return output_path.parent_path() / temp_name;
37+
}
38+
39+
return output_path.string() + unique_suffix;
5340
}
5441

55-
return {};
56-
}
42+
inline Result<void> ensure_output_parent_directory(const std::filesystem::path& output_path) {
43+
if (output_path.parent_path().empty()) {
44+
return {};
45+
}
5746

58-
inline Result<void> replace_atomic_output_file(const std::filesystem::path& temp_path,
59-
const std::filesystem::path& output_path) {
60-
#ifdef _WIN32
61-
const auto temp_w = temp_path.wstring();
62-
const auto output_w = output_path.wstring();
63-
if (!MoveFileExW(temp_w.c_str(), output_w.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {
64-
return std::unexpected(Error{
65-
ErrorCode::WRITE_FAILURE,
66-
std::format("Failed to replace '{}' with temporary export '{}': Windows error {}",
67-
output_path.string(), temp_path.string(), GetLastError())});
47+
std::error_code ec;
48+
std::filesystem::create_directories(output_path.parent_path(), ec);
49+
if (ec) {
50+
return std::unexpected(Error{
51+
ErrorCode::WRITE_FAILURE,
52+
std::format("Failed to create output directory '{}': {}", output_path.parent_path().string(), ec.message())});
53+
}
54+
55+
return {};
6856
}
57+
58+
inline Result<void> replace_atomic_output_file(const std::filesystem::path& temp_path,
59+
const std::filesystem::path& output_path) {
60+
#ifdef _WIN32
61+
const auto temp_w = temp_path.wstring();
62+
const auto output_w = output_path.wstring();
63+
if (!MoveFileExW(temp_w.c_str(), output_w.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {
64+
return std::unexpected(Error{
65+
ErrorCode::WRITE_FAILURE,
66+
std::format("Failed to replace '{}' with temporary export '{}': Windows error {}",
67+
output_path.string(), temp_path.string(), GetLastError())});
68+
}
6969
#else
70-
std::error_code ec;
71-
std::filesystem::rename(temp_path, output_path, ec);
72-
if (ec) {
73-
return std::unexpected(Error{
74-
ErrorCode::WRITE_FAILURE,
75-
std::format("Failed to replace '{}' with temporary export '{}': {}",
76-
output_path.string(), temp_path.string(), ec.message())});
77-
}
70+
std::error_code ec;
71+
std::filesystem::rename(temp_path, output_path, ec);
72+
if (ec) {
73+
return std::unexpected(Error{
74+
ErrorCode::WRITE_FAILURE,
75+
std::format("Failed to replace '{}' with temporary export '{}': {}",
76+
output_path.string(), temp_path.string(), ec.message())});
77+
}
7878
#endif
7979

80-
return {};
81-
}
80+
return {};
81+
}
8282

83-
class ScopedAtomicOutputFile {
84-
public:
85-
explicit ScopedAtomicOutputFile(
86-
std::filesystem::path output_path,
87-
AtomicOutputTempName name_style = AtomicOutputTempName::AppendSuffix)
88-
: output_path_(std::move(output_path))
89-
, temp_path_(make_atomic_temp_output_path(output_path_, name_style)) {}
83+
class ScopedAtomicOutputFile {
84+
public:
85+
explicit ScopedAtomicOutputFile(
86+
std::filesystem::path output_path,
87+
AtomicOutputTempName name_style = AtomicOutputTempName::AppendSuffix)
88+
: output_path_(std::move(output_path)), temp_path_(make_atomic_temp_output_path(output_path_, name_style)) {}
9089

91-
ScopedAtomicOutputFile(const ScopedAtomicOutputFile&) = delete;
92-
ScopedAtomicOutputFile& operator=(const ScopedAtomicOutputFile&) = delete;
90+
ScopedAtomicOutputFile(const ScopedAtomicOutputFile&) = delete;
91+
ScopedAtomicOutputFile& operator=(const ScopedAtomicOutputFile&) = delete;
9392

94-
ScopedAtomicOutputFile(ScopedAtomicOutputFile&&) = delete;
95-
ScopedAtomicOutputFile& operator=(ScopedAtomicOutputFile&&) = delete;
93+
ScopedAtomicOutputFile(ScopedAtomicOutputFile&&) = delete;
94+
ScopedAtomicOutputFile& operator=(ScopedAtomicOutputFile&&) = delete;
9695

97-
~ScopedAtomicOutputFile() {
98-
if (!committed_) {
99-
std::error_code ec;
100-
std::filesystem::remove(temp_path_, ec);
96+
~ScopedAtomicOutputFile() {
97+
if (!committed_) {
98+
std::error_code ec;
99+
std::filesystem::remove(temp_path_, ec);
100+
}
101101
}
102-
}
103102

104-
const std::filesystem::path& output_path() const { return output_path_; }
105-
const std::filesystem::path& temp_path() const { return temp_path_; }
103+
const std::filesystem::path& output_path() const { return output_path_; }
104+
const std::filesystem::path& temp_path() const { return temp_path_; }
106105

107-
Result<void> commit() {
108-
auto result = replace_atomic_output_file(temp_path_, output_path_);
109-
if (!result) {
110-
return result;
106+
Result<void> commit() {
107+
auto result = replace_atomic_output_file(temp_path_, output_path_);
108+
if (!result) {
109+
return result;
110+
}
111+
112+
committed_ = true;
113+
return {};
111114
}
112115

113-
committed_ = true;
114-
return {};
116+
private:
117+
std::filesystem::path output_path_;
118+
std::filesystem::path temp_path_;
119+
bool committed_ = false;
120+
};
121+
122+
inline bool report_export_progress(const ExportProgressCallback& callback, float progress, const std::string& stage) {
123+
if (!callback) {
124+
return true;
125+
}
126+
return callback(progress, stage);
115127
}
116128

117-
private:
118-
std::filesystem::path output_path_;
119-
std::filesystem::path temp_path_;
120-
bool committed_ = false;
121-
};
129+
inline ExportProgressCallback scale_export_progress(
130+
ExportProgressCallback callback,
131+
float start,
132+
float end) {
133+
if (!callback) {
134+
return {};
135+
}
122136

123-
inline bool report_export_progress(const ExportProgressCallback& callback, float progress, const std::string& stage) {
124-
if (!callback) {
125-
return true;
137+
return [callback = std::move(callback), start, end](float progress, const std::string& stage) {
138+
const float scaled = start + (end - start) * progress;
139+
return callback(scaled, stage);
140+
};
126141
}
127-
return callback(progress, stage);
128-
}
129-
130-
inline ExportProgressCallback scale_export_progress(
131-
ExportProgressCallback callback,
132-
float start,
133-
float end) {
134-
if (!callback) {
135-
return {};
136-
}
137-
138-
return [callback = std::move(callback), start, end](float progress, const std::string& stage) {
139-
const float scaled = start + (end - start) * progress;
140-
return callback(scaled, stage);
141-
};
142-
}
143142

144143
} // namespace lfs::io

tests/test_nurec_usdz_format.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,11 @@ namespace {
324324
const fs::path usdz_path = temp_dir / "roundtrip.usdz";
325325
std::vector<float> updates;
326326

327-
ASSERT_TRUE(save_nurec_usdz(original, {
328-
.output_path = usdz_path,
329-
.progress_callback = [&](float progress, const std::string&) {
330-
updates.push_back(progress);
331-
return true;
332-
}})
327+
ASSERT_TRUE(save_nurec_usdz(original, {.output_path = usdz_path,
328+
.progress_callback = [&](float progress, const std::string&) {
329+
updates.push_back(progress);
330+
return true;
331+
}})
333332
.has_value());
334333
ASSERT_TRUE(fs::exists(usdz_path));
335334
expect_progress_completed(updates);
@@ -365,11 +364,10 @@ namespace {
365364
const std::string existing_contents = "existing usdz data";
366365
write_text_file(usdz_path, existing_contents);
367366

368-
auto result = save_nurec_usdz(original, {
369-
.output_path = usdz_path,
370-
.progress_callback = [](float progress, const std::string&) {
371-
return progress < 1.0f;
372-
}});
367+
auto result = save_nurec_usdz(original, {.output_path = usdz_path,
368+
.progress_callback = [](float progress, const std::string&) {
369+
return progress < 1.0f;
370+
}});
373371
ASSERT_FALSE(result.has_value());
374372
EXPECT_EQ(result.error().code, ErrorCode::CANCELLED);
375373
expect_existing_target_and_no_temp_files(usdz_path, existing_contents);

tests/test_usd_format.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,11 @@ namespace {
155155
const fs::path usd_path = temp_dir / "roundtrip.usda";
156156
std::vector<float> updates;
157157

158-
ASSERT_TRUE(save_usd(original, {
159-
.output_path = usd_path,
160-
.progress_callback = [&](float progress, const std::string&) {
161-
updates.push_back(progress);
162-
return true;
163-
}})
158+
ASSERT_TRUE(save_usd(original, {.output_path = usd_path,
159+
.progress_callback = [&](float progress, const std::string&) {
160+
updates.push_back(progress);
161+
return true;
162+
}})
164163
.has_value());
165164
ASSERT_TRUE(fs::exists(usd_path));
166165
expect_progress_completed(updates);
@@ -233,11 +232,10 @@ namespace {
233232
const std::string existing_contents = "existing usd data";
234233
write_text_file(usd_path, existing_contents);
235234

236-
auto result = save_usd(splat, {
237-
.output_path = usd_path,
238-
.progress_callback = [](float progress, const std::string&) {
239-
return progress < 1.0f;
240-
}});
235+
auto result = save_usd(splat, {.output_path = usd_path,
236+
.progress_callback = [](float progress, const std::string&) {
237+
return progress < 1.0f;
238+
}});
241239
ASSERT_FALSE(result.has_value());
242240
EXPECT_EQ(result.error().code, ErrorCode::CANCELLED);
243241
expect_existing_target_and_no_temp_files(usd_path, existing_contents);

0 commit comments

Comments
 (0)