BT-MatML-Editor 0.1.4
Editor for the MatML 3.1 XML Schema
StringStream.h
1#ifndef STRINGSTREAM_H
2#define STRINGSTREAM_H
3
4//************Converting an Arbitrary Type to String**************
5//Our first function template takes a value of an arbitrary type T,
6//converts it to string, and writes the result to a user-supplied
7//string called val. We use the stringstream::str() member function
8//to obtain a copy of the stream's internal string:
9
10#include <sstream>
11#include <string>
12using namespace std;
13
14namespace bellshire{
15template <class T>
16void string_fmt(string & val, const T & t)
17{
18 ostringstream oss; // create a stream
19 oss << t; // insert value to stream
20 val=oss.str(); // extract string and copy
21}
22
23//In the following example, we use the string_fmt() function
24//template to convert the value 10.76 to string and write the
25//result to val:
26//
27//
28//string val;
29//string_fmt(val,10.76);
30
31
32//************Converting from One Arbitrary Type to Another************
33//Our second function template is called cast_stream().
34//It converts a variable of type in_value to a variable
35//of type out_type (in_value and out_value are template parameters):
36
37template <class out_type, class in_value>
38out_type cast_stream(const in_value & t)
39{
40 stringstream ss;
41 ss << t; // first insert value to stream
42 out_type result; // value will be converted to out_type
43 ss >> result; // write value to result
44 return result;
45}
46//In the following example, cast_stream() converts
47//a string with the value "18.67" to double using cast_stream():
48//
49//string s="18.67";
50//double d=cast_stream < double > (s); // assign 18.67 to d
51
52}//namespace bellshire
53
54#endif // STRINGSTREAM_H
Contains the GUI and GUI associated classes. OnInit() calls the creation of the MaterialFrame GUI
Definition: BT_MatML_App.h:39