Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
utility.h
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
8#pragma once
9
10#include <sstream>
11#include <string>
12#include <string_view>
13#include <vector>
14
15namespace momentum::io_detail {
16
19 std::string content;
20 size_t startLine;
21};
22
26 public:
27 void addSegment(std::string_view content, size_t startLine) {
28 segments_.push_back({std::string(content), startLine});
29 }
30
31 [[nodiscard]] bool empty() const {
32 return segments_.empty();
33 }
34
37 public:
38 explicit LineIterator(const std::vector<SectionSegment>& segments);
39
42 bool getline(std::string& line);
43
45 [[nodiscard]] size_t currentLine() const;
46
47 private:
48 const std::vector<SectionSegment>& segments_;
49 size_t segmentIndex_;
50 size_t lineInSegment_;
51 std::istringstream currentStream_;
52 };
53
54 [[nodiscard]] LineIterator begin() const {
55 return LineIterator(segments_);
56 }
57
59 [[nodiscard]] std::string toString() const;
60
61 private:
62 std::vector<SectionSegment> segments_;
63};
64
65} // namespace momentum::io_detail
Iterator that walks through all segments while tracking line numbers.
Definition utility.h:36
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
Holds all segments of a section and provides line-aware iteration This is used internally to track li...
Definition utility.h:25
std::string toString() const
Get all content as a single concatenated string (for backward compatibility).
Definition utility.cpp:45
void addSegment(std::string_view content, size_t startLine)
Definition utility.h:27
LineIterator begin() const
Definition utility.h:54
Represents a single segment of a section (when sections are split across the file).
Definition utility.h:18