Path: blob/master/thirdparty/embree/common/sys/estring.h
9912 views
// Copyright 2009-2021 Intel Corporation1// SPDX-License-Identifier: Apache-2.023#pragma once45#include "platform.h"6#include "../math/vec2.h"7#include "../math/vec3.h"8#include "../math/vec4.h"910namespace embree11{12class IOStreamStateRestorer13{14public:15IOStreamStateRestorer(std::ostream& iostream)16: iostream(iostream), flags(iostream.flags()), precision(iostream.precision()) {17}1819~IOStreamStateRestorer() {20iostream.flags(flags);21iostream.precision(precision);22}2324private:25std::ostream& iostream;26std::ios::fmtflags flags;27std::streamsize precision;28};2930struct IndentOStream : public std::streambuf31{32explicit IndentOStream(std::ostream &ostream, int indent = 2)33: streambuf(ostream.rdbuf())34, start_of_line(true)35, ident_str(indent, ' ')36, stream(&ostream)37{38// set streambuf of ostream to this and save original streambuf39stream->rdbuf(this);40}4142virtual ~IndentOStream()43{44if (stream != NULL) {45// restore old streambuf46stream->rdbuf(streambuf);47}48}4950protected:51virtual int overflow(int ch) {52if (start_of_line && ch != '\n') {53streambuf->sputn(ident_str.data(), ident_str.size());54}55start_of_line = ch == '\n';56return streambuf->sputc(ch);57}5859private:60std::streambuf *streambuf;61bool start_of_line;62std::string ident_str;63std::ostream *stream;64};6566std::string toLowerCase(const std::string& s);67std::string toUpperCase(const std::string& s);6869Vec2f string_to_Vec2f ( std::string str );70Vec3f string_to_Vec3f ( std::string str );71Vec4f string_to_Vec4f ( std::string str );72}737475