/Scripts/Marshall/CAudioStringMarshaller.py
Python | 126 lines | 119 code | 0 blank | 7 comment | 4 complexity | 9b2623c9dd603922ba59907efa53501f MD5 | raw file
Possible License(s): Apache-2.0
- """
- This source file is part of HGamer3D
- (A project to enable 3D game development in Haskell)
- For the latest info, see http://www.althainz.de/HGamer3D.html
-
- (c) 2011 Peter Althainz
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- """
-
- # CAudioStringMarshaller.py
-
- import os, re, sys
- import Config, BasicMarshaller
-
- class CAudioStringMarshaller(BasicMarshaller.BasicMarshaller):
- """
- marshalling of Simple c/Haskell types
-
- Transformation Table for "irrstring" Types:
- ----------------------------------------
-
- ----------------+--------+-----------+------------------------------------------------------+-------+------------------------------------------+
- cpp-type + In/Out + x_ctype + CtoCpp + vcpm + CpptoC +
- ----------------+--------+-----------+------------------------------------------------------+-------+------------------------------------------+
- base | In | ctype* | base name_cpp = *((const base * const) in_name_c); | - | - |
- const base & | In | ctype* | base name_cpp = *((const base * const) in_name_c); | - | - |
- ----------------+--------+-----------+------------------------------------------------------+-------+------------------------------------------+
-
- x_type is in/out c-type
- """
-
- def getPossibleModifications(self):
- """string types currently support only in (plain and constref) and constref out"""
- return {
- # const, ref, pointer, doublepointer
- "plain" : (False, False, False, False), # input struct only
- "constref" : (True, True, False, False), # input const ref struct
- }
-
- #
- # here are coming the marshalling routines
- #
-
-
- def vcpm(self):
- """
- modifier before the variable name, for the invocation of the function,
- depends on the difference between the parameter type and the variable
- type.
- """
- return ""
-
-
- def ctype(self, overwriteIsOut):
- """
- type for C-function declaration,
- overwriteIsOut: the parameter is an out parameter, independent
- of the mod function (its a function return value)
- """
- return "char *"
-
- def fromCtoCpp(self, cname, cppname, overwriteOut):
- """
- returns lines of code, to create a cpp variable, transform the
- input C value to this type. If it is a out variable, transformation
- of input variable not needed, but creation of cpp variable still needed.
- overwriteOut: if True, this is a out variable, independent of self.mod
- """
- if overwriteOut:
- if self.mod != "constref" and self.mod != "plain":
- print "overwriteOut for irrstring type", self.cpptype()
- sys.exit(-1)
-
- if overwriteOut and self.mod == "constref":
- return self.baseType + " " + cppname + ";\n"
- else:
- return self.baseType + " " + cppname + " = cAudioString((const char* const) " + cname + ");\n"
-
- def fromCpptoC(self, cname, cppname, overwriteOut):
- """
- returns lines of code, to transform the cpp value to the output
- c value, only needed in case of out variable.
- overwriteOut: if True, this is a out variable, independent of self.mod
- """
- if overwriteOut:
- if self.mod != "constref" and self.mod != "plain":
- print "overwriteOut for caudiostring type", self.cpptype()
- sys.exit(-1)
-
- if overwriteOut and (self.mod == "plain" or self.mod == "constref"):
- outtext = "if (strlen( (char *) " + cppname + ".c_str()) < (1024 * 64 - 1)) { \n"
- # outtext = "if (strlen( (char *) toWINSTR(" + cppname + ".c_str())) < (1024 * 64 - 1)) { \n"
- outtext = outtext + "strcpy(" + cname + ", (char *) " + cppname + ".c_str()); } else {\n"
- outtext = outtext + "strcpy(" + cname + ", \"error: outstring larger then 64k\");};\n"
- return outtext
- else:
- return ""
-
- def chsFuncDefinition(self, overwriteOut):
- if overwriteOut:
- if self.mod != "constref" and self.mod != "plain":
- print "overwriteOut for ogrestring type", self.cpptype()
- sys.exit(-1)
-
- """provides the marshalling string within the C2HS func definition"""
- conf = self.typeConfig
-
- if overwriteOut and self.mod == "plain":
- return "alloc64k- `" + conf.getProp("htype") + "' " + conf.getProp("outmarsh") + "*"
- elif overwriteOut and self.mod == "constref":
- return "alloc64k- `" + conf.getProp("htype") + "' " + conf.getProp("outmarsh") + "*"
- else:
- return conf.getProp("inmarsh") + "* `" + conf.getProp("htype") + "' "
-
-