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

隨筆-341  評論-2670  文章-0  trackbacks-0
    在制作GacUI讀pdb生成代碼的過程中,感受到了C++語言設(shè)計和dll的需求之間的鴻溝。對于一個充分利用了C++各種功能的類庫來說,制作成dll具有非常大的困難,特別是在函數(shù)返回POD(Plain Old Data)的引用,和輸入輸出帶有泛型的類上面。所以現(xiàn)在還是決定以源代碼的方式來發(fā)布GacUI。但是pdb生成代碼并沒有白做,因為反射還是存在的。但是因為GacUI一共有48000行代碼,80多個源代碼文件,直接發(fā)布使用起來總是不方便。所以我寫了個小工具,根據(jù)xml的配置來將源代碼合并成少數(shù)幾個比較大的代碼文件。這樣使用的時候,只需要直接把幾個cpp拖進工程里面,就可以使用了。而且根據(jù)之前發(fā)布的一個投票,似乎大家也最喜歡這種方法。因此這次的決定,僅僅刪掉了作為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包含了用于開發(fā)這個工程的所有VC++2010的工程文件的地址,然后使用category對他們進行分類(pattern是文件全名的某個部分),最后對每一個部分生成一對cpp和h。在最后生成代碼對的時候,如果源代碼從一開始就存在依賴關(guān)系的話,那么在代碼對的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,而且是可以通過編譯的。

 驅(qū)動器 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 字節(jié)
               
2 個目錄 166,357,680,128 可用字節(jié)

   在生成的時候,生成器將會閱讀代碼本身,然后獲取#include "path",然后對他們的關(guān)系進行處理。這個工具的代碼如下:
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");
            }
        }
    }
}

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

評論:
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了 2012-02-29 07:32 | Exoticknight
只看到開源二字就應(yīng)該支持,雖然我暫時不懂C++  回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了 2012-02-29 09:17 | Zblc
強烈支持 拭目以待 = =+   回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了 2012-02-29 18:29 | 春秋十一月
本想幫你的腳本弄個benchmark, 和lua之類的對比一下速度。無奈那么多數(shù)學(xué)函數(shù)里,就木有找到sqrt函數(shù),太杯具了。可以軟實現(xiàn)sqrt,但結(jié)果肯定不公平,無奈只得放棄。  回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了[未登錄] 2012-02-29 21:15 | 陳梓瀚(vczh)
@春秋十一月
一定要sqrt?  回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了 2012-02-29 22:58 | phoenixbing
不容易,真不容易。48000行代碼,80多個源代碼文件  回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了 2012-02-29 22:58 | phoenixbing
不能支持你更多  回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了 2012-03-01 04:42 | bennycen
火速前來參拜Orz  回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了[未登錄] 2012-03-01 09:40 | 潘孫友
還是以源碼方式提供吧,最直接最給力了!  回復(fù)  更多評論
  
# re: 最終還是決定直接以源代碼方式發(fā)布GacUI了 2012-03-01 17:34 | 空明流轉(zhuǎn)
@春秋十一月
SQRT其實沒啥比較的價值,因為這個不是什么常用的函數(shù),如果以數(shù)學(xué)為主導(dǎo)的腳本,那肯定有匯編實現(xiàn),如果是以邏輯為主導(dǎo)的,那一般都是轉(zhuǎn)發(fā)CRT的SQRT了。  回復(fù)  更多評論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产精品自拍三区| 亚洲视频观看| 亚洲一区3d动漫同人无遮挡| 亚洲国产婷婷香蕉久久久久久| 国产女优一区| 激情婷婷久久| 亚洲欧洲日本国产| 一区二区三区精品视频在线观看| 一本久道久久综合中文字幕| 亚洲天堂免费观看| 欧美在线一二三四区| 久久亚洲国产精品一区二区| 欧美激情一区二区三区在线视频| 亚洲国产欧洲综合997久久| 农村妇女精品| 亚洲午夜黄色| 乱人伦精品视频在线观看| 欧美精品免费观看二区| 国产精品欧美日韩久久| 悠悠资源网亚洲青| 久久精品夜色噜噜亚洲aⅴ| 亚洲精品美女91| 中文在线一区| 欧美成人一区二区| 国产美女精品视频| 亚洲欧洲日产国码二区| 午夜日韩福利| 亚洲国产日韩欧美在线图片| 亚洲影视综合| 欧美日本一区| 亚洲第一精品夜夜躁人人爽| 亚洲午夜视频在线观看| 欧美国产精品久久| 久久精品成人一区二区三区| 欧美性猛交视频| 亚洲黄色av| 久久综合色一综合色88| 亚洲在线观看视频| 欧美日韩专区在线| 在线视频你懂得一区| 欧美国产日韩xxxxx| 久久久91精品国产一区二区精品| 国产精品久久久久毛片软件| 亚洲黄色成人| 欧美承认网站| 久久久午夜精品| 国产情侣一区| 欧美在线视频免费播放| 一区二区免费在线播放| 欧美人成网站| 一本大道久久a久久综合婷婷| 欧美成人激情视频| 久久蜜臀精品av| 亚洲第一在线视频| 麻豆成人精品| 久久中文精品| 亚洲国产婷婷香蕉久久久久久99| 久久久一二三| 久久精品最新地址| 在线观看国产精品淫| 蜜桃久久av一区| 蜜桃av一区二区| 亚洲伦理在线免费看| 亚洲欧洲日本在线| 欧美日韩一区二区国产| 中国成人在线视频| 亚洲一区在线直播| 国产欧美日韩一区二区三区在线| 小嫩嫩精品导航| 久久se精品一区二区| 黄色亚洲网站| 欧美aⅴ一区二区三区视频| 久久久水蜜桃| 亚洲精品激情| 中文一区在线| 精品福利电影| 亚洲国产精品电影| 欧美日韩亚洲一区二区三区在线观看| 夜夜爽www精品| 欧美天堂亚洲电影院在线观看| 国产精品video| 夜夜夜久久久| 在线亚洲免费视频| 国产精品日韩欧美| 老**午夜毛片一区二区三区| 久久久久久久97| 亚洲三级免费| 亚洲午夜精品网| 激情综合久久| 亚洲精选久久| 国产在线拍揄自揄视频不卡99| 媚黑女一区二区| 欧美图区在线视频| 开心色5月久久精品| 欧美日韩精品三区| 久久久久国产精品一区三寸| 欧美成人一区二区| 久久精品国产久精国产爱| 欧美黄色一区二区| 久久国产精品网站| 欧美日韩成人网| 久久青草福利网站| 欧美午夜电影完整版| 快射av在线播放一区| 欧美图区在线视频| 亚洲国产乱码最新视频| 国内外成人在线| 亚洲素人在线| 日韩一级大片在线| 久久久精品日韩| 性久久久久久| 欧美日韩一本到| 欧美好骚综合网| 国产一区二区三区在线观看视频| 亚洲理论在线观看| 亚洲欧洲日产国码二区| 久久av资源网| 欧美一区二区视频在线观看2020| 久久免费视频网站| 久久黄色级2电影| 国产精品久久久久久影院8一贰佰| 亚洲春色另类小说| 在线电影一区| 久久久国产一区二区三区| 欧美一区二区三区在线播放| 欧美日本在线播放| 亚洲国产裸拍裸体视频在线观看乱了| 极品少妇一区二区三区| 欧美在线www| 久久久欧美一区二区| 国产乱码精品一区二区三区五月婷| 亚洲精品一区二区三区福利| 日韩视频一区二区在线观看| 男男成人高潮片免费网站| 欧美电影电视剧在线观看| 在线日韩av片| 免费成人av| 欧美激情1区2区| 亚洲二区在线视频| 欧美成人小视频| 91久久精品一区| 一片黄亚洲嫩模| 欧美视频三区在线播放| 99国产精品一区| 性色av一区二区三区红粉影视| 国产精品久久久亚洲一区| 亚洲欧洲视频| 欧美成人资源网| 最新国产成人在线观看| 男女激情久久| 亚洲国产欧洲综合997久久| 亚洲精品综合久久中文字幕| 欧美精品成人91久久久久久久| 亚洲人成网站在线观看播放| 一本色道久久综合一区| 国产精品久久一级| 欧美一区高清| 亚洲福利视频免费观看| 日韩午夜激情电影| 欧美午夜在线观看| 久久国产精品99精品国产| 欧美国产大片| 亚洲视频网站在线观看| 国产亚洲精品福利| 欧美成人国产| av不卡在线看| 久久综合一区二区| 夜夜嗨av一区二区三区四区| 国产精品久久久久7777婷婷| 亚欧美中日韩视频| 欧美高清在线一区| 性一交一乱一区二区洋洋av| 在线成人欧美| 国产精品自拍小视频| 欧美电影电视剧在线观看| 亚洲欧美国产精品专区久久| 欧美成人精品不卡视频在线观看| 一区二区三区偷拍| 亚洲电影自拍| 国产日韩欧美一区在线 | 999在线观看精品免费不卡网站| 国产精品99久久久久久宅男 | 一区二区三区视频在线观看| 久久国产视频网| 亚洲视频日本| 亚洲日本成人在线观看| 国产一区二区精品在线观看| 欧美色播在线播放| 麻豆成人在线播放| 亚洲自拍偷拍一区| 亚洲欧洲在线一区| 欧美h视频在线| 久久er精品视频| 亚洲一区二区三区乱码aⅴ| 亚洲高清久久| 国产主播精品在线| 国产精品午夜电影| 国产精品久久91| 欧美视频四区| 欧美理论片在线观看|