English 中文(简体)
如何在大型C++源树中找到所有相互友谊?
原标题:How to find all mutual friendships in large C++ source tree?

在大型的C++源树中,大约有600种左右的树级被定义,我想找到每个树种的所有奶制品,宣布对方为朋友。

很多情况下,一类人是另一类的朋友,太多人要通过简单细微的结果放弃。

最佳回答

您可以在此实施三轮循环;计算法如下:

  1. First loop: find all classes who have friends, and remember the name of the friend and the name of the actual class;
  2. Then run inner loop for all the classes and find a class with the name of the friend from step 1.
  3. Then run another inner loop through all the friends of the class found at step 2. If you have found class with name from step 1 - voila - they re mutual friends.

我认为, Per和reg是此类事情的最佳工具。

P.S.确保这一办法有其局限性,因为C++中的所有东西都不可能与格雷克(<>使用名称空间的编码是我头脑中的第一个东西)。 但在某种程度上,这种做法是行之有效的,如果你没有其他选择,你可以让它尝试。

EDIT: An idea came to my mind today in the morning, while I still was lying in my bed. :) The idea is quite simple and clear (like all morning ideas): use SQL! Naturally, imagine you have a table of classes with 2 columns, where first column is class name, and second column is it s friend`s name. Say, something like this:

ClassName FriendName
C1        C2
C1        C3
C1        C4
C2        C1
C2        C8
C3        C1
C3        C2
...       ...

然后,你可以对其提出简单的质疑。 比如,Say(令我感到担忧的是,我没有任何银手,也没有听说过问,但我希望你会照此想法,并根据需要加以执行:

SELECT ClassName as c, FriendName as f FROM T
WHERE c in 
  (SELECT FriendName FROM T
     WHERE FriendName = c AND ClassName = f)

这一变式背后的想法是,我们应当使用完全适合这项任务的计票。 能够比较一下一下一下你需要什么数据集?

问题回答

一) 某些方法:

1 Doxygen (http://www.doxygen.nl/) 或许能够向您提供你需要的东西。 (如果现在没有提供这种信息的话,你可以 ha弄Doxygen s C++ parser a bit,以获得你所需要的信息。)

2) 现有C++的CNLR制图档案。

二) 更快捷的方式(或许在此采取正确做法):

象其他人所建议的那样,为了你的目的,应只罚款。 考虑以下假守则:

rm -f result_file;
foreach source_file
do
  sed  s/[ 	
]+/ /g  $source_file >  temp_file;  ## remove newlines, etc
  grep -o -P -i "friend [^;]*;"  >> result_file; ## you can improve this regex for eliminating some possible unwanted matches or post-process result_file later
done

现在,你们所有朋友的关系都是这样。 您可以采用另一种简单的格外和(或)处理结果,根据需要再删除“友好功能”。

这一答案与“用户534498 s”相似,但Im会更详细,因为“C++与reg”的建议是这样无动于衷的,我认为这并不值得考虑。

我还不认为,你会再次找到一种自动工具,使你能够这样做。 如果这块土地得到管理,我就提出如下建议:Nitriq,但我想到的是C++的工程。

如果你不再担心nes门课堂,我认为你可以不遇到太多困难地为朋友建造课堂。 你可以发现关键词类别的实例,随后是粗略的布局,在曲折中,可以找到朋友发言。 这应该给你一份名单,列出朋友们的哪几班。

Once you ve done that, you can check for duplicate references easily. (Depends on the language you re using... if you re in C++ then you d put your results in a std::multimap with the keys being class name and values being the friends)

我认为,这类似于“Haspemulator”建议......但我的观点是,可能比较容易分出教区,然后执行转播令,在纸板或地图上进行核对,然后将试图对这些行动进行盘问。

per 或++ ++ reg reg reg par par all files files files files files files 这种配对应为600个奶粉。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签