1#This file is distributed under the terms of
2#the GNU Lesser General Public license (See the file COPYING for details).
3#Copyright (C) 2000 Stefanus Du Toit and Aloril
4#Copyright (C) 2001-2004 Alistair Riddoch
5
6__revision__ = '$Id$'
7
8import sys, os
9try:
10    import filecmp
11    filecmp = filecmp.cmp
12except ImportError:
13    import cmp
14    filecmp = cmp.cmp
15sys.path.append("../../Atlas-Python")
16from atlas import *
17from atlas.codecs import *
18
19def deb(): import pdb; pdb.pm()
20
21copyright_template = \
22"""// This file may be redistributed and modified only under the terms of
23// the GNU Lesser General Public License (See COPYING for details).
24// Copyright 2000-2001 %s.
25// Copyright 2001-2005 %s.
26// Automatically generated using gen_cpp.py.
27"""
28
29copyright = copyright_template % ("Stefanus Du Toit and Aloril", "Alistair Riddoch")
30
31#objects that will have static attributes
32static_objects = ["root", "root_entity", "root_operation"]
33
34# These are only used for description.
35descr_attrs = ['children', 'description', 'args_description', 'example', \
36               'long_description', 'specification', 'specification_file', \
37               'stamp_inherit', 'interface', 'time_string']
38
39# C++ equivalents of atlas types
40cpp_type = {'map' : 'Atlas::Message::MapType',
41            'list' : 'Atlas::Message::ListType',
42            'string' : 'std::string',
43            'int' : 'long',
44            'float' : 'double',
45            'RootList' : 'std::vector<Root>',
46            'string_list' : 'std::list<std::string>',
47            'int_list' : 'std::list<long>',
48            'float_list' : 'std::list<double>',
49            'string_list_length' : 'std::vector<std::string>',
50            'int_list_length' : 'std::vector<long>',
51            'float_list_length' : 'std::vector<double>'}
52
53# Const references
54cpp_param_type = {'map' : 'const ' + cpp_type['map'] + '&',
55                  'list' : 'const ' + cpp_type['list'] + '&',
56                  'string' : 'const ' + cpp_type['string'] + '&',
57                  'int' : cpp_type['int'],
58                  'float' : cpp_type['float'],
59                  'RootList' : 'const ' + cpp_type['RootList'] + '&',
60                  'string_list' : 'const ' + cpp_type['string_list'] + '&',
61                  'int_list' : 'const ' + cpp_type['int_list'] + '&',
62                  'float_list' : 'const ' + cpp_type['float_list'] + '&',
63                  'string_list_length' : 'const ' + cpp_type['string_list_length'] + '&',
64                  'int_list_length' : 'const ' + cpp_type['int_list_length'] + '&',
65                  'float_list_length' : 'const ' + cpp_type['float_list_length'] + '&'}
66
67# Non-const references
68cpp_param_type2 = {'map' : cpp_type['map'] + '&',
69                  'list' : cpp_type['list'] + '&',
70                  'string' : cpp_type['string'] + '&',
71                  'int' : cpp_type['int'] + '&',
72                  'float' : cpp_type['float'] + '&',
73                  'RootList' : cpp_type['RootList'] + '&',
74                  'string_list' : cpp_type['string_list'] + '&',
75                  'int_list' : cpp_type['int_list'] + '&',
76                  'float_list' : cpp_type['float_list'] + '&',
77                  'string_list_length' : cpp_type['string_list_length'] + '&',
78                  'int_list_length' : cpp_type['int_list_length'] + '&',
79                  'float_list_length' : cpp_type['float_list_length'] + '&'}
80
81def capitalize_only(str):
82    return string.upper(str[:1]) + str[1:]
83
84# Turns some_thing into SomeThing
85def classize(id, data=0):
86    if type(id)!=StringType: id = id.id
87    cid = string.join( map(capitalize_only, string.split(id, '_') ), "")
88    if data: return cid + "Data"
89    return cid
90
91def doc(indent, text):
92    return " " * indent + "/// %s\n" % text
93
94def find_in_parents(obj, attr_name):
95    for parent in obj.parents:
96        if hasattr(parent, attr_name):
97            return parent
98    return None
99
100