|
Some people just like that thunking feeling they experience as they keep banging their head upon the wall ...
I can't wait to see what turds float to the surface the moment a customer passes a network file path into that garbled up code!
I also like the code examples you come across that assume the 'path' starts after the semicolon.
Oh, wait the path "\\Dev\Link\Shared\MyFile.Txt" does not have a semicolon, how can this be
|
|
|
|
|
How about PathFindFileName in shlwapi.dll?
Pax Domini sit semper vobiscum
|
|
|
|
|
Thanks pal. But I think dealing with ReversFind() is so easy.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Does anyone know of any open-source code that will allow me to parse a C++ header file for all the class method signatures?
---
Yours Truly, The One and Only!
web: devmentor.org
Design, Code, Test, Deploy
|
|
|
|
|
Can you more explain about parsing a header file,please?
|
|
|
|
|
i am looking for simple code that will give me a list of all the class method signatures. i want to use these signatures for a tool to generate mock classes for a unit testing tool i have developed.
---
Yours Truly, The One and Only!
web: devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
What part of "parse a C++ header file for all the class method signatures" is troubling you? That's fairly self-explanatory, yes?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Yeah I see.
BTW(I saw your signature they are nice sentences).
|
|
|
|
|
|
i was just thinking about this project!
i wonder if they have a few simple classes i can use to get a parse tree of only the method signature? ... i was looking for something more simple, don't got the energy to dive into larger projects and start ripping out what i need
possibly i can ask the developers to point me to the files i need.
thanks
---
Yours Truly, The One and Only!
web: devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
just a guess, but what are you trying to accomplish here ?
forget this, i've just seen your reply[^] to Hamid.
|
|
|
|
|
DevMentor.org wrote: i was looking for something more simple
Unfortunately, this is not a simple problem.The parser has to be able to handle everything that the CPP language can throw at it, and has to start with trigraph conversion and pre-processing.
If all you need is a tool to fish methods out of classes, something simpler may do. Kernighan and Ritchie give an excelent example of a function declaration parser in their book which you can possibly expand upon for CPP. But, then again, you need to know the names of the types. They are often declared in previously included headers. Maybe hard code in a basic symbol table?
Regards and success
Bram van Kampen
|
|
|
|
|
Thanks Bran for your reply.
I have found a simply tool that someone from the Doxygen-Develop mailing list said I could use, it's called gcc-xml and designed for tool developers like me who don't want to read the "Red Dragon" book on parsing
---
Yours Truly, The One and Only!
web: devmentor.org
Design, Code, Test, Debug
|
|
|
|
|
I am currently trying to create a program to find all possibilities for placing 5 queens and 5 knights on an 8x8 board in such a way nothing will attack anything else. There are 16 possible solutions. My problem i am encountering, is when placing queens. It is not generating all possibilities. I believe it is just taking the first instance it finds and going with that rather than examining the rest of the row for possible solutions. Here is what I have, if you could possibly help it would be greatly appreciated.
#include <iostream>
#include <string>
using namespace std;
class QueenKnight
{
public:
QueenKnight()
{
queens = 0;
knight = 0;
row = 8;
column = 8;
count = 0;
for(int i= 0; i<row; i++)
="" {
="" for(int="" j="0;" j<column;="" j++)
="" board[i][j]="." ;
="" }
=""
="" void="" updateboardq(int="" r,="" int="" c)
="" i="0;" i<row;="" if(i="=" r)
="" if(j="" !="c)
" if(="" (i-j)="=" (r-c)="" )
="" j!="c)
" (i+j)="=" (r+c)="" placequeen(int="" startr,="" startc)
="" if(board[startr][startc]="=" ".")
="" board[startr][startc]="Q" updateboardq(startr,="" startc);
="" if(board[i][j]="" if(queens="" <="" 5)
="" updateboardq(i,j);
="" queens++;
="" }
="" countfree()
="" 8;="" j<8;="" count++;
="" return="" count;
=""
="" displayboard()
="" i<="" row;="" cout="" <<board[i][j]="" <<"="" ";
="" <<endl;
="" bool="" checkknight(int="" i,int="" j)="" returns="" false="" if="" position="" is="" not="" acceptable
="" if((i+2)="" &&="" (j-1)="">=0)
{
if(board[(i+2)][(j-1)] == "Q" || board[(i+2)][(j-1)] == "K")
{
return false;
}
}
if((i+2) <= 7 && (j+1) <=7)
{
if(board[(i+2)][(j+1)] == "Q" || board[(i+2)][(j+1)] == "K")
{
return false;
}
}
if((i-2) >= 0 && (j-1) >=0)
{
if(board[(i-2)][(j-1)] == "Q" || board[(i-2)][(j-1)] == "K")
{
return false;
}
}
if((i-2) >= 0 && (j+1) <= 7)
{
if(board[(i-2)][(j+1)] == "Q" || board[(i-2)][(j+1)] == "K")
{
return false;
}
}
if((i+1) <= 7 && (j-2) >=0)
{
if(board[(i+1)][(j-2)] == "Q" || board[(i+1)][(j-2)] == "K")
{
return false;
}
}
if((i+1) <= 7 && (j+2) <=7)
{
if(board[(i+1)][(j+2)] == "Q" || board[(i+1)][(j+2)] == "K")
{
return false;
}
}
if((i-1) >= 0 && (j-2) >=0)
{
if(board[(i-1)][(j-2)] == "Q" || board[(i-1)][(j-2)] == "K")
{
return false;
}
}
if((i-1) >= 0 && (j+2) <= 7)
{
if(board[(i-1)][(j+2)] == "Q" || board[(i-1)][(j+2)] == "K")
{
return false;
}
}
return true;
}
void placeKnight()
{
for(int i=0; i<8; i++)
{
for(int j=0; j<8; j++)
{
if(board[i][j] == ".")
{
if(checkKnight(i,j))
{
board[i][j] = "K";
knight++;
}
}
}
}
}
int knightCount()
{
return knight;
}
private:
int row;
int queens;
int column;
string board[8][8];
int count;
int knight;
};
int main()
{
int displays = 0;
for(int k=0; k<64; k++)
{
QueenKnight example;
example.placeQueen((k/8), (k % 8));
if(example.countFree() > 4)
{
example.placeKnight();
//cout <<"display: "<<displays<< endl;
="" if(example.knightcount()=""> 2)
// {
example.displayBoard();
cout <
|
|
|
|
|
Hi,
I did not study your code in detail, but have two remarks.
your code would be (more) readable when you:
- show it inside PRE tags (they preserve formatting, in particular indentation)
- (if possible) put opening brackets on the right of the previous line (which most
people don't do, I prefer it since it allows for more useful code lines per screen)
your code would be a lot simpler if you would use a one-dimensional board[64] array
(i.e. concatenating the eight rows) it would avoid a lot of for loops.
For attack checking, you would have to convert the linear index into a row/col pair
which is simply a divide/modulo 8 operation (two preprocessor macros can come in handy here).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
See here.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
can someone post a code on this forum that that takes a matrix converts it to upper triangular form prints the upper triangular form,
|
|
|
|
|
To post this code the users of forum will need to make the same as you can do by yourself... google, because I think no one is going to write you the whole code.
This link[^] is about multipliying matrix and this one[^] is about inverting order (i dont know the technical name) i mean A[i][j] -> A [j][i]. They are on spanish, but you can read the code examples and take a look int the figures, it should be not difficult to get the idea to programm it.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
I wasn't sure where to post this, but since the code I'm having problems on is in my MFC app, I'm posting it here.
I have an RDTSC function in my code. It uses the RDTSC instruction to obtain a value in EDX:EAX. I need to print that value out before the function exits. How do I do that?
(I realize that this might be a stupid question, since I've only been working in assembly for around 3 months and I'm still learning.)
Thanks in advance.
|
|
|
|
|
Something like this maybe?
unsigned __int64 rdtscval;
__asm
{
rdtsc
lea ebx, rdtscval
mov [ebx], eax
mov [ebx+4], edx
}
CString str;
str.Format(_T("%I64u"), rdtscval);
::MessageBox(*this, str, _T("rdtsc"), MB_OK);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I've written into some Code Project sample code a solution generously offered to me by a fellow poster for an adaptation to the code I had wanted to make. I had asked the board if there was a way to get at the value inside a variable called strContent here inside of OnDataReady (and one aspect of the solution involved renaming it to m_strContent, the way it's now shown here in this CMemMapCppClientDlg.cpp snip):
LRESULT CMemMapCppClientDlg::OnDataReady(WPARAM, LPARAM) <br />
{<br />
HANDLE hMapFile = NULL;<br />
PVOID pView = NULL;<br />
<br />
hMapFile = OpenFileMapping(FILE_MAP_READ, FALSE, m_pszMemMapFileName);<br />
if(hMapFile == NULL) {<br />
MessageBox("Can not open file mapping");<br />
return 0;<br />
}<br />
<br />
pView = MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);<br />
if(pView == NULL) {<br />
MessageBox("Can map view of file");<br />
CloseHandle(hMapFile);<br />
return 0;<br />
}<br />
<br />
LPSTR szContent = reinterpret_cast<LPSTR>(pView);<br />
int nLen = strlen(szContent);<br />
while(nLen > 0) {<br />
m_strContent += *szContent++;<br />
--nLen;<br />
}<br />
m_strContent += '\0';<br />
m_strContent.Replace("\n", "\r\n");<br />
<br />
if(pView) UnmapViewOfFile(pView);<br />
if(hMapFile) CloseHandle(hMapFile);<br />
<br />
return 0;<br />
}<br />
<br />
CString CMemMapCppClientDlg::GetContent()<br />
{<br />
return m_strContent;<br />
}
Another part of the solution involved adding the ::GetContent() function, shown there immediately above.
Then the appropriate changes were shown to me for the header, here:
<br />
#if !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)<br />
#define AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
<br />
class CMemMapCppClientDlg : public CDialog<br />
{<br />
public:<br />
static UINT UWM_DATA_READY;<br />
CMemMapCppClientDlg(CWnd* pParent = NULL);
CString GetContent();<br />
<br />
enum { IDD = IDD_MEMMAPCPPCLIENT_DIALOG };<br />
protected:<br />
<br />
protected:<br />
virtual BOOL OnInitDialog();<br />
afx_msg LRESULT OnDataReady(WPARAM wParam, LPARAM lParam);<br />
DECLARE_MESSAGE_MAP()<br />
CString m_strContent; <br />
<br />
private:<br />
LPCTSTR m_pszMemMapFileName;<br />
};<br />
<br />
#define UWM_DATA_READY_MSG _T("UWM_DATA_READY_MSG-{7FDB2CB4-5510-4d30-99A9-CD7752E0D680}")<br />
<br />
<br />
#endif // !defined(AFX_MEMMAPCPPCLIENTDLG_H__A51F6AF7_F28D_461D_8FB3_EFC7B929D99C__INCLUDED_)
And, lastly, here is the MemMapCppClient.cpp that contains the call to GetContent():
...<br />
<br />
VARIANT _stdcall SumOneToArray(VARIANT sourceArray)<br />
{<br />
CMemMapCppClientDlg dlg;<br />
CString strContent = dlg.GetContent();<br />
MessageBox(NULL, _T(strContent), _T("Like this:"), MB_OK);<br />
<br />
if(sourceArray.vt==VT_DISPATCH)<br />
sourceArray = CheckExcelArray(sourceArray);<br />
<br />
long ncols, nrows, i, j;<br />
<br />
ncols=(sourceArray.parray)->rgsabound[0].cElements;<br />
nrows=(sourceArray.parray)->rgsabound[1].cElements;<br />
<br />
...<br />
}<br />
...
I've gone and stuck the...
CMemMapCppClientDlg dlg;<br />
CString strContent = dlg.GetContent();<br />
MessageBox(NULL, _T(strContent), _T("Like this:"), MB_OK);
...inside the top of one of the functions. The project won't compile if I put those statements anywhere else in the function, like in the middle. I get "initialization" errors.
The question is this: Even when all of this compiles perfectly, and my program works great--even the MessageBox gets displayed on cue--no content is there in the MessageBox. Never in any incarnation of a successful compile do I get content within the MessageBox. The prog always works perfectly otherwise.
(I know for a fact content is otherwise available in m_strContent over in the MemMapCppClient.cpp because if I put the MessageBox over there, I get m_strContent just fine.)
I botched this somehow. How can I get a value into the MessageBox inside of CMemMapCppClientApp?
Thanks again for all your help.
-- modified at 18:45 Thursday 8th November, 2007
|
|
|
|
|
e40s wrote: So, one question is how do I use CMemMapCppClientDlg dlg;
elsewhere in the MemMapCppClient.cpp while still retaining the apps compilability?
Do the same thing that you have done earlier with the CString m_strContent by declaring the CMemMapCppClientDlg on the MemMapCppClient.h. Try if that works first.
e40s wrote: The bigger question is this: Even when all of this compiles perfectly, and my program works great--even the MessageBox gets displayed on cue--no content is there in the MessageBox. Never in any incarnation of a successful compile do I get content within the MessageBox. The prog always works perfectly otherwise.
Make it into this: MessageBox(strContent, _T("Like this:"));
By default the message box has an OK button so no need to add MB_OK there.
|
|
|
|
|
That suggestion works in some other parts of the program, but in this, MessageBoxA demands four arguments.
But there is something else I'm noticing: The strContent may never appear in the box because it's never arriving from GetContent().
In MemMapCppClientDlg, I added a MessageBox() to GetContent(), above the return, like so:
MessageBox(_T(m_strContent), _T("Forget this."));<br />
return m_strContent;
and got no content inside the MessageBox's client area. It's possible m_strContent isn't delivering a value.
Can someone please look at this--maybe specifically the header file, and see if something's lacking. A pointer maybe? I don't know; I'm lost.
Thanks again all.
|
|
|
|
|
It will be better if you use the < pre > < /pre > tags to englobe pieces of code, and the < code > < /code > to highlight little things. Is easier to read on the other way. And with pre the horizontal limit for a line is bigger, so commands won't be broken in different lines not so oft.
EDIT: Maybe a Site Admin could change the label from tags.
code -> Highlight (or something like that)
pre -> snippet (or something like that)
I had the same mistake at the beggining, I thought "paste code = code tag"
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Thanks for this, Nelek. I didn't know about pre.
|
|
|
|
|