SyFi 0.3
tests/codeformatting/codeformatter.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #from sfc.CodeFormatter import CodeFormatter
00003 from newsfc.codegeneration import CodeFormatter
00004 
00005 facet_dofs = [(2, 0, 1), (5, 3, 4), (6, 7, 8)]
00006 
00007 code = CodeFormatter()
00008 code.begin_switch("facet")
00009 for i, dofs in enumerate(facet_dofs):
00010     code.begin_case(i)
00011     for j, d in enumerate(dofs):
00012         code += "dofs[%d] = %d;" % (j, d)
00013     code.end_case()
00014 code += "default:"
00015 code.indent()
00016 code += 'throw std::runtime_error("Invalid facet number.");'
00017 code.outdent()
00018 code.end_switch()
00019 
00020 code = str(code)
00021 assert code == """switch(facet)
00022 {
00023 case 0:
00024     dofs[0] = 2;
00025     dofs[1] = 0;
00026     dofs[2] = 1;
00027     break;
00028 case 1:
00029     dofs[0] = 5;
00030     dofs[1] = 3;
00031     dofs[2] = 4;
00032     break;
00033 case 2:
00034     dofs[0] = 6;
00035     dofs[1] = 7;
00036     dofs[2] = 8;
00037     break;
00038 default:
00039     throw std::runtime_error("Invalid facet number.");
00040 }"""
00041 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines