青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆-341  評論-2670  文章-0  trackbacks-0
    在制作GacUI讀pdb生成代碼的過程中,感受到了C++語言設計和dll的需求之間的鴻溝。對于一個充分利用了C++各種功能的類庫來說,制作成dll具有非常大的困難,特別是在函數返回POD(Plain Old Data)的引用,和輸入輸出帶有泛型的類上面。所以現在還是決定以源代碼的方式來發布GacUI。但是pdb生成代碼并沒有白做,因為反射還是存在的。但是因為GacUI一共有48000行代碼,80多個源代碼文件,直接發布使用起來總是不方便。所以我寫了個小工具,根據xml的配置來將源代碼合并成少數幾個比較大的代碼文件。這樣使用的時候,只需要直接把幾個cpp拖進工程里面,就可以使用了。而且根據之前發布的一個投票,似乎大家也最喜歡這種方法。因此這次的決定,僅僅刪掉了作為backup plan的dll方法。

    這里我給出小工具的代碼和配置文件。這個配置文件是基于GacUI做出來的,不過大家可以修改它,以便用于自己的工程上面:
<?xml version="1.0" encoding="utf-8" ?>
<codegen>
  
<projects>
    
<project path="..\..\..\GacUISrc\GacUISrc.vcxproj" />
  
</projects>
  
<categories>
    
<category name="vlpp" pattern="\Library\"/>
    
<category name="gacui" pattern="\GacUILibrary\">
      
<except filename="GacUI_WinMain.cpp" />
      
<except filename="GuiTypeDescriptorImpHelper.cpp" />
      
<except filename="GuiTypeDescriptorImpProvider_codegen.cpp" />
    
</category>
  
</categories>
  
<output path="..\..\..\GacUILibraryExternal\">
    
<codepair category="vlpp" filename="Vlpp" />
    
<codepair category="gacui" filename="GacUI" />
    
<header source="..\..\..\GacUILibrary\GacUI.h" filename="GacUIIncludes" />
  
</output>
</codegen>

    在這里面,project包含了用于開發這個工程的所有VC++2010的工程文件的地址,然后使用category對他們進行分類(pattern是文件全名的某個部分),最后對每一個部分生成一對cpp和h。在最后生成代碼對的時候,如果源代碼從一開始就存在依賴關系的話,那么在代碼對的h文件里面,會包含依賴的代碼對的h。在這里,vlpp是獨立的,而gacui依賴了vlpp,所以gacui.h將會#include"vlpp.h",而cpp只include自己的h文件。output里面除了codepair以外還有header,header是不參與codepair計算的,純粹為了生成“可以省事直接include”的頭文件。在這個例子里面,GacUIIncludes.h將會包含完整的GacUI.h和一部分的Vlpp.h,而且是可以通過編譯的。

 驅動器 E 中的卷沒有標簽。
 卷的序列號是 
9614-79B9

 E:\Codeplex\vlpp\Workspace\Tools\Release\SideProjects\GacUISrc\GacUILibraryExternal 的目錄

2012/02/29  21:42    <DIR>          .
2012/02/29  21:42    <DIR>          ..
2012/02/29  21:42                 0 dir.txt
2012/02/29  21:18           677,987 GacUI.cpp
2012/02/29  21:18           304,231 GacUI.h
2012/02/29  21:18           481,551 GacUIIncludes.h
2012/02/29  21:18            69,348 Vlpp.cpp
2012/02/29  21:18           310,126 Vlpp.h
               
6 個文件      1,843,243 字節
               
2 個目錄 166,357,680,128 可用字節

   在生成的時候,生成器將會閱讀代碼本身,然后獲取#include "path",然后對他們的關系進行處理。這個工具的代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Linq;
using System.Text.RegularExpressions;

