2 from __future__
import print_function
9 r = re.compile(
r"([_\/:][a-z]|[_\/:][0-9])")
12 tokens = r.split(name, 1)
15 if tokens[1][0] ==
"_":
19 + tokens[0][1:].lower()
20 + tokens[1][1].upper()
23 ret += tokens[0].lower() + tokens[1][1].upper()
28 + tokens[0][1:].lower()
30 + tokens[1][1].upper()
33 ret += tokens[0].lower() + tokens[1][0] + tokens[1][1].upper()
34 tokens = r.split(tokens[2], 1)
38 ret += tokens[0][0].upper() + tokens[0][1:].lower() + tokens[1][0]
40 ret += tokens[0][0].upper() + tokens[0][1:].lower()
42 ret += tokens[0].lower()
48 r = re.compile(
r"([A-Za-z][0-9]|[0-9][A-z]|[a-z][A-Z]|[A-Z][A-Z][a-z]|[_\/:][A-z])")
50 tokens = r.split(name, 1)
55 or tokens[1][0] ==
":" 56 or tokens[1][0] ==
"_" 57 or tokens[1][1] ==
"_" 59 ret += tokens[0].lower() + tokens[1][0].lower() + tokens[1][1:].lower()
63 + tokens[1][0].lower()
65 + tokens[1][1:].lower()
67 tokens = r.split(tokens[2], 1)
69 ret += tokens[0].lower()
77 print(*args, file=sys.stderr, **kwargs)
81 sys.stderr.write(msg +
"\n")
99 ret +=
",\n " + (d[
"Name"]) +
"(_" + (d[
"Name"]) +
") " 104 if data[
"Value"]
is None:
106 elif data[
"Value"] ==
"{}":
113 if data[
"Value"] ==
None:
116 return " = " + data[
"Value"]
129 if "Required" in d
and not d[
"Required"]:
142 if "Required" in data:
143 return " " + data[
"Type"] +
" " + (data[
"Name"]) +
";\n" 150 if type_in ==
"std::string":
151 return "boost::any_cast<" + type_in +
">(prop.Get())" 152 elif type_in ==
"exotica::Initializer" or type_in ==
"Initializer":
153 return "prop.IsInitializerVectorType()?boost::any_cast<std::vector<exotica::Initializer>>(prop.Get()).at(0):boost::any_cast<exotica::Initializer>(prop.Get())" 155 type_in ==
"std::vector<Initializer>" 156 or type_in ==
"std::vector<exotica::Initializer>" 158 return "boost::any_cast<std::vector<exotica::Initializer>>(prop.Get())" 159 elif type_in ==
"Eigen::VectorXd":
160 parser =
"ParseVector<double,Eigen::Dynamic>" 161 elif type_in ==
"Eigen::Vector4d":
162 parser =
"ParseVector<double,4>" 163 elif type_in ==
"Eigen::Vector3d":
164 parser =
"ParseVector<double,3>" 165 elif type_in ==
"Eigen::Vector2d":
166 parser =
"ParseVector<double,2>" 167 elif type_in ==
"Eigen::VectorXi":
168 parser =
"ParseVector<int,Eigen::Dynamic>" 169 elif type_in ==
"bool":
171 elif type_in ==
"double":
172 parser =
"ParseDouble" 173 elif type_in ==
"int":
175 elif type_in ==
"std::vector<std::string>":
177 elif type_in ==
"std::vector<int>":
178 parser =
"ParseIntList" 179 elif type_in ==
"std::vector<bool>":
180 parser =
"ParseBoolList" 182 eprint(
"Unknown data type '" + type_in +
"'")
186 "prop.IsStringType()?" 188 +
"(boost::any_cast<std::string>(prop.Get())):boost::any_cast<" 195 if "Required" in data:
197 ' ret.properties_.emplace("' 212 if "Required" in data:
214 ' if (other.HasProperty("' 216 +
'")) { const Property& prop = other.properties_.at("' 218 +
'"); if(prop.IsSet()) {' 229 if "Required" in data
and data[
"Required"]:
231 ' if(!other.HasProperty("' 233 +
'") || !other.properties_.at("' 235 +
'").IsSet()) ThrowPretty("Initializer ' 237 +
" requires property " 245 def construct(namespace, class_name_orig, data, include):
246 class_name = class_name_orig +
"Initializer" 248 """// This file was automatically generated. Do not edit this file! 249 #ifndef INITIALIZER_""" 254 #define INITIALIZER_""" 260 #include <exotica_core/property.h> 264 inline std::vector<Initializer> Get""" 274 +
" : public InitializerBase" 278 static std::string GetContainerName() { return """ 289 +
"() : InitializerBase()" 301 +
") : InitializerBase()" 309 +
"""(const Initializer& other) : """ 326 virtual Initializer GetTemplate() const 328 return (Initializer)""" 333 virtual std::vector<Initializer> GetAllTemplates() const 340 virtual void Check(const Initializer& other) const 345 ret +=
check(d, class_name)
348 operator Initializer() 350 Initializer ret(GetContainerName()); 354 ret +=
""" return ret; 370 +
"""_initializers_numerator.h> 375 ret +=
"#include <" + i +
".h>\n" 383 if line.startswith(
"//"):
386 last = line.find(
";")
388 line = line[0:last].strip()
390 last = line.find(
"//")
392 line = line[0:last].strip()
399 if line.startswith(
"include"):
401 "Include": line[7:].strip().strip(
">").strip(
"<").strip(
'"'),
402 "Code": line.strip(),
404 if line.startswith(
"extend"):
406 "Extends": line[6:].strip().strip(
">").strip(
"<").strip(
'"'),
407 "Code": line.strip(),
409 if line.startswith(
"class"):
411 "ClassName": line[5:].strip().strip(
">").strip(
"<").strip(
'"'),
412 "Code": line.strip(),
416 eprint(
"Can't find ';' in '" + function_name +
"', on line " + str(line_number))
420 if line.startswith(
"Required"):
422 elif line.startswith(
"Optional"):
426 "Can't parse 'Required/Optional' tag in '" 438 has_default_arg =
not (eq == -1)
440 value = line[eq + 1 : last]
444 name_start = line[0:eq].strip().rfind(
" ")
445 name = line[name_start:eq].strip()
446 field_type = line[9:name_start].strip()
447 if not has_default_arg:
448 eprint(
"Optional parameter '" + name +
"' requires a default argument!")
450 name_start = line[0:last].strip().rfind(
" ")
451 name = line[name_start:last].strip()
452 field_type = line[9:name_start].strip()
454 return {
"Required": required,
"Type": field_type,
"Name": name,
"Value": value}
458 with open(file_name)
as f:
459 lines = f.readlines()
471 if d[
"Required"] ==
False:
476 "Required properties_ have to come before Optional ones, in '" 484 include.append(d[
"Include"])
486 extends.append(d[
"Extends"])
488 names.append(d[
"ClassName"])
490 eprint(
"Could not parse initializer class name in '" + file_name +
"'!")
493 return {
"Data": data,
"Include": include,
"Extends": extends,
"ClassName": names[0]}
498 if d[
"Type"] == type_name
and d[
"Name"] == name:
519 class_name = file_content[
"ClassName"]
520 if "Extends" in file_content:
521 for e
in file_content[
"Extends"]:
525 for d
in search_dirs:
526 ff = d +
"/share/" + ext[0] +
"/init/" + ext[1] +
".in" 527 if os.path.isfile(ff):
531 eprint(
"Cannot find extension '" + e +
"'!")
532 content[
"Extends"].append(e)
535 if "Data" in file_content:
536 for d
in file_content[
"Data"]:
539 for e
in content[
"Data"]:
540 if e[
"Name"] == d[
"Name"]:
541 e[
"Value"] = d[
"Value"]
543 d[
"Class"] = class_name
544 content[
"Data"].append(d)
545 if "Include" in file_content:
546 for i
in file_content[
"Include"]:
548 content[
"Include"].append(i)
550 content[
"ClassName"] = class_name
565 def generate(input_files, output_files, namespace, search_dirs, devel_dir):
566 print(
"Generating " + output_files)
568 input_files, search_dirs, {
"Data": [],
"Include": [],
"Extends": []}
571 namespace, content[
"ClassName"],
sort_data(content[
"Data"]), content[
"Include"]
573 path = os.path.dirname(output_files)
574 if not os.path.exists(path):
576 with open(output_files,
"w")
as f:
578 return content[
"ClassName"]
583 """// This file was automatically generated. Do not edit this file! 584 #ifndef INITIALIZE_PROJECT_HEADER_""" 587 #define INITIALIZE_PROJECT_HEADER_""" 591 #include <exotica_core/property.h> 594 for init
in class_inits:
595 ret +=
"#include <" + namespace +
"/" + init[0] +
"_initializer.h>\n" 602 inline std::vector<Initializer> Get""" 606 std::vector<Initializer> ret; 609 for init
in class_inits:
610 ret +=
" ret.push_back(" + init[1] +
"Initializer().GetTemplate());\n" 611 ret +=
""" return ret; 618 path = os.path.dirname(file_name)
619 if not os.path.exists(path):
621 with open(file_name,
"w")
as f:
625 if __name__ ==
"__main__":
626 if len(sys.argv) > 5:
628 n = int((len(sys.argv) - offset) / 2)
629 namespace = sys.argv[1]
630 search_dirs = sys.argv[2].split(
":")
631 devel_dir = sys.argv[3]
632 class_inits_header_file = sys.argv[4]
633 if not os.path.exists(devel_dir +
"/init"):
634 os.makedirs(devel_dir +
"/init")
636 for i
in range(0, n):
637 input_files = sys.argv[offset + i]
638 class_name = os.path.basename(sys.argv[offset + i][0:-3])
639 with open(input_files,
"r") as fi: 640 with open(devel_dir + "/init/" + class_name +
".in",
"w")
as f:
644 for i
in range(0, n):
645 input_files = sys.argv[offset + i]
646 output_files = sys.argv[offset + n + i]
647 class_file_name = os.path.basename(sys.argv[offset + i][0:-3])
652 input_files, output_files, namespace, search_dirs, devel_dir
659 eprint(
"Initializer generation failure: invalid arguments!")
def constructor_list(data)
def create_class_init_header(class_inits, file_name)
def contains_extends(name, list_in)
def parse_file(file_name)
def collect_extensions(input_files, search_dirs, content)
def default_constructor_list(data)
def generate(input_files, output_files, namespace, search_dirs, devel_dir)
def construct(namespace, class_name_orig, data, include)
def constructor_argument_list(data)
def contains_include(name, list_in)
def parse_line(line, line_number, function_name)
def contains_data(type_name, name, list_in)
def to_underscores(name, num_pass=0)
def default_argument_value(data)
def needs_default_constructor(data)