aboutsummaryrefslogtreecommitdiffstats
path: root/streamingvisitors/src/vespa/vsm/vsm/flattendocsumwriter.h
blob: f6eb29f9f7ec88fcf37db170fe81a94ee000cbf5 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <vespa/document/fieldvalue/fieldvalue.h>
#include <vespa/document/fieldvalue/iteratorhandler.h>
#include <vespa/vsm/common/charbuffer.h>

namespace vsm {

/**
 * This class is used to flatten out and write a complex field value.
 * A separator string is inserted between primitive field values.
 **/
class FlattenDocsumWriter : public document::fieldvalue::IteratorHandler {
private:
    CharBuffer       _output;
    vespalib::string _separator;
    bool             _useSeparator;

    void considerSeparator();
    void onPrimitive(uint32_t, const Content & c) override;

public:
    FlattenDocsumWriter(const vespalib::string & separator = " ");
    ~FlattenDocsumWriter();
    void setSeparator(const vespalib::string & separator) { _separator = separator; }
    const CharBuffer & getResult() const { return _output; }
    void clear() {
        _output.reset();
        _separator = " ";
        _useSeparator = false;
    }
};

}