Skip to content

Commit

Permalink
AVRO-1542 replacing auto_ptr by unique_ptr & std::move
Browse files Browse the repository at this point in the history
This closes #157
  • Loading branch information
sanjosh authored and dkulp committed Dec 4, 2018
1 parent c5aa1d6 commit 0e6df48
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 171 deletions.
2 changes: 2 additions & 0 deletions lang/c++/CMakeLists.txt
Expand Up @@ -40,6 +40,8 @@ set (AVRO_VERSION_MINOR "0")
project (Avro-cpp)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})

add_definitions(-std=c++11 -fPIC)

if (WIN32 AND NOT CYGWIN AND NOT MSYS)
add_definitions (/EHa)
add_definitions (
Expand Down
30 changes: 15 additions & 15 deletions lang/c++/api/DataFile.hh
Expand Up @@ -65,16 +65,16 @@ class AVRO_DECL DataFileWriterBase : boost::noncopyable {
const size_t syncInterval_;
Codec codec_;

std::auto_ptr<OutputStream> stream_;
std::auto_ptr<OutputStream> buffer_;
std::unique_ptr<OutputStream> stream_;
std::unique_ptr<OutputStream> buffer_;
const DataFileSync sync_;
int64_t objectCount_;

typedef std::map<std::string, std::vector<uint8_t> > Metadata;

Metadata metadata_;

static std::auto_ptr<OutputStream> makeStream(const char* filename);
static std::unique_ptr<OutputStream> makeStream(const char* filename);
static DataFileSync makeSync();

void writeHeader();
Expand Down Expand Up @@ -113,7 +113,7 @@ public:
*/
DataFileWriterBase(const char* filename, const ValidSchema& schema,
size_t syncInterval, Codec codec = NULL_CODEC);
DataFileWriterBase(std::auto_ptr<OutputStream> outputStream,
DataFileWriterBase(std::unique_ptr<OutputStream> outputStream,
const ValidSchema& schema, size_t syncInterval, Codec codec);

~DataFileWriterBase();
Expand All @@ -139,7 +139,7 @@ public:
*/
template <typename T>
class DataFileWriter : boost::noncopyable {
std::auto_ptr<DataFileWriterBase> base_;
std::unique_ptr<DataFileWriterBase> base_;
public:
/**
* Constructs a new data file.
Expand All @@ -148,7 +148,7 @@ public:
size_t syncInterval = 16 * 1024, Codec codec = NULL_CODEC) :
base_(new DataFileWriterBase(filename, schema, syncInterval, codec)) { }

DataFileWriter(std::auto_ptr<OutputStream> outputStream, const ValidSchema& schema,
DataFileWriter(std::unique_ptr<OutputStream> outputStream, const ValidSchema& schema,
size_t syncInterval = 16 * 1024, Codec codec = NULL_CODEC) :
base_(new DataFileWriterBase(outputStream, schema, syncInterval, codec)) { }

Expand Down Expand Up @@ -183,7 +183,7 @@ public:
*/
class AVRO_DECL DataFileReaderBase : boost::noncopyable {
const std::string filename_;
const std::auto_ptr<InputStream> stream_;
const std::unique_ptr<InputStream> stream_;
const DecoderPtr decoder_;
int64_t objectCount_;
bool eof_;
Expand All @@ -194,7 +194,7 @@ class AVRO_DECL DataFileReaderBase : boost::noncopyable {
ValidSchema readerSchema_;
ValidSchema dataSchema_;
DecoderPtr dataDecoder_;
std::auto_ptr<InputStream> dataStream_;
std::unique_ptr<InputStream> dataStream_;
typedef std::map<std::string, std::vector<uint8_t> > Metadata;

Metadata metadata_;
Expand Down Expand Up @@ -232,7 +232,7 @@ public:
*/
DataFileReaderBase(const char* filename);

DataFileReaderBase(std::auto_ptr<InputStream> inputStream);
DataFileReaderBase(std::unique_ptr<InputStream> inputStream);

/**
* Initializes the reader so that the reader and writer schemas
Expand Down Expand Up @@ -293,7 +293,7 @@ public:
*/
template <typename T>
class DataFileReader : boost::noncopyable {
std::auto_ptr<DataFileReaderBase> base_;
std::unique_ptr<DataFileReaderBase> base_;
public:
/**
* Constructs the reader for the given file and the reader is
Expand All @@ -304,7 +304,7 @@ public:
base_->init(readerSchema);
}

DataFileReader(std::auto_ptr<InputStream> inputStream, const ValidSchema& readerSchema) :
DataFileReader(std::unique_ptr<InputStream> inputStream, const ValidSchema& readerSchema) :
base_(new DataFileReaderBase(inputStream)) {
base_->init(readerSchema);
}
Expand All @@ -318,7 +318,7 @@ public:
base_->init();
}

DataFileReader(std::auto_ptr<InputStream> inputStream) :
DataFileReader(std::unique_ptr<InputStream> inputStream) :
base_(new DataFileReaderBase(inputStream)) {
base_->init();
}
Expand All @@ -332,7 +332,7 @@ public:
* The schema present in the data file will be used for reading
* from this reader.
*/
DataFileReader(std::auto_ptr<DataFileReaderBase> base) : base_(base) {
DataFileReader(std::unique_ptr<DataFileReaderBase> base) : base_(std::move(base)) {
base_->init();
}

Expand All @@ -345,8 +345,8 @@ public:
* The argument readerSchema will be used for reading
* from this reader.
*/
DataFileReader(std::auto_ptr<DataFileReaderBase> base,
const ValidSchema& readerSchema) : base_(base) {
DataFileReader(std::unique_ptr<DataFileReaderBase> base,
const ValidSchema& readerSchema) : base_(std::move(base)) {
base_->init(readerSchema);
}

Expand Down
16 changes: 8 additions & 8 deletions lang/c++/api/Stream.hh
Expand Up @@ -147,14 +147,14 @@ public:
/**
* Returns a new OutputStream, which grows in memory chunks of specified size.
*/
AVRO_DECL std::auto_ptr<OutputStream> memoryOutputStream(size_t chunkSize = 4 * 1024);
AVRO_DECL std::unique_ptr<OutputStream> memoryOutputStream(size_t chunkSize = 4 * 1024);

/**
* Returns a new InputStream, with the data from the given byte array.
* It does not copy the data, the byte array should remain valid
* until the InputStream is used.
*/
AVRO_DECL std::auto_ptr<InputStream> memoryInputStream(const uint8_t* data, size_t len);
AVRO_DECL std::unique_ptr<InputStream> memoryInputStream(const uint8_t* data, size_t len);

/**
* Returns a new InputStream with the contents written into an
Expand All @@ -163,7 +163,7 @@ AVRO_DECL std::auto_ptr<InputStream> memoryInputStream(const uint8_t* data, size
* input stream are the snapshot of the outputstream. One can construct
* any number of memory input stream from a single memory output stream.
*/
AVRO_DECL std::auto_ptr<InputStream> memoryInputStream(const OutputStream& source);
AVRO_DECL std::unique_ptr<InputStream> memoryInputStream(const OutputStream& source);

/**
* Returns the contents written so far into the output stream, which should
Expand All @@ -179,32 +179,32 @@ AVRO_DECL boost::shared_ptr<std::vector<uint8_t> > snapshot(const OutputStream&
* If there is a file with the given name, it is truncated and overwritten.
* If there is no file with the given name, it is created.
*/
AVRO_DECL std::auto_ptr<OutputStream> fileOutputStream(const char* filename,
AVRO_DECL std::unique_ptr<OutputStream> fileOutputStream(const char* filename,
size_t bufferSize = 8 * 1024);

/**
* Returns a new InputStream whose contents come from the given file.
* Data is read in chunks of given buffer size.
*/
AVRO_DECL std::auto_ptr<InputStream> fileInputStream(
AVRO_DECL std::unique_ptr<InputStream> fileInputStream(
const char *filename, size_t bufferSize = 8 * 1024);
AVRO_DECL std::auto_ptr<SeekableInputStream> fileSeekableInputStream(
AVRO_DECL std::unique_ptr<SeekableInputStream> fileSeekableInputStream(
const char *filename, size_t bufferSize = 8 * 1024);

/**
* Returns a new OutputStream whose contents will be sent to the given
* std::ostream. The std::ostream object should outlive the returned
* OutputStream.
*/
AVRO_DECL std::auto_ptr<OutputStream> ostreamOutputStream(std::ostream& os,
AVRO_DECL std::unique_ptr<OutputStream> ostreamOutputStream(std::ostream& os,
size_t bufferSize = 8 * 1024);

/**
* Returns a new InputStream whose contents come from the given
* std::istream. The std::istream object should outlive the returned
* InputStream.
*/
AVRO_DECL std::auto_ptr<InputStream> istreamInputStream(
AVRO_DECL std::unique_ptr<InputStream> istreamInputStream(
std::istream &in, size_t bufferSize = 8 * 1024);

/** A convenience class for reading from an InputStream */
Expand Down
4 changes: 2 additions & 2 deletions lang/c++/examples/custom.cc
Expand Up @@ -42,13 +42,13 @@ struct codec_traits<std::complex<T> > {
int
main()
{
std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
std::unique_ptr<avro::OutputStream> out = avro::memoryOutputStream();
avro::EncoderPtr e = avro::binaryEncoder();
e->init(*out);
std::complex<double> c1(1.0, 2.0);
avro::encode(*e, c1);

std::auto_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::binaryDecoder();
d->init(*in);

Expand Down
4 changes: 2 additions & 2 deletions lang/c++/examples/generated.cc
Expand Up @@ -24,15 +24,15 @@
int
main()
{
std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
std::unique_ptr<avro::OutputStream> out = avro::memoryOutputStream();
avro::EncoderPtr e = avro::binaryEncoder();
e->init(*out);
c::cpx c1;
c1.re = 1.0;
c1.im = 2.13;
avro::encode(*e, c1);

std::auto_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::binaryDecoder();
d->init(*in);

Expand Down
4 changes: 2 additions & 2 deletions lang/c++/examples/generic.cc
Expand Up @@ -35,15 +35,15 @@ main()
avro::ValidSchema cpxSchema;
avro::compileJsonSchema(ifs, cpxSchema);

std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
std::unique_ptr<avro::OutputStream> out = avro::memoryOutputStream();
avro::EncoderPtr e = avro::binaryEncoder();
e->init(*out);
c::cpx c1;
c1.re = 100.23;
c1.im = 105.77;
avro::encode(*e, c1);

std::auto_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::binaryDecoder();
d->init(*in);

Expand Down
4 changes: 2 additions & 2 deletions lang/c++/examples/resolving.cc
Expand Up @@ -43,15 +43,15 @@ main()
avro::ValidSchema cpxSchema = load("cpx.json");
avro::ValidSchema imaginarySchema = load("imaginary.json");

std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
std::unique_ptr<avro::OutputStream> out = avro::memoryOutputStream();
avro::EncoderPtr e = avro::binaryEncoder();
e->init(*out);
c::cpx c1;
c1.re = 100.23;
c1.im = 105.77;
avro::encode(*e, c1);

std::auto_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::resolvingDecoder(cpxSchema, imaginarySchema,
avro::binaryDecoder());
d->init(*in);
Expand Down
4 changes: 2 additions & 2 deletions lang/c++/examples/validating.cc
Expand Up @@ -49,14 +49,14 @@ main()
avro::ValidSchema cpxSchema;
avro::compileJsonSchema(ifs, cpxSchema);

std::auto_ptr<avro::OutputStream> out = avro::memoryOutputStream();
std::unique_ptr<avro::OutputStream> out = avro::memoryOutputStream();
avro::EncoderPtr e = avro::validatingEncoder(cpxSchema,
avro::binaryEncoder());
e->init(*out);
std::complex<double> c1(1.0, 2.0);
avro::encode(*e, c1);

std::auto_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::validatingDecoder(cpxSchema,
avro::binaryDecoder());
d->init(*in);
Expand Down
4 changes: 2 additions & 2 deletions lang/c++/impl/Compiler.cc
Expand Up @@ -538,7 +538,7 @@ AVRO_DECL ValidSchema compileJsonSchemaFromStream(InputStream& is)

AVRO_DECL ValidSchema compileJsonSchemaFromFile(const char* filename)
{
std::auto_ptr<InputStream> s = fileInputStream(filename);
std::unique_ptr<InputStream> s = fileInputStream(filename);
return compileJsonSchemaFromStream(*s);
}

Expand All @@ -561,7 +561,7 @@ AVRO_DECL ValidSchema compileJsonSchemaFromString(const string& input)

static ValidSchema compile(std::istream& is)
{
std::auto_ptr<InputStream> in = istreamInputStream(is);
std::unique_ptr<InputStream> in = istreamInputStream(is);
return compileJsonSchemaFromStream(*in);
}

Expand Down

0 comments on commit 0e6df48

Please sign in to comment.