1 /* Frobby: Software for monomial ideal computations.
2    Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3 
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; either version 2 of the License, or
7    (at your option) any later version.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see http://www.gnu.org/licenses/.
16 */
17 #ifndef FROBBY_STRING_STREAM_GUARD
18 #define FROBBY_STRING_STREAM_GUARD
19 
20 #include <string>
21 #include <stdexcept>
22 
23 /** A replacement for stringstream. See the .cpp file for a motivation
24  to use this instead of the regular stringstream. It should not be
25  used for operations that need to be efficient. */
26 class FrobbyStringStream {
27  public:
28   FrobbyStringStream& operator<<(unsigned long long integer);
29   FrobbyStringStream& operator<<(unsigned long integer);
30   FrobbyStringStream& operator<<(unsigned int integer);
31   FrobbyStringStream& operator<<(const mpz_class& integer);
32   FrobbyStringStream& operator<<(const string& text);
33   FrobbyStringStream& operator<<(const char* text);
34 
35   /** This overload actually appends the character to the stream
36    instead of appending a string representation of the number. This
37    is different from stringstream. */
38   FrobbyStringStream& operator<<(char character);
39 
40   string& str();
41   const string& str() const;
42   operator const string&() const;
43 
clear()44   void clear() {_str.clear();}
45 
46   static void appendIntegerToString(string& str, unsigned long integer);
47   static void appendIntegerToString(string& str, const mpz_class& integer);
48 
49   /** Throws NotAnIntegerException if str is not the string
50    representation of an integer. */
51   static void parseInteger(mpz_class& integer, const string& str);
52   class NotAnIntegerException : public runtime_error {
53   public:
54     NotAnIntegerException(const string&);
55   };
56 
57  private:
58   string _str;
59 };
60 
61 #endif
62