• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019-2022 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_OPERATOR_CONNECTOR_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_OPERATOR_CONNECTOR_H_
18 
19 #include <memory>
20 #include <string>
21 #include <utility>
22 #include "minddata/dataset/core/tensor_row.h"
23 #include "minddata/dataset/engine/connector.h"
24 
25 #include "minddata/dataset/include/dataset/constants.h"
26 
27 namespace mindspore {
28 namespace dataset {
29 
30 class OperatorConnector : public Queue<TensorRow> {
31  public:
32   /// Constructor of OperatorConnector
33   /// \param queue_capacity The number of element (TensorRows) for the queue.
OperatorConnector(int32_t queue_capacity)34   explicit OperatorConnector(int32_t queue_capacity) : Queue<TensorRow>(queue_capacity), out_rows_count_(0) {}
35 
36   /// Destructor of -OperatorConnector
37   ~OperatorConnector() = default;
38 
PopFront(TensorRow * row)39   Status PopFront(TensorRow *row) override {
40     out_rows_count_++;
41     return Queue::PopFront(row);
42   }
SendEOE()43   Status SendEOE() noexcept {
44     TensorRow eoe = TensorRow(TensorRow::kFlagEOE);
45     return Add(std::move(eoe));
46   }
47 
SendEOF()48   Status SendEOF() noexcept {
49     TensorRow eof = TensorRow(TensorRow::kFlagEOF);
50     return Add(std::move(eof));
51   }
out_rows_count()52   auto out_rows_count() const { return out_rows_count_; }
53 
54  private:
55   int64_t out_rows_count_;
56 };
57 }  // namespace dataset
58 }  // namespace mindspore
59 
60 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_OPERATOR_CONNECTOR_H_
61