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.

slice.cc 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. #include "minddata/dataset/util/slice.h"
  14. namespace mindspore {
  15. namespace dataset {
  16. WritableSlice::WritableSlice(const WritableSlice &src, off64_t offset, size_t len) : ReadableSlice(src, offset, len) {
  17. mutable_data_ = static_cast<char *>(src.mutable_data_) + offset;
  18. }
  19. WritableSlice::WritableSlice(const WritableSlice &src, off64_t offset)
  20. : WritableSlice(src, offset, src.GetSize() - offset) {}
  21. Status WritableSlice::Copy(WritableSlice *dest, const ReadableSlice &src) {
  22. RETURN_UNEXPECTED_IF_NULL(dest);
  23. RETURN_UNEXPECTED_IF_NULL(dest->GetMutablePointer());
  24. if (dest->GetSize() <= 0) {
  25. RETURN_STATUS_UNEXPECTED("Destination length is non-positive");
  26. }
  27. auto err = memcpy_s(dest->GetMutablePointer(), dest->GetSize(), src.GetPointer(), src.GetSize());
  28. if (err) {
  29. RETURN_STATUS_UNEXPECTED(std::to_string(err));
  30. }
  31. return Status::OK();
  32. }
  33. } // namespace dataset
  34. } // namespace mindspore