| 67 | public: |
| 68 | // Options for adding a Node to a Graph. |
| 69 | class Options { |
| 70 | public: |
| 71 | // Sets the Graph (that Nodes will be added to) and the status. The |
| 72 | // status may be set to nullptr, in which case errors cause CHECK |
| 73 | // failures. The graph and status must outlive *this. |
| 74 | Options(Graph* graph, Status* status); |
| 75 | ~Options(); |
| 76 | |
| 77 | // Methods for setting options. These are const methods: they |
| 78 | // return a copy of *this with the option set. |
| 79 | Options WithName(StringPiece name) const; |
| 80 | Options WithDevice(StringPiece device) const; |
| 81 | Options WithControlInput(Node* control_input) const; |
| 82 | Options WithControlInputs(gtl::ArraySlice<Node*> control_inputs) const; |
| 83 | |
| 84 | // Override the default value for an optional attr. |
| 85 | template <class T> |
| 86 | Options WithAttr(StringPiece attr_name, T&& value) const { |
| 87 | return Options(*this).WithAttrImpl(attr_name, std::forward<T>(value)); |
| 88 | } |
| 89 | // Note: overload needed to allow {...} expressions for value. |
| 90 | template <class T> |
| 91 | Options WithAttr(StringPiece attr_name, |
| 92 | std::initializer_list<T> value) const { |
| 93 | return WithAttr<std::initializer_list<T>>(attr_name, std::move(value)); |
| 94 | } |
| 95 | |
| 96 | // Methods for using options from a function that creates a Node. |
| 97 | |
| 98 | // Returns true if the status associated with *this has an error. |
| 99 | // Use this to skip processing that may depend on prior results. |
| 100 | bool HaveError() const { return status_ != nullptr && !status_->ok(); } |
| 101 | |
| 102 | // Returns a string representation of the status associated with *this. |
| 103 | // Returns the string `"OK"` if the status doesn't have any error. |
| 104 | string StatusToString() const { return status_->ToString(); } |
| 105 | |
| 106 | // Given the Op type name, return a name for a node of that type. |
| 107 | // Uses the value set in WithName() if that has been called. Otherwise, |
| 108 | // returns a name built out of the Op type name. |
| 109 | string GetNameForOp(StringPiece op) const; |
| 110 | |
| 111 | // Sets the device, adds control inputs, adds attrs, and calls Finalize(). |
| 112 | // If Finalize returns an error, it is saved and this function returns |
| 113 | // nullptr. |
| 114 | Node* FinalizeBuilder(NodeBuilder* builder) const; |
| 115 | |
| 116 | // Updates the associated status, if any, or calls TF_CHECK_OK if none. |
| 117 | void UpdateStatus(const Status& status) const; |
| 118 | |
| 119 | // Accessor |
| 120 | const OpRegistryInterface* op_registry() const { |
| 121 | return graph_->op_registry(); |
| 122 | } |
| 123 | |
| 124 | private: |
| 125 | Options WithNameImpl(StringPiece name); |
| 126 | Options WithDeviceImpl(StringPiece device); |
no outgoing calls
no test coverage detected