File: streamfilters.h

package info (click to toggle)
embree 4.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 100,656 kB
  • sloc: cpp: 228,918; xml: 40,944; ansic: 2,685; python: 812; sh: 635; makefile: 228; csh: 42
file content (39 lines) | stat: -rw-r--r-- 1,055 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "stream.h"

namespace embree
{
  /* removes all line comments from a stream */
  class LineCommentFilter : public Stream<int>
  {
  public:
    LineCommentFilter (const FileName& fileName, const std::string& lineComment)
      : cin(new FileStream(fileName)), lineComment(lineComment) {}
    LineCommentFilter (Ref<Stream<int> > cin, const std::string& lineComment)
      : cin(cin), lineComment(lineComment) {}

    ParseLocation location() { return cin->loc(); }

    int next()
    {
      /* look if the line comment starts here */
      for (size_t j=0; j<lineComment.size(); j++) {
        if (cin->peek() != lineComment[j]) { cin->unget(j); goto not_found; }
        cin->get();
      }
      /* eat all characters until the end of the line (or file) */
      while (cin->peek() != '\n' && cin->peek() != EOF) cin->get();

    not_found:
      return cin->get();
    }

  private:
    Ref<Stream<int> > cin;
    std::string lineComment;
  };
}