namespace Codegen
{
    
class Program
    {
        
static string[] GetCppFiles(string projectFile)
        {
            
string np = @"http://schemas.microsoft.com/developer/msbuild/2003";
            XDocument document 
= XDocument.Load(projectFile);
            
return document
                .Root
                .Elements(XName.Get(
"ItemGroup", np))
                .SelectMany(e 
=> e.Elements(XName.Get("ClCompile", np)))
                .Select(e 
=> Path.GetFullPath(Path.GetDirectoryName(projectFile) + "\\" + e.Attribute("Include").Value))
                .ToArray();
        }

        
static Dictionary<stringstring[]> CategorizeCodeFiles(XDocument config, string[] files)
        {
            Dictionary
<stringstring[]> categorizedFiles = new Dictionary<stringstring[]>();
            
foreach (var e in config.Root.Element("categories").Elements("category"))
            {
                
string name = e.Attribute("name").Value;
                
string pattern = e.Attribute("pattern").Value.ToUpper();
                
string[] exceptions = e.Elements("except").Select(x => x.Attribute("filename").Value.ToUpper()).ToArray();
                categorizedFiles.Add(
                    name,
                    files
                        .Where(f 
=> f.ToUpper().Contains(pattern))
                        .Where(f 
=> !exceptions.Contains(Path.GetFileName(f).ToUpper()))
                        .ToArray()
                        );
            }
            
foreach (var a in categorizedFiles.Keys)
            {
                
foreach (var b in categorizedFiles.Keys)
                {
                    
if (a != b)
                    {
                        
if (categorizedFiles[a].Intersect(categorizedFiles[b]).Count() != 0)
                        {
                            
throw new ArgumentException();
                        }
                    }
                }
            }
            
return categorizedFiles;
        }

        
static Dictionary<stringstring[]> ScannedFiles = new Dictionary<stringstring[]>();
        
static Regex IncludeRegex = new Regex(@"^\s*\#include\s*""(?<path>[^""]+)""\s*$");
        
static Regex IncludeSystemRegex = new Regex(@"^\s*\#include\s*\<(?<path>[^""]+)\>\s*$");

        
static string[] GetIncludedFiles(string codeFile)
        {
            codeFile 
= Path.GetFullPath(codeFile).ToUpper();
            
string[] result = null;
            
if (!ScannedFiles.TryGetValue(codeFile, out result))
            {
                List
<string> directIncludeFiles = new List<string>();
                
foreach (var line in File.ReadAllLines(codeFile))
                {
                    Match match 
= IncludeRegex.Match(line);
                    
if (match.Success)
                    {
                        
string path = match.Groups["path"].Value;
                        path 
= Path.GetFullPath(Path.GetDirectoryName(codeFile) + @"\" + path).ToUpper();
                        
if (!directIncludeFiles.Contains(path))
                        {
                            directIncludeFiles.Add(path);
                        }
                    }
                }

                
for (int i = directIncludeFiles.Count - 1; i >= 0; i--)
                {
                    directIncludeFiles.InsertRange(i, GetIncludedFiles(directIncludeFiles[i]));
                }
                result 
= directIncludeFiles.Distinct().ToArray();
                ScannedFiles.Add(codeFile, result);
            }
            
return result;
        }

        
static string[] SortDependecies(Dictionary<stringstring[]> dependeicies)
        {
            var dep 
= dependeicies.ToDictionary(p => p.Key, p => new HashSet<string>(p.Value));
            List
<string> sorted = new List<string>();
            
while (dep.Count > 0)
            {
                
bool found = false;
                
foreach (var p in dep)
                {
                    
if (p.Value.Count == 0)
                    {
                        found 
= true;
                        sorted.Add(p.Key);
                        
foreach (var q in dep.Values)
                        {
                            q.Remove(p.Key);
                        }
                        dep.Remove(p.Key);
                        
break;
                    }
                }
                
if (!found)
                {
                    
throw new ArgumentException();
                }
            }
            
return sorted.ToArray();
        }

        
static void Combine(string[] files, string outputFilename, HashSet<string> systemIncludes, params string[] externalIncludes)
        {
            
try
            {
                
using (StreamWriter writer = new StreamWriter(new FileStream(outputFilename, FileMode.Create), Encoding.Default))
                {
                    writer.WriteLine(
"/***********************************************************************");
                    writer.WriteLine(
"THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY");
                    writer.WriteLine(
"DEVELOPER: 陳梓瀚(vczh)");
                    writer.WriteLine(
"***********************************************************************/");
                    
foreach (var inc in externalIncludes)
                    {
                        writer.WriteLine(
"#include \"{0}\"", inc);
                    }

                    
foreach (var file in files)
                    {
                        writer.WriteLine(
"");
                        writer.WriteLine(
"/***********************************************************************");
                        writer.WriteLine(file);
                        writer.WriteLine(
"***********************************************************************/");
                        
foreach (var line in File.ReadAllLines(file, Encoding.Default))
                        {
                            Match match 
= null;

                            match 
= IncludeSystemRegex.Match(line);
                            
if (match.Success)
                            {
                                
if (systemIncludes.Add(match.Groups["path"].Value.ToUpper()))
                                {
                                    writer.WriteLine(line);
                                }
                            }
                            
else
                            {
                                match 
= IncludeRegex.Match(line);
                                
if (!match.Success)
                                {
                                    writer.WriteLine(line);
                                }
                            }
                        }
                    }
                }
                Console.WriteLine(
"Succeeded to write: {0}", outputFilename);
            }
            
catch (Exception)
            {
                Console.WriteLine(
"Failed to write: {0}", outputFilename);
            }
        }

        
static void Combine(string inputFilename, string outputFilename, params string[] externalIncludes)
        {
            HashSet
<string> systemIncludes = new HashSet<string>();
            
string[] files = GetIncludedFiles(inputFilename).Concat(new string[] { inputFilename }).Distinct().ToArray();
            Combine(files, outputFilename, systemIncludes, externalIncludes);
        }

        
static void Main(string[] args)
        {
            
// load configuration
            XDocument config = XDocument.Load("CodegenConfig.xml");
            
string folder = Path.GetDirectoryName(typeof(Program).Assembly.Location) + "\\";

            
// collect project files
            string[] projectFiles = config.Root
                .Element(
"projects")
                .Elements(
"project")
                .Select(e 
=> Path.GetFullPath(folder + e.Attribute("path").Value))
                .ToArray();

            
// collect code files
            string[] unprocessedCppFiles = projectFiles.SelectMany(GetCppFiles).Distinct().ToArray();
            
string[] unprocessedHeaderFiles = unprocessedCppFiles.SelectMany(GetIncludedFiles).Distinct().ToArray();

            
// categorize code files
            var categorizedCppFiles = CategorizeCodeFiles(config, unprocessedCppFiles);
            var categorizedHeaderFiles 
= CategorizeCodeFiles(config, unprocessedHeaderFiles);
            var outputFolder 
= Path.GetFullPath(folder + config.Root.Element("output").Attribute("path").Value);
            var categorizedOutput 
= config.Root
                .Element(
"output")
                .Elements(
"codepair")
                .ToDictionary(
                    e 
=> e.Attribute("category").Value,
                    e 
=> Path.GetFullPath(outputFolder + e.Attribute("filename").Value
                    ));

            
// calculate category dependencies
            var categoryDependencies = categorizedCppFiles
                .Keys
                .Select(k 
=>
                    {
                        var headerFiles 
= categorizedCppFiles[k]
                            .SelectMany(GetIncludedFiles)
                            .Distinct()
                            .ToArray();
                        var keys 
= categorizedHeaderFiles
                            .Where(p 
=> p.Value.Any(h => headerFiles.Contains(h)))
                            .Select(p 
=> p.Key)
                            .Except(
new string[] { k })
                            .ToArray();
                        
return Tuple.Create(k, keys);
                    })
                .ToDictionary(t 
=> t.Item1, t => t.Item2);

            
// sort categories by dependencies
            var categoryOrder = SortDependecies(categoryDependencies);
            Dictionary
<string, HashSet<string>> categorizedSystemIncludes = new Dictionary<string, HashSet<string>>();

            
// generate code pair header files
            foreach (var c in categoryOrder)
            {
                
string output = categorizedOutput[c] + ".h";
                List
<string> includes = new List<string>();
                
foreach (var dep in categoryDependencies[c])
                {
                    includes.AddRange(categorizedSystemIncludes[dep]);
                }
                HashSet
<string> systemIncludes = new HashSet<string>(includes.Distinct());
                categorizedSystemIncludes.Add(c, systemIncludes);
                Combine(
                    categorizedHeaderFiles[c],
                    output,
                    systemIncludes,
                    categoryDependencies[c]
                        .Select(d 
=> Path.GetFileName(categorizedOutput[d] + ".h"))
                        .ToArray()
                    );
            }

            
// generate code pair cpp files
            foreach (var c in categoryOrder)
            {
                
string output = categorizedOutput[c];
                
string outputHeader = Path.GetFileName(output + ".h");
                
string outputCpp = output + ".cpp";
                HashSet
<string> systemIncludes = categorizedSystemIncludes[c];
                Combine(
                    categorizedCppFiles[c],
                    outputCpp,
                    systemIncludes,
                    outputHeader
                    );
            }

            
// generate header files
            var headerOutput = config.Root
                .Element(
"output")
                .Elements(
"header")
                .ToDictionary(
                    e 
=> Path.GetFullPath(folder + e.Attribute("source").Value),
                    e 
=> Path.GetFullPath(outputFolder + e.Attribute("filename").Value)
                    );
            
foreach (var o in headerOutput)
            {
                Combine(o.Key, o.Value 
+ ".h");
            }
        }
    }
}

    代碼已經checkin在了Vczh Library++3.0(Tools\Release\SideProjects\GacUISrc\GacUISrc.sln)下面,里面也包含了生成后的代碼。
posted on 2012-02-29 05:34 陳梓瀚(vczh) 閱讀(4029) 評論(9)  編輯 收藏 引用 所屬分類: GacUI

評論:
# re: 最終還是決定直接以源代碼方式發布GacUI了 2012-02-29 07:32 | Exoticknight
只看到開源二字就應該支持,雖然我暫時不懂C++  回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了 2012-02-29 09:17 | Zblc
強烈支持 拭目以待 = =+   回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了 2012-02-29 18:29 | 春秋十一月
本想幫你的腳本弄個benchmark, 和lua之類的對比一下速度。無奈那么多數學函數里,就木有找到sqrt函數,太杯具了??梢攒泴崿Fsqrt,但結果肯定不公平,無奈只得放棄。  回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了[未登錄] 2012-02-29 21:15 | 陳梓瀚(vczh)
@春秋十一月
一定要sqrt?  回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了 2012-02-29 22:58 | phoenixbing
不容易,真不容易。48000行代碼,80多個源代碼文件  回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了 2012-02-29 22:58 | phoenixbing
不能支持你更多  回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了 2012-03-01 04:42 | bennycen
火速前來參拜Orz  回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了[未登錄] 2012-03-01 09:40 | 潘孫友
還是以源碼方式提供吧,最直接最給力了!  回復  更多評論
  
# re: 最終還是決定直接以源代碼方式發布GacUI了 2012-03-01 17:34 | 空明流轉
@春秋十一月
SQRT其實沒啥比較的價值,因為這個不是什么常用的函數,如果以數學為主導的腳本,那肯定有匯編實現,如果是以邏輯為主導的,那一般都是轉發CRT的SQRT了。  回復  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久婷婷丁香| 精品动漫一区二区| 亚洲国产高清aⅴ视频| 麻豆国产精品一区二区三区 | 亚洲破处大片| 榴莲视频成人在线观看| 久久欧美肥婆一二区| 久久久水蜜桃| 欧美大秀在线观看| 一本到高清视频免费精品| 亚洲男人第一av网站| 久久久www成人免费无遮挡大片| 开心色5月久久精品| 欧美日韩国产另类不卡| 国产精品一区一区三区| 在线观看一区视频| 亚洲午夜一区二区三区| 久久综合影音| 一区二区日韩| 猛干欧美女孩| 国产一区二区看久久| 日韩亚洲欧美一区二区三区| 亚洲欧美日韩一区二区三区在线 | 91久久夜色精品国产九色| 中文精品视频一区二区在线观看| 欧美在线高清视频| 欧美日韩一区二区免费视频| 黄色成人91| 西瓜成人精品人成网站| 亚洲精品1234| 久久久久久久999精品视频| 欧美日韩视频一区二区| 在线精品福利| 久久天天狠狠| 亚洲欧美伊人| 国产精品久久久久aaaa九色| 亚洲精品日韩久久| 美女露胸一区二区三区| 国产伦精品一区二区三区视频孕妇| 国产精品毛片在线看| 国产精品夜夜嗨| 一区二区三区 在线观看视频| 裸体丰满少妇做受久久99精品| 一本色道**综合亚洲精品蜜桃冫| 欧美国产日韩一二三区| 在线观看精品视频| 久久免费的精品国产v∧| 亚洲欧美伊人| 国产三级欧美三级| 亚洲欧美在线一区| 亚洲在线成人精品| 国产精品一区二区三区免费观看| 亚洲网友自拍| 一区电影在线观看| 欧美午夜电影在线| 亚洲在线日韩| 亚洲伊人网站| 国产午夜精品在线| 久久综合久久综合久久| 久久久久国产一区二区| 亚洲高清一二三区| 亚洲国产二区| 欧美日韩一区二区在线| 亚洲性感激情| 亚洲欧美日本日韩| 狠狠色丁香久久婷婷综合丁香| 久久久天天操| 久久综合五月天婷婷伊人| 亚洲福利视频免费观看| 欧美激情视频一区二区三区免费 | 在线一区欧美| 国产视频不卡| 欧美成人精品在线| 欧美另类视频| 欧美综合二区| 老色鬼久久亚洲一区二区| 亚洲欧洲三级电影| 中文欧美字幕免费| 国产亚洲精品久久久| 欧美1级日本1级| 欧美日韩岛国| 久久久久久久久综合| 久久亚洲综合色| 一区二区三区欧美在线观看| 亚洲一区制服诱惑| 在线免费观看视频一区| 亚洲每日在线| 国产一区二区福利| 久久中文精品| 国产精品www| 久久精品夜色噜噜亚洲a∨ | 欧美一级视频免费在线观看| 久久久国产一区二区三区| 99re热这里只有精品视频| 亚洲在线1234| 亚洲免费观看视频| 99精品欧美一区二区蜜桃免费| 久久夜色精品国产欧美乱极品| 欧美大片一区二区| 亚洲欧美日韩一区二区三区在线| 欧美制服丝袜第一页| 亚洲婷婷免费| 欧美风情在线观看| 久久婷婷蜜乳一本欲蜜臀| 欧美亚洲成人网| 亚洲电影av在线| 黑人巨大精品欧美一区二区| 一区二区三区.www| 亚洲精品一区二区三区av| 欧美一区精品| 欧美综合国产精品久久丁香| 欧美日韩成人一区| 亚洲成色精品| 在线免费观看成人网| 午夜精品福利在线| 亚洲欧美欧美一区二区三区| 欧美激情一区二区三区不卡| 久久久精品久久久久| 国产农村妇女毛片精品久久莱园子 | 你懂的视频一区二区| 久久精品欧美| 国产精品婷婷午夜在线观看| 亚洲精品久久7777| 亚洲人久久久| 欧美va日韩va| 嫩草国产精品入口| 国产综合色产| 欧美在线视频一区二区| 久久爱www久久做| 国产精品久久久久久模特| 亚洲久色影视| 夜夜嗨av一区二区三区免费区| 美女999久久久精品视频| 欧美a级在线| 亚洲国语精品自产拍在线观看| 久久久久久久网| 免费在线观看一区二区| 亚洲国产你懂的| 欧美福利在线| 日韩亚洲精品在线| 亚洲欧美日韩国产成人精品影院| 国产精品久久久久久福利一牛影视| 在线综合亚洲| 久久国产精品色婷婷| 国内精品久久久久影院薰衣草| 久久精品女人的天堂av| 欧美激情第4页| 中日韩美女免费视频网址在线观看 | 欧美高清视频一区| 亚洲国产日韩欧美在线动漫| 欧美电影在线播放| 99精品免费视频| 久久精品国产久精国产思思| 红杏aⅴ成人免费视频| 黄网站免费久久| 欧美大片免费看| 日韩亚洲国产欧美| 欧美一区二区三区四区高清| 国内精品久久久久久久影视麻豆 | 卡一卡二国产精品| 最新国产乱人伦偷精品免费网站| 国产精品99久久久久久久久久久久| 国产精品国产三级国产| 欧美在线国产| 91久久在线播放| 午夜一区二区三区不卡视频| 影音先锋久久| 欧美色网在线| 久久久久国产精品人| 亚洲黄一区二区三区| 欧美在线日韩| 99视频一区二区| 精品成人国产| 国产精品国产三级国产专播品爱网| 久久九九国产| 中文国产成人精品| 欧美黄色aaaa| 久久精品国产亚洲一区二区| 一区二区不卡在线视频 午夜欧美不卡'| 国产精品亚洲综合| 欧美aⅴ一区二区三区视频| 亚洲一级二级在线| 亚洲精品黄网在线观看| 久久看片网站| 香蕉久久国产| 一区二区欧美日韩视频| 在线免费观看视频一区| 国产欧美精品日韩| 欧美日韩精品一区| 久久综合久色欧美综合狠狠| 亚洲欧美日韩一区| 日韩午夜一区| 亚洲国产欧美一区二区三区久久| 久久久www免费人成黑人精品| 一区二区三区欧美激情| 亚洲精选在线观看| 亚洲国产精品久久91精品| 国语自产在线不卡| 国产女主播一区二区三区| 国产精品video|