Files
SDK_SG200x_V2/cviruntime/include/runtime/stream.hpp
carbon e25f20f7a3 add cviruntime
commit 3f4938648950a7f3bf9a19c320ca9fae7c52de20
Author: sophgo-forum-service <forum_service@sophgo.com>
Date:   Mon May 13 13:44:23 2024 +0800

    [feat] cviruntime opensource for cv18xx soc.

    - a4b6a3, add cumsum and gatherelements_pt.
2024-05-31 11:51:34 +08:00

58 lines
1.1 KiB
C++

#ifndef RUNTIME_CVISTREAM_H
#define RUNTIME_CVISTREAM_H
#include <iostream>
#include <fstream>
namespace cvi {
namespace runtime {
class BaseStream {
public:
BaseStream() {}
virtual ~BaseStream() {}
size_t length() {
return _length;
}
virtual size_t read(uint8_t *buf, size_t offset, size_t size) = 0;
protected:
size_t _length = 0;
};
class FileStream : public BaseStream {
public:
FileStream(const std::string &file_name);
~FileStream();
size_t read(uint8_t *buf, size_t offset, size_t size);
private:
std::ifstream *_fstream;
};
class BufferStream : public BaseStream {
public:
BufferStream(const int8_t *buf, size_t size);
~BufferStream() {}
size_t read(uint8_t *buf, size_t offset, size_t size);
private:
const int8_t *buffer;
};
class FdStream : public BaseStream {
public:
FdStream(const int fd, const size_t ud_offset);
~FdStream() {};
size_t read(uint8_t *buf, size_t offset, size_t size);
private:
int file_descriptor;
size_t user_define_offset = 0; //The file header's offset that user defined.
};
} // namespace runtime
} // namespace cvi
#endif