Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/embree/common/lexers/parsestream.h
9912 views
1
// Copyright 2009-2021 Intel Corporation
2
// SPDX-License-Identifier: Apache-2.0
3
4
#pragma once
5
6
#include "stringstream.h"
7
#include "../sys/filename.h"
8
#include "../math/vec2.h"
9
#include "../math/vec3.h"
10
#include "../math/col3.h"
11
#include "../math/color.h"
12
13
namespace embree
14
{
15
/*! helper class for simple command line parsing */
16
class ParseStream : public Stream<std::string>
17
{
18
public:
19
ParseStream (const Ref<Stream<std::string> >& cin) : cin(cin) {}
20
21
ParseStream (const Ref<Stream<int> >& cin, const std::string& seps = "\n\t\r ",
22
const std::string& endl = "", bool multiLine = false)
23
: cin(new StringStream(cin,seps,endl,multiLine)) {}
24
25
public:
26
ParseLocation location() { return cin->loc(); }
27
std::string next() { return cin->get(); }
28
29
void force(const std::string& next) {
30
std::string token = getString();
31
if (token != next)
32
THROW_RUNTIME_ERROR("token \""+next+"\" expected but token \""+token+"\" found");
33
}
34
35
std::string getString() {
36
return get();
37
}
38
39
FileName getFileName() {
40
return FileName(get());
41
}
42
43
int getInt () {
44
return atoi(get().c_str());
45
}
46
47
Vec2i getVec2i() {
48
int x = atoi(get().c_str());
49
int y = atoi(get().c_str());
50
return Vec2i(x,y);
51
}
52
53
Vec3ia getVec3ia() {
54
int x = atoi(get().c_str());
55
int y = atoi(get().c_str());
56
int z = atoi(get().c_str());
57
return Vec3ia(x,y,z);
58
}
59
60
float getFloat() {
61
return (float)atof(get().c_str());
62
}
63
64
Vec2f getVec2f() {
65
float x = (float)atof(get().c_str());
66
float y = (float)atof(get().c_str());
67
return Vec2f(x,y);
68
}
69
70
Vec3f getVec3f() {
71
float x = (float)atof(get().c_str());
72
float y = (float)atof(get().c_str());
73
float z = (float)atof(get().c_str());
74
return Vec3f(x,y,z);
75
}
76
77
Vec3fa getVec3fa() {
78
float x = (float)atof(get().c_str());
79
float y = (float)atof(get().c_str());
80
float z = (float)atof(get().c_str());
81
return Vec3fa(x,y,z);
82
}
83
84
Col3f getCol3f() {
85
float x = (float)atof(get().c_str());
86
float y = (float)atof(get().c_str());
87
float z = (float)atof(get().c_str());
88
return Col3f(x,y,z);
89
}
90
91
Color getColor() {
92
float r = (float)atof(get().c_str());
93
float g = (float)atof(get().c_str());
94
float b = (float)atof(get().c_str());
95
return Color(r,g,b);
96
}
97
98
private:
99
Ref<Stream<std::string> > cin;
100
};
101
}
102
103