Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/common/sys/estring.h
9912 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "platform.h"
7
#include "../math/vec2.h"
8
#include "../math/vec3.h"
9
#include "../math/vec4.h"
10
11
namespace embree
12
{
13
class IOStreamStateRestorer
14
{
15
public:
16
IOStreamStateRestorer(std::ostream& iostream)
17
: iostream(iostream), flags(iostream.flags()), precision(iostream.precision()) {
18
}
19
20
~IOStreamStateRestorer() {
21
iostream.flags(flags);
22
iostream.precision(precision);
23
}
24
25
private:
26
std::ostream& iostream;
27
std::ios::fmtflags flags;
28
std::streamsize precision;
29
};
30
31
struct IndentOStream : public std::streambuf
32
{
33
explicit IndentOStream(std::ostream &ostream, int indent = 2)
34
: streambuf(ostream.rdbuf())
35
, start_of_line(true)
36
, ident_str(indent, ' ')
37
, stream(&ostream)
38
{
39
// set streambuf of ostream to this and save original streambuf
40
stream->rdbuf(this);
41
}
42
43
virtual ~IndentOStream()
44
{
45
if (stream != NULL) {
46
// restore old streambuf
47
stream->rdbuf(streambuf);
48
}
49
}
50
51
protected:
52
virtual int overflow(int ch) {
53
if (start_of_line && ch != '\n') {
54
streambuf->sputn(ident_str.data(), ident_str.size());
55
}
56
start_of_line = ch == '\n';
57
return streambuf->sputc(ch);
58
}
59
60
private:
61
std::streambuf *streambuf;
62
bool start_of_line;
63
std::string ident_str;
64
std::ostream *stream;
65
};
66
67
std::string toLowerCase(const std::string& s);
68
std::string toUpperCase(const std::string& s);
69
70
Vec2f string_to_Vec2f ( std::string str );
71
Vec3f string_to_Vec3f ( std::string str );
72
Vec4f string_to_Vec4f ( std::string str );
73
}
74
75