summaryrefslogtreecommitdiffstats
path: root/staging_vespalib/src/vespa/vespalib/objects/cloneable.h
blob: c0b12272797b56aed74bf1629ccded79b043dac5 (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
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
/**
 * @class vespalib::Cloneable
 * @brief Superclass for objects implementing clone() deep copy.
 */

#include <memory>

namespace vespalib {

class Cloneable {
public:
    /**
     * @brief Creates a clone of this instance.
     *
     * Note that the caller takes ownership of the returned object. It
     * is not an unique_ptr since that would not support covariant
     * return types. A class T that inherits this interface should
     * define T* clone() const, such that people cloning a T object
     * don't need to cast it to get the correct type.
     */
    virtual Cloneable* clone() const = 0;
    virtual ~Cloneable() {}
};

} // namespace vespalib