Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ParseUtils.h
Go to the documentation of this file.
1/************************************************************************************[ParseUtils.h]
2Copyright (c) 2003-2006, Niklas Een, Niklas Sorensson
3Copyright (c) 2007-2010, Niklas Sorensson
4
5Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6associated documentation files (the "Software"), to deal in the Software without restriction,
7including without limitation the rights to use, copy, modify, merge, publish, distribute,
8sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in all copies or
12substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19**************************************************************************************************/
20
21#pragma once
22
23#include <stdlib.h>
24#include <stdio.h>
25
26//#include <ogdf/lib/minisat/win/zlib.h>
27
28namespace Minisat {
29namespace Internal {
30
31//-------------------------------------------------------------------------------------------------
32// A simple buffered character stream class:
33
34static const int buffer_size = 1048576;
35
36/*
37class StreamBuffer {
38 gzFile in;
39 unsigned char buf[buffer_size];
40 int pos;
41 int size;
42
43 void assureLookahead() {
44 if (pos >= size) {
45 pos = 0;
46 size = gzread(in, buf, sizeof(buf)); } }
47
48public:
49 explicit StreamBuffer(gzFile i) : in(i), pos(0), size(0) { assureLookahead(); }
50
51 int operator * () const { return (pos >= size) ? EOF : buf[pos]; }
52 void operator ++ () { pos++; assureLookahead(); }
53 int position () const { return pos; }
54};
55
56
57//-------------------------------------------------------------------------------------------------
58// End-of-file detection functions for StreamBuffer and char*:
59
60
61static inline bool isEof(StreamBuffer& in) { return *in == EOF; }
62static inline bool isEof(const char* in) { return *in == '\0'; }
63
64*/
65
66//-------------------------------------------------------------------------------------------------
67// Generic parse functions parametrized over the input-stream type.
68
69
70template<class B>
71static void skipWhitespace(B& in) {
72 while ((*in >= 9 && *in <= 13) || *in == 32)
73 ++in; }
74
75
76template<class B>
77static void skipLine(B& in) {
78 for (;;){
79 if (isEof(in)) return;
80 if (*in == '\n') { ++in; return; }
81 ++in; } }
82
83
84template<class B>
85static int parseInt(B& in) {
86 int val = 0;
87 bool neg = false;
89 if (*in == '-') neg = true, ++in;
90 else if (*in == '+') ++in;
91 if (*in < '0' || *in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", *in), exit(3);
92 while (*in >= '0' && *in <= '9')
93 val = val*10 + (*in - '0'),
94 ++in;
95 return neg ? -val : val; }
96
97
98// String matching: in case of a match the input iterator will be advanced the corresponding
99// number of characters.
100template<class B>
101static bool match(B& in, const char* str) {
102 int i;
103 for (i = 0; str[i] != '\0'; i++)
104 if (in[i] != str[i])
105 return false;
106
107 in += i;
108
109 return true;
110}
111
112// String matching: consumes characters eagerly, but does not require random access iterator.
113template<class B>
114static bool eagerMatch(B& in, const char* str) {
115 for (; *str != '\0'; ++str, ++in)
116 if (*str != *in)
117 return false;
118 return true; }
119
120
121//=================================================================================================
122} // namespace Internal
123} // namespace Minisat
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
static const int buffer_size
Definition ParseUtils.h:34
static bool eagerMatch(B &in, const char *str)
Definition ParseUtils.h:114
static bool match(B &in, const char *str)
Definition ParseUtils.h:101
static int parseInt(B &in)
Definition ParseUtils.h:85
static void skipLine(B &in)
Definition ParseUtils.h:77
static void skipWhitespace(B &in)
Definition ParseUtils.h:71