Path: blob/master/thirdparty/embree/common/lexers/parsestream.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "stringstream.h"6#include "../sys/filename.h"7#include "../math/vec2.h"8#include "../math/vec3.h"9#include "../math/col3.h"10#include "../math/color.h"1112namespace embree13{14/*! helper class for simple command line parsing */15class ParseStream : public Stream<std::string>16{17public:18ParseStream (const Ref<Stream<std::string> >& cin) : cin(cin) {}1920ParseStream (const Ref<Stream<int> >& cin, const std::string& seps = "\n\t\r ",21const std::string& endl = "", bool multiLine = false)22: cin(new StringStream(cin,seps,endl,multiLine)) {}2324public:25ParseLocation location() { return cin->loc(); }26std::string next() { return cin->get(); }2728void force(const std::string& next) {29std::string token = getString();30if (token != next)31THROW_RUNTIME_ERROR("token \""+next+"\" expected but token \""+token+"\" found");32}3334std::string getString() {35return get();36}3738FileName getFileName() {39return FileName(get());40}4142int getInt () {43return atoi(get().c_str());44}4546Vec2i getVec2i() {47int x = atoi(get().c_str());48int y = atoi(get().c_str());49return Vec2i(x,y);50}5152Vec3ia getVec3ia() {53int x = atoi(get().c_str());54int y = atoi(get().c_str());55int z = atoi(get().c_str());56return Vec3ia(x,y,z);57}5859float getFloat() {60return (float)atof(get().c_str());61}6263Vec2f getVec2f() {64float x = (float)atof(get().c_str());65float y = (float)atof(get().c_str());66return Vec2f(x,y);67}6869Vec3f getVec3f() {70float x = (float)atof(get().c_str());71float y = (float)atof(get().c_str());72float z = (float)atof(get().c_str());73return Vec3f(x,y,z);74}7576Vec3fa getVec3fa() {77float x = (float)atof(get().c_str());78float y = (float)atof(get().c_str());79float z = (float)atof(get().c_str());80return Vec3fa(x,y,z);81}8283Col3f getCol3f() {84float x = (float)atof(get().c_str());85float y = (float)atof(get().c_str());86float z = (float)atof(get().c_str());87return Col3f(x,y,z);88}8990Color getColor() {91float r = (float)atof(get().c_str());92float g = (float)atof(get().c_str());93float b = (float)atof(get().c_str());94return Color(r,g,b);95}9697private:98Ref<Stream<std::string> > cin;99};100}101102103