PageRenderTime 83ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Scripts/Marshall/CAudioStringMarshaller.py

https://code.google.com/p/hgamer3d/
Python | 126 lines | 119 code | 0 blank | 7 comment | 4 complexity | 9b2623c9dd603922ba59907efa53501f MD5 | raw file
Possible License(s): Apache-2.0
  1. """
  2. This source file is part of HGamer3D
  3. (A project to enable 3D game development in Haskell)
  4. For the latest info, see http://www.althainz.de/HGamer3D.html
  5. (c) 2011 Peter Althainz
  6. Licensed under the Apache License, Version 2.0 (the "License");
  7. you may not use this file except in compliance with the License.
  8. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. """
  16. # CAudioStringMarshaller.py
  17. import os, re, sys
  18. import Config, BasicMarshaller
  19. class CAudioStringMarshaller(BasicMarshaller.BasicMarshaller):
  20. """
  21. marshalling of Simple c/Haskell types
  22. Transformation Table for "irrstring" Types:
  23. ----------------------------------------
  24. ----------------+--------+-----------+------------------------------------------------------+-------+------------------------------------------+
  25. cpp-type + In/Out + x_ctype + CtoCpp + vcpm + CpptoC +
  26. ----------------+--------+-----------+------------------------------------------------------+-------+------------------------------------------+
  27. base | In | ctype* | base name_cpp = *((const base * const) in_name_c); | - | - |
  28. const base & | In | ctype* | base name_cpp = *((const base * const) in_name_c); | - | - |
  29. ----------------+--------+-----------+------------------------------------------------------+-------+------------------------------------------+
  30. x_type is in/out c-type
  31. """
  32. def getPossibleModifications(self):
  33. """string types currently support only in (plain and constref) and constref out"""
  34. return {
  35. # const, ref, pointer, doublepointer
  36. "plain" : (False, False, False, False), # input struct only
  37. "constref" : (True, True, False, False), # input const ref struct
  38. }
  39. #
  40. # here are coming the marshalling routines
  41. #
  42. def vcpm(self):
  43. """
  44. modifier before the variable name, for the invocation of the function,
  45. depends on the difference between the parameter type and the variable
  46. type.
  47. """
  48. return ""
  49. def ctype(self, overwriteIsOut):
  50. """
  51. type for C-function declaration,
  52. overwriteIsOut: the parameter is an out parameter, independent
  53. of the mod function (its a function return value)
  54. """
  55. return "char *"
  56. def fromCtoCpp(self, cname, cppname, overwriteOut):
  57. """
  58. returns lines of code, to create a cpp variable, transform the
  59. input C value to this type. If it is a out variable, transformation
  60. of input variable not needed, but creation of cpp variable still needed.
  61. overwriteOut: if True, this is a out variable, independent of self.mod
  62. """
  63. if overwriteOut:
  64. if self.mod != "constref" and self.mod != "plain":
  65. print "overwriteOut for irrstring type", self.cpptype()
  66. sys.exit(-1)
  67. if overwriteOut and self.mod == "constref":
  68. return self.baseType + " " + cppname + ";\n"
  69. else:
  70. return self.baseType + " " + cppname + " = cAudioString((const char* const) " + cname + ");\n"
  71. def fromCpptoC(self, cname, cppname, overwriteOut):
  72. """
  73. returns lines of code, to transform the cpp value to the output
  74. c value, only needed in case of out variable.
  75. overwriteOut: if True, this is a out variable, independent of self.mod
  76. """
  77. if overwriteOut:
  78. if self.mod != "constref" and self.mod != "plain":
  79. print "overwriteOut for caudiostring type", self.cpptype()
  80. sys.exit(-1)
  81. if overwriteOut and (self.mod == "plain" or self.mod == "constref"):
  82. outtext = "if (strlen( (char *) " + cppname + ".c_str()) < (1024 * 64 - 1)) { \n"
  83. # outtext = "if (strlen( (char *) toWINSTR(" + cppname + ".c_str())) < (1024 * 64 - 1)) { \n"
  84. outtext = outtext + "strcpy(" + cname + ", (char *) " + cppname + ".c_str()); } else {\n"
  85. outtext = outtext + "strcpy(" + cname + ", \"error: outstring larger then 64k\");};\n"
  86. return outtext
  87. else:
  88. return ""
  89. def chsFuncDefinition(self, overwriteOut):
  90. if overwriteOut:
  91. if self.mod != "constref" and self.mod != "plain":
  92. print "overwriteOut for ogrestring type", self.cpptype()
  93. sys.exit(-1)
  94. """provides the marshalling string within the C2HS func definition"""
  95. conf = self.typeConfig
  96. if overwriteOut and self.mod == "plain":
  97. return "alloc64k- `" + conf.getProp("htype") + "' " + conf.getProp("outmarsh") + "*"
  98. elif overwriteOut and self.mod == "constref":
  99. return "alloc64k- `" + conf.getProp("htype") + "' " + conf.getProp("outmarsh") + "*"
  100. else:
  101. return conf.getProp("inmarsh") + "* `" + conf.getProp("htype") + "' "