Shadowrun: Awakened 29 September 2011 - Build 871
CppWrapperSetRoutine.cs
Go to the documentation of this file.
00001 using System;
00002 using System.Collections.Generic;
00003 using System.Linq;
00004 using System.Text;
00005 
00006 namespace RoutineAnalyzer
00007 {
00008     class CppWrapperSetRoutine : RoutineBase
00009     {
00010         public CppWrapperSetRoutine(string sql)
00011             : base(sql)
00012         {
00013         }
00014 
00015         public override string GetDeclaration()
00016         {
00017             StringBuilder builder = new StringBuilder();
00018             builder.Append("__declspec(dllexport) void ");
00019             builder.Append(ParseHelper.ConvertUnderscoreToCamelCase(_name));
00020             builder.Append("(");
00021             foreach (RoutineParamBase param in _params)
00022             {
00023                 builder.Append(param.GetDeclaration());
00024                 if (param != _params.Last<RoutineParamBase>())
00025                     builder.Append(", ");
00026             }
00027 
00028             builder.Append(")");
00029             return builder.ToString();
00030         }
00031 
00032         public override string GetCode()
00033         {
00034             //build the start of the function
00035             StringBuilder builder = new StringBuilder();
00036             builder.AppendLine(GetDeclaration());
00037             builder.AppendLine("{");
00038 
00039             //before calling the C++ implementation, we may need to convert parameters
00040             foreach (RoutineParamBase param in _params)
00041             {
00042                 string preExecCode = param.GetPreExecuteCode();
00043                 if (!string.IsNullOrEmpty(preExecCode))
00044                     builder.AppendLine(preExecCode);
00045             }
00046 
00047             //build a call to the C++ implementation, including each parameter
00048             builder.Append(ParseHelper.ConvertUnderscoreToCamelCase(_name));
00049             builder.Append("(");
00050             foreach (RoutineParamBase param in _params)
00051             {
00052                 builder.Append(param.GetParameter());
00053                 if (_params.IndexOf(param) < _params.Count - 1)
00054                     builder.Append(",");
00055             }
00056             builder.AppendLine(");");
00057 
00058             //after calling the C++ implementation, we may need to convert return parameters
00059             //before calling the C++ implementation, we may need to convert parameters
00060             foreach (RoutineParamBase param in _params)
00061             {
00062                 string preExecCode = param.GetPreExecuteCode();
00063                 if (!string.IsNullOrEmpty(preExecCode))
00064                     builder.AppendLine(preExecCode);
00065             }
00066 
00067             //close up the function and return it
00068             builder.AppendLine("}");
00069             return builder.ToString();
00070         }
00071 
00072         protected override RoutineParamBase CreateRoutineParam(string sql, int index)
00073         {
00074             return new CppWrapperSetRoutineParam(sql, index);
00075         }
00076     }
00077 }

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net