Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
utility.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
9
10namespace momentum::io_detail {
11
12// LineIterator implementation
13SectionContent::LineIterator::LineIterator(const std::vector<SectionSegment>& segments)
14 : segments_(segments), segmentIndex_(0), lineInSegment_(0) {
15 if (!segments_.empty()) {
16 currentStream_.str(segments_[0].content);
17 }
18}
19
21 while (segmentIndex_ < segments_.size()) {
22 if (std::getline(currentStream_, line)) {
23 ++lineInSegment_;
24 return true;
25 }
26
27 // Move to next segment
28 ++segmentIndex_;
29 lineInSegment_ = 0;
30 if (segmentIndex_ < segments_.size()) {
31 currentStream_.clear();
32 currentStream_.str(segments_[segmentIndex_].content);
33 }
34 }
35 return false;
36}
37
39 if (segmentIndex_ >= segments_.size()) {
40 return 0;
41 }
42 return segments_[segmentIndex_].startLine + lineInSegment_ - 1;
43}
44
45std::string SectionContent::toString() const {
46 std::string result;
47 for (const auto& segment : segments_) {
48 result += segment.content;
49 }
50 return result;
51}
52
53} // namespace momentum::io_detail
size_t currentLine() const
Get the current line number in the original file.
Definition utility.cpp:38
bool getline(std::string &line)
Get the next line from the sections.
Definition utility.cpp:20
LineIterator(const std::vector< SectionSegment > &segments)
Definition utility.cpp:13
std::string toString() const
Get all content as a single concatenated string (for backward compatibility).
Definition utility.cpp:45