@@ -33,20 +33,20 @@ namespace embree
3333 {
3434 public:
3535 ParseLocation () : fileName(nullptr ), lineNumber(-1 ), colNumber(-1 ), charNumber(-1 ) {}
36- ParseLocation (const char * fileName, ssize_t lineNumber, ssize_t colNumber, ssize_t charNumber)
36+ ParseLocation (std::shared_ptr<std::string> fileName, ssize_t lineNumber, ssize_t colNumber, ssize_t charNumber)
3737 : fileName(fileName), lineNumber(lineNumber), colNumber(colNumber), charNumber(charNumber) {}
3838
3939 std::string str () const
4040 {
4141 std::string str = " unknown" ;
42- if (fileName) str = fileName;
42+ if (fileName) str = * fileName;
4343 if (lineNumber >= 0 ) str += " line " + toString (lineNumber);
4444 if (lineNumber >= 0 && colNumber >= 0 ) str += " character " + toString (colNumber);
4545 return str;
4646 }
4747
4848 private:
49- const char * fileName; // / name of the file (or stream) the token is from
49+ std::shared_ptr<std::string> fileName; // / name of the file (or stream) the token is from
5050 ssize_t lineNumber; // / the line number the token is from
5151 ssize_t colNumber; // / the character number in the current line
5252 ssize_t charNumber; // / the character in the file
@@ -113,10 +113,10 @@ namespace embree
113113 {
114114 public:
115115 StdStream (std::istream& cin, const std::string& name = " std::stream" )
116- : cin(cin), lineNumber(1 ), colNumber(0 ), charNumber(0 ), name(name) {}
116+ : cin(cin), lineNumber(1 ), colNumber(0 ), charNumber(0 ), name(std::shared_ptr<std::string>( new std::string( name)) ) {}
117117 ~StdStream () {}
118118 ParseLocation location () {
119- return ParseLocation (name. c_str () ,lineNumber,colNumber,charNumber);
119+ return ParseLocation (name,lineNumber,colNumber,charNumber);
120120 }
121121 int next () {
122122 int c = cin.get ();
@@ -129,7 +129,7 @@ namespace embree
129129 ssize_t lineNumber; // / the line number the token is from
130130 ssize_t colNumber; // / the character number in the current line
131131 ssize_t charNumber; // / the character in the file
132- std::string name; // / name of buffer
132+ std::shared_ptr<std:: string> name; // / name of buffer
133133 };
134134
135135 /* ! creates a stream from a file */
@@ -138,10 +138,10 @@ namespace embree
138138 public:
139139
140140 FileStream (FILE* file, const std::string& name = " file" )
141- : file(file), lineNumber(1 ), colNumber(0 ), charNumber(0 ), name(name) {}
141+ : file(file), lineNumber(1 ), colNumber(0 ), charNumber(0 ), name(std::shared_ptr<std::string>( new std::string( name)) ) {}
142142
143143 FileStream (const FileName& fileName)
144- : lineNumber(1 ), colNumber(0 ), charNumber(0 ), name(fileName.str())
144+ : lineNumber(1 ), colNumber(0 ), charNumber(0 ), name(std::shared_ptr<std::string>( new std::string( fileName.str()) ))
145145 {
146146 file = fopen (fileName.c_str ()," r" );
147147 if (file == nullptr ) THROW_RUNTIME_ERROR (" cannot open file " + fileName.str ());
@@ -150,7 +150,7 @@ namespace embree
150150
151151 public:
152152 ParseLocation location () {
153- return ParseLocation (name. c_str () ,lineNumber,colNumber,charNumber);
153+ return ParseLocation (name,lineNumber,colNumber,charNumber);
154154 }
155155
156156 int next () {
@@ -165,7 +165,7 @@ namespace embree
165165 ssize_t lineNumber; // / the line number the token is from
166166 ssize_t colNumber; // / the character number in the current line
167167 ssize_t charNumber; // / the character in the file
168- std::string name; // / name of buffer
168+ std::shared_ptr<std:: string> name; // / name of buffer
169169 };
170170
171171 /* ! creates a stream from a string */
@@ -178,7 +178,7 @@ namespace embree
178178
179179 public:
180180 ParseLocation location () {
181- return ParseLocation (nullptr ,lineNumber,colNumber,charNumber);
181+ return ParseLocation (std::shared_ptr<std::string>() ,lineNumber,colNumber,charNumber);
182182 }
183183
184184 int next () {
@@ -201,15 +201,15 @@ namespace embree
201201 {
202202 public:
203203 CommandLineStream (int argc, char ** argv, const std::string& name = " command line" )
204- : i(0 ), j(0 ), charNumber(0 ), name(name)
204+ : i(0 ), j(0 ), charNumber(0 ), name(std::shared_ptr<std::string>( new std::string( name)) )
205205 {
206206 if (argc > 0 ) charNumber = strlen (argv[0 ])+1 ;
207207 for (ssize_t k=1 ; k<argc; k++) args.push_back (argv[k]);
208208 }
209209 ~CommandLineStream () {}
210210 public:
211211 ParseLocation location () {
212- return ParseLocation (name. c_str () ,0 ,charNumber,charNumber);
212+ return ParseLocation (name,0 ,charNumber,charNumber);
213213 }
214214 int next () {
215215 if (i == args.size ()) return EOF;
@@ -221,6 +221,6 @@ namespace embree
221221 size_t i,j;
222222 std::vector<std::string> args;
223223 ssize_t charNumber; // / the character in the file
224- std::string name; // / name of buffer
224+ std::shared_ptr<std:: string> name; // / name of buffer
225225 };
226226}
0 commit comments