Open3D (C++ API)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
docstring.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include <string>
30 #include <unordered_map>
31 
32 #include "pybind/open3d_pybind.h"
33 
34 namespace open3d {
35 namespace docstring {
36 
37 class ArgumentDoc {
38 public:
39  std::string name_ = "";
40  std::string type_ = "";
41  std::string default_ = "";
42  // Long default values are not displayed in signature, but in docstrings
43  std::string long_default_ = "";
44  std::string body_ = "";
45 };
46 
81 class FunctionDoc {
82 public:
83  FunctionDoc(const std::string& pybind_doc);
84 
86  std::string ToGoogleDocString() const;
87 
89  static std::string NamespaceFix(const std::string& s);
90 
91 protected:
93  void ParseFunctionName();
94 
96  void ParseSummary();
97 
99  void ParseArguments();
100 
102  void ParseReturn();
103 
106  static std::vector<std::string> GetArgumentTokens(
107  const std::string& pybind_doc);
108 
110  static ArgumentDoc ParseArgumentToken(const std::string& argument_token);
111 
113  static std::string StringCleanAll(std::string& s,
114  const std::string& white_space = " \t\n");
115 
116 public:
117  std::string name_ = "";
118  std::vector<ArgumentDoc> argument_docs_;
120  std::string summary_ = "";
121  std::string body_ = "";
122 
123 protected:
124  std::string pybind_doc_ = "";
125 };
126 
129 void FunctionDocInject(
130  py::module& pybind_module,
131  const std::string& function_name,
132  const std::unordered_map<std::string, std::string>& map_parameter_docs =
133  std::unordered_map<std::string, std::string>());
134 
138  py::module& pybind_module,
139  const std::string& class_name,
140  const std::string& function_name,
141  const std::unordered_map<std::string, std::string>&
142  map_parameter_body_docs =
143  std::unordered_map<std::string, std::string>());
144 
145 extern py::handle static_property;
146 
147 } // namespace docstring
148 } // namespace open3d
std::string default_
Definition: docstring.h:41
std::string body_
Definition: docstring.h:44
Definition: docstring.h:81
std::string long_default_
Definition: docstring.h:43
py::handle static_property
Definition: docstring.cpp:42
std::string type_
Definition: docstring.h:40
void ClassMethodDocInject(py::module &pybind_module, const std::string &class_name, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:45
void FunctionDocInject(py::module &pybind_module, const std::string &function_name, const std::unordered_map< std::string, std::string > &map_parameter_body_docs)
Definition: docstring.cpp:110
std::vector< ArgumentDoc > argument_docs_
Definition: docstring.h:118
Definition: Open3DViewer.h:29
ArgumentDoc return_doc_
Definition: docstring.h:119
std::string name_
Definition: docstring.h:39
Definition: docstring.h:37