public APINode Search(string text) { if (Name.ToLower().Trim().Contains(text)) { return(this); } foreach (APINode nd in Children) { APINode n = nd.Search(text); if (n != null) { return(n); } } return(null); }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("BindingGenerator - Copyright (C) 2015 JSandusky"); Console.WriteLine(" Purpose: Generates C++/CLI binding classes based on dox attributes data"); Console.WriteLine(" Basic: BindingGenerator OutputDirectory"); Console.WriteLine(" AS: BindingGenerator OutputDirectory InputDir"); return; } if (args.Length == 2) { ASFromXML.Process(args[0], args[1]); //List<string> desired = new List<string>(); //List<ClassInfo> classes = new List<ClassInfo>(); //List<EnumData> enums = new List<EnumData>(); //foreach (string file in System.IO.Directory.EnumerateFiles(args[1])) //{ // if (file.EndsWith("API.cpp")) // { // ASBindingScanner.ScanFile(file, desired, classes, enums); // } //} //foreach (ClassInfo ci in classes) //{ // TypeWriter.WriteClass(args[0], ci); //} // //TypeWriter.WriteEnums(System.IO.Path.Combine(args[0], "Enumerations.h"), enums); } else { APIDocumentation docs = new APIDocumentation(); APINode node = docs.DocumentNode.Children.FirstOrDefault(p => p.Name.Equals("Attribute list")); foreach (APINode clazz in node.Children) { if (clazz.Name.Equals("Node") || clazz.Name.Equals("Scene") || clazz.Name.Equals("UIElement")) { continue; } string code = String.Format(FRONT_SOURCE, clazz.Name); foreach (APILeaf attr in clazz.Children) { string spacelessName = attr.Name.Replace(" ", ""); spacelessName = spacelessName.Substring(0, spacelessName.IndexOf(':')); spacelessName = spacelessName.Replace("-", ""); spacelessName = spacelessName.Replace("/", ""); spacelessName = spacelessName.Replace(".", ""); // If our attribute name collides with our classname, append the last character in repetition // in order to resolve the name collision: ie. the "Text" attribute of "Text" class is exposed as "Textt" // UI hopefully refers to the UAttribute attribute for the correct display name to avoid displaying the minor typographical error if (spacelessName.Equals(clazz.Name)) { spacelessName += spacelessName.Last(); } string trimmedName = attr.Name.Substring(0, attr.Name.IndexOf(':') - 1); string attrCode = String.Format(ATTR_ANNOTE, trimmedName); string appendCode = String.Format(ATTR_SOURCE, ConvertTypeName(attr.TypeAnnote), spacelessName, trimmedName, ConvertTypeFuncName(attr.TypeAnnote)); code += attrCode; code += appendCode; } code += BACK_SOURCE; System.IO.File.WriteAllText(System.IO.Path.Combine(args[0], clazz.Name + ".h"), code); } System.IO.File.WriteAllText(System.IO.Path.Combine(args[0], "ComponentCast.h"), CAST_HEADER); string convertCode = CAST_SOURCE_FILE_BEGIN; foreach (APINode clazz in node.Children) { if (clazz.Name.Equals("Node") || clazz.Name.Equals("Scene") || clazz.Name.Equals("UIElement")) { continue; } convertCode += "#include \"" + clazz.Name + ".h\"\r\n"; } convertCode += CAST_SOURCE_FUNC_BEGIN; foreach (APINode clazz in node.Children) { if (clazz.Name.Equals("Node") || clazz.Name.Equals("Scene") || clazz.Name.Equals("UIElement")) { continue; } convertCode += String.Format(" if (typeName->Equals(\"{0}\")) return gcnew {0}(comp);\r\n", clazz.Name); } convertCode += CAST_SOURCE_FILE_END; System.IO.File.WriteAllText(System.IO.Path.Combine(args[0], "ComponentCast.cpp"), convertCode); } }
public APIDocumentation() { if (root_ == null) { string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); dir = System.IO.Path.Combine(dir, "ScriptAPI.dox"); if (!System.IO.File.Exists(dir)) { //\todo, do something about the case where it doesn't exist? invoke the script API } string[] lines = File.ReadAllLines(dir); APINode current = new APINode { Name = "Root" }; APINode lastPage = null; APINode lastSection = null; APINode lastSubsection = null; foreach (string line in lines) { if (line.StartsWith("\\page")) { string[] words = line.Split(' '); APINode nd = new APINode { Name = string.Join(" ", words, 2, words.Length - 2) }; current.Children.Add(nd); nd.Parent = current; lastPage = nd; lastSection = null; lastSubsection = null; } else if (line.StartsWith("\\section")) { string[] words = line.Split(' '); APINode nd = new APINode { Name = string.Join(" ", words, 2, words.Length - 2) }; if (lastSection != null) { lastSection.Children.Add(nd); nd.Parent = lastSection; } else { lastPage.Children.Add(nd); nd.Parent = lastPage; } lastSubsection = nd; } else if (line.StartsWith("## ")) { APINode nd = new APINode { Name = line.Replace("## ", "").Replace("%", "") }; lastSection = nd; lastPage.Children.Add(nd); nd.Parent = lastPage; } else if (line.StartsWith("### ")) { APINode nd = new APINode { Name = line.Replace("### ", "").Replace("%", "") }; if (lastSection == null) { lastPage.Children.Add(nd); nd.Parent = lastPage; } else { lastSection.Children.Add(nd); nd.Parent = lastSection; } lastSubsection = nd; } else if (line.StartsWith("- ")) { APILeaf leaf = new APILeaf { Name = line.Replace("- ", "").Replace("%", "") }; if (leaf.Name.Contains(":")) { leaf.TypeAnnote = leaf.Name.Substring(leaf.Name.IndexOf(':') + 2); } lastSubsection.Children.Add(leaf); leaf.Parent = lastSubsection; } } //current.Prune(); DocumentNode = current; } }