You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pybind11_datareader.h 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* Tencent is pleased to support the open source community by making ncnn available.
  2. *
  3. * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
  4. *
  5. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. * in compliance with the License. You may obtain a copy of the License at
  7. *
  8. * https://opensource.org/licenses/BSD-3-Clause
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed
  11. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. * specific language governing permissions and limitations under the License.
  14. */
  15. #ifndef PYBIND11_NCNN_DATAREADER_H
  16. #define PYBIND11_NCNN_DATAREADER_H
  17. #include <datareader.h>
  18. class DataReaderFromEmpty : public ncnn::DataReader
  19. {
  20. public:
  21. #if NCNN_STRING
  22. virtual int scan(const char* format, void* p) const
  23. {
  24. return 0;
  25. }
  26. #endif // NCNN_STRING
  27. virtual size_t read(void* buf, size_t size) const
  28. {
  29. memset(buf, 0, size);
  30. return size;
  31. }
  32. };
  33. template<class Base = ncnn::DataReader>
  34. class PyDataReader : public Base
  35. {
  36. public:
  37. using Base::Base; // Inherit constructors
  38. #if NCNN_STRING
  39. int scan(const char* format, void* p) const override
  40. {
  41. PYBIND11_OVERLOAD(int, Base, scan, format, p);
  42. }
  43. #endif // NCNN_STRING
  44. size_t read(void* buf, size_t size) const override
  45. {
  46. PYBIND11_OVERLOAD(size_t, Base, read, buf, size);
  47. }
  48. };
  49. template<class Other>
  50. class PyDataReaderOther : public PyDataReader<Other>
  51. {
  52. public:
  53. using PyDataReader<Other>::PyDataReader;
  54. #if NCNN_STRING
  55. int scan(const char* format, void* p) const override
  56. {
  57. PYBIND11_OVERLOAD(int, Other, scan, format, p);
  58. }
  59. #endif // NCNN_STRING
  60. size_t read(void* buf, size_t size) const override
  61. {
  62. PYBIND11_OVERLOAD(size_t, Other, read, buf, size);
  63. }
  64. };
  65. #endif