Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Profiling
- {
- class Generator
- {
- public static string GenerateDeclarations()
- {
- var structOrClass = new StringBuilder();
- var value = new StringBuilder();
- for (int i = 0; i < Constants.FieldCounts.Count; i++)
- {
- var elementOfField = Constants.FieldCounts.ElementAt(i);
- for (int j = elementOfField/2; j < elementOfField; j++)
- {
- value.Append("byte Value" + j + ';');
- }
- structOrClass.Append("struct S" + elementOfField + "{" + value + "}");
- structOrClass.Append("class C" + elementOfField + "{" + value + "}");
- }
- return structOrClass.ToString();
- }
- public static void MethodsForClassAndStruct(StringBuilder arrayRuner, int i)
- {
- var elementOfField = Constants.FieldCounts.ElementAt(i);
- arrayRuner.Append("\nvoid PC" + elementOfField + "()\n");
- arrayRuner.Append("{\n\tvar array = new C" + elementOfField + "[Constants.ArraySize];\n");
- arrayRuner.Append("\tfor (int i = 0; i < Constants.ArraySize; i++) array[i] = new C" +
- elementOfField + "();\n}\n");
- arrayRuner.Append("\nvoid PS" + elementOfField + "()\n");
- arrayRuner.Append("{\n\tvar array = new S" + elementOfField + "[Constants.ArraySize];\n}\n");
- }
- public static string GenerateArrayRunner()
- {
- var arrayRuner = new StringBuilder();
- arrayRuner.Append("public class ArrayRunner : IRunner\n{");
- for (int i = 0; i < Constants.FieldCounts.Count; i++)
- {
- MethodsForClassAndStruct(arrayRuner, i);
- }
- arrayRuner.Append("public void Call(bool isClass, int size, int count)\n{\n");
- for (int i = 0; i < Constants.FieldCounts.Count; i++)
- {
- var elementOfField = Constants.FieldCounts.ElementAt(i);
- arrayRuner.Append("if (isClass && size == " + elementOfField + ")\n{\n\tfor (int i = 0; i < count; i++) PC" +
- elementOfField + "(); \nreturn;}\n");
- arrayRuner.Append("if (!isClass && size == " + elementOfField + ")\n{\n\tfor (int i = 0; i < count; i++) PS" +
- elementOfField + "(); \nreturn;}\n");
- }
- arrayRuner.Append("throw new ArgumentException();\n}\n}\n");
- return arrayRuner.ToString();
- }
- public static void Call(StringBuilder callRunner, int i)
- {
- var elementOfField = Constants.FieldCounts.ElementAt(i);
- callRunner.Append("if (isClass && size == " + elementOfField + ")\n{\n");
- callRunner.Append("var o = new C" + elementOfField + "(); for (int i = 0; i < count; i++) PC" +
- elementOfField + "(o); \nreturn;\n}\n");
- callRunner.Append("if (!isClass && size == " + elementOfField + ")\n{\n");
- callRunner.Append("var o = new S" + elementOfField + "(); for (int i = 0; i < count; i++) PS" +
- elementOfField + "(o); \nreturn;\n}\n");
- }
- public static string GenerateCallRunner()
- {
- var callRunner = new StringBuilder();
- callRunner.Append("public class CallRunner : IRunner\n{\n");
- for (int i = 0; i < Constants.FieldCounts.Count; i++)
- {
- var elementOfField = Constants.FieldCounts.ElementAt(i);
- callRunner.Append("void PC" + elementOfField + "(C" + elementOfField + " o) { }\n");
- callRunner.Append("void PS" + elementOfField + "(S" + elementOfField + " o) { }\n");
- }
- callRunner.Append("public void Call(bool isClass, int size, int count)\n{\n");
- for (int i = 0; i < Constants.FieldCounts.Count; i++)
- {
- Call(callRunner, i);
- }
- callRunner.Append("throw new ArgumentException();\n}\n}\n");
- return callRunner.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement