Package madgraph :: Package iolibs :: Module file_writers :: Class CPPWriter
[hide private]
[frames] | no frames]

Class CPPWriter

source code

object --+        
         |        
      file --+    
             |    
    FileWriter --+
                 |
                CPPWriter

Routines for writing C++ lines. Keeps track of brackets, spaces, indentation and splitting of long lines

Nested Classes [hide private]
  CPPWriterError
Exception raised if an error occurs in the definition or the execution of a CPPWriter.

Inherited from FileWriter: FileWriterError

Instance Methods [hide private]
 
write_line(self, line)
Write a C++ line, with correct indent, spacing and line splits
source code
 
write_comment_line(self, line)
Write a comment line, with correct indent and line splits
source code
 
split_line(self, line, split_characters)
Split a line if it is longer than self.line_length columns.
source code
 
split_comment_line(self, line)
Split a line if it is longer than self.line_length columns.
source code

Inherited from FileWriter: __init__, write_comments, writelines

Inherited from file: __delattr__, __enter__, __exit__, __getattribute__, __iter__, __new__, __repr__, __setattr__, close, fileno, flush, isatty, next, read, readinto, readline, readlines, seek, tell, truncate, write, xreadlines

Inherited from object: __format__, __hash__, __reduce__, __reduce_ex__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  standard_indent = 2
  line_cont_indent = 4
  indent_par_keywords = {'^else if': 2, '^for': 2, '^if': 2, '^s...
  indent_single_keywords = {'^else': 2}
  indent_content_keywords = {'^class': 2, '^namespace': 0}
  cont_indent_keywords = {'^case': 2, '^default': 2, '^private':...
  spacing_patterns = [('\\s*"\\s*}', '"'), ('\\s*,\\s*', ', '), ...
  spacing_re = {'([{(,=])\\s*-\\s*': re.compile(r'([\{\(,=])\s*-...
  init_array_pattern = re.compile(r'=\s*\{.*\}')
  short_clause_pattern = re.compile(r'\{.*\}')
  comment_char = '//'
  comment_pattern = re.compile(r'^(\s*#\s+|\s*//)')
  start_comment_pattern = re.compile(r'^(\s*/\*)')
  end_comment_pattern = re.compile(r'(\s*\*/)$')
  quote_chars = re.compile(r'[^\\]["\']|^["\']')
  no_space_comment_patterns = re.compile(r'--|\*\*|==|\+\+')
  line_length = 80
  max_split = 40
  split_characters = ' '
  comment_split_characters = ' '
  __indent = 0
  __keyword_list = deque([])
  __comment_ongoing = False
  key = ('\\s+', ' ')
Properties [hide private]

Inherited from file: closed, encoding, errors, mode, name, newlines, softspace

Inherited from object: __class__

Method Details [hide private]

write_line(self, line)

source code 

Write a C++ line, with correct indent, spacing and line splits

Overrides: FileWriter.write_line

write_comment_line(self, line)

source code 

Write a comment line, with correct indent and line splits

Overrides: FileWriter.write_comment_line

split_line(self, line, split_characters)

source code 

Split a line if it is longer than self.line_length columns. Split in preferential order according to split_characters. Also fix spacing for line.

split_comment_line(self, line)

source code 

Split a line if it is longer than self.line_length columns. Split in preferential order according to split_characters.


Class Variable Details [hide private]

indent_par_keywords

Value:
{'^else if': 2, '^for': 2, '^if': 2, '^switch': 2, '^while': 2}

cont_indent_keywords

Value:
{'^case': 2,
 '^default': 2,
 '^private': 2,
 '^protected': 2,
 '^public': 2}

spacing_patterns

Value:
[('\\s*"\\s*}', '"'),
 ('\\s*,\\s*', ', '),
 ('\\s*-\\s*', ' - '),
 ('([{(,=])\\s*-\\s*', '\\g<1> -'),
 ('(return)\\s*-\\s*', '\\g<1> -'),
 ('\\s*\\+\\s*', ' + '),
 ('([{(,=])\\s*\\+\\s*', '\\g<1> +'),
 ('\\(\\s*', '('),
...

spacing_re

Value:
{'([{(,=])\\s*-\\s*': re.compile(r'([\{\(,=])\s*-\s*'),
 '([{(,=])\\s*\\+\\s*': re.compile(r'([\{\(,=])\s*\+\s*'),
 '(\\d+\\.{0,1}\\d*|\\.\\d+)\\s*[eE]\\s*([+-]{0,1})\\s*(\\d+)': re.com\
pile(r'(\d+\.?\d*|\.\d+)\s*[eE]\s*([\+-]?)\s*(\d+)'),
 '(return)\\s*-\\s*': re.compile(r'(return)\s*-\s*'),
 ';\\s*$}': re.compile(r';\s*$\}'),
 ';\\s*\\}': re.compile(r';\s*\}'),
 '<\\s*double\\s*>>\\s*': re.compile(r'<\s*double\s*>>\s*'),
...