|
Could you post the offendig .cpp as well?
Also, I've seen an unmatched #endif , but I guess it's a only copy&paste error.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
<small><b>Joaquín M López Muñoz wrote:
</b></small><i>Also, I've seen an unmatched #endif, but I guess it's a only copy&paste error. </i>
As stupid as it would have made me look, you got my hopes up there! But yes, just a copy and paste error.
What follows is one of the offending .cpp files (with the corresponding header file as well). I'm sure the only thing you need to look at it the include order at the top of the .cpp.
Flaw.hpp just includes a bunch of constants carried over from the previous version.
J
/* BFrame.h
*
*
*/
#ifndef _BFRAME_H_
#define _BFRAME_H_
#include "Flaw.hpp"
class CFLAWDoc;
class CBFrame
{
private:
// Data is essentially a 3D graph
// ------------------------------
// so list the dimensions
cbDIMENSIONS size;
short frame_number; // current frame (starts from 0)
short line_number; // current line within current frame
LONG channel_offset; // beginning of B-Scan Channel
POSL current; // current position corresponding to
// data (raw axial)
public:
CFile f; // File class
void SetDoc (CFLAWDoc *p);
CFLAWDoc *pDoc; // ptr to the Document Class
DWORD Axial ();
short WavePoints ();
short FrameNumber ();
short LineNumber ();
short RotaryPoints ();
short AxialPoints ();
void SetAxialPoints (short ap);
void SetChannelOffset (long co);
CBFrame (CString FileName, // Constructor for reading B-Scan
LONG ChannelOffset);
virtual ~CBFrame();
cbRETURN_CODE Read (short *frame, short *line, BYTE * data);
cbRETURN_CODE ReadFramePosition (short frame, POSL *pos);
BYTE Seek (DWORD axial); // Locate frame associated with
// specified axial position (raw value)
// in units of 0.00807
BYTE Seek (short frame, short line, short point = 0);
BYTE Seek (short frame, POSL *pos);
BYTE Seek (short frame);
BYTE AdvanceFrame (BYTE inc);
};
#endif // !defined(AFX_BFRAME_H__76544D71_721F_11D4_88BF_006008662998__INCLUDED_)
// BFrame.cpp: implementation of the CBFrame class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BFrame.h"
#include "FlawDoc.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
// Constructor for Circumferential B-scan frame - read
// ============================================
// file is expected to be already opened, as specified by FileName
// and offset to beginning of data specified by ChannelOffset
CBFrame::CBFrame (CString FileName, long ChannelOffset)
{
channel_offset = ChannelOffset;
CFileException e;
if (!f.Open (FileName,
CFile::modeRead |
CFile::shareDenyWrite |
CFile::typeBinary,
&e))
{
AfxMessageBox ("Error: Unable to open File",MB_OK, NULL);
}
long seek = f.Seek (ChannelOffset, CFile::begin);
f.Read (&size.WavePoints, sizeof (size.WavePoints));
f.Read (&size.RotaryPoints, sizeof (size.RotaryPoints));
f.Read (&size.AxialPoints, sizeof (size.AxialPoints));
frame_number = 0;
line_number = 0;
}
CBFrame::~CBFrame()
{
}
// Functions to provide access to private data variables
short CBFrame::WavePoints ()
{
return size.WavePoints;
}
short CBFrame::FrameNumber ()
{
return frame_number;
}
short CBFrame::LineNumber ()
{
return line_number;
}
short CBFrame::RotaryPoints ()
{
return size.RotaryPoints;
}
DWORD CBFrame::Axial ()
{
return current.axial;
}
short CBFrame::AxialPoints ()
{
return size.AxialPoints;
}
// Functions to alter private data variables
void CBFrame::SetChannelOffset (long co)
{
channel_offset = co;
}
void CBFrame::SetAxialPoints (short ap)
{
size.AxialPoints = ap;
}
// Seek a particular frame based on axial value
// ============================================
// axial is raw value in units of flAXIAL_MM_PER_BIT
BYTE CBFrame::Seek (DWORD axial)
{
long offset;
if ((axial >= (DWORD) pDoc->GetFirstPosition()->GetAxial()
) &&
(axial <= (DWORD) pDoc->GetLastPosition()->GetAxial()
)
)
{
// Remember
// --------
// that the axial increment is rounded up to the nearest
// measurable axial value
WORD inc;
inc = pDoc->GetAxialIncrement();
inc += (1 << flAXIAL_BITS_DROPPED) - 1;
inc >>= flAXIAL_BITS_DROPPED;
// June 1, 1993
// ------------
// remove roundup with (inc >> 1). Gives more accurate mapping
frame_number = (short)( (axial -
(DWORD) pDoc->GetFirstPosition()->GetAxial())/inc);
// Ensure frame number within range
// --------------------------------
if (frame_number < 0)
{
frame_number = 0;
}
if (frame_number >= size.AxialPoints)
{
frame_number = size.AxialPoints - 1;
}
offset = channel_offset + 6 /* sizeof (cbDIMENSIONS) */;
offset += frame_number * ((long) size.WavePoints * size.RotaryPoints +
6 /* sizeof (POSL) */);
f.Seek (offset, CFile::begin);
return TRUE;
}
return FALSE;
}
// Seek the beginning of a particular frame
// ========================================
// and return the position information associated with that frame
BYTE CBFrame::Seek (short frame, POSL *pos)
{
long offset;
// Make sure parameters are legal
// ------------------------------
if (!(frame >= 0 && frame < size.AxialPoints))
{
return (FALSE);
}
offset = channel_offset + 6 /* sizeof (cbDIMENSIONS) */;
offset += frame * ((long) size.WavePoints * size.RotaryPoints +
6 /* sizeof (POSL) */);
f.Seek (offset, CFile::begin);
f.Read (pos, 6 /* sizeof (POSL) */);
frame_number = frame;
line_number = 0;
return (TRUE);
}
// Seek the beginning of a particular frame
// ========================================
// Recall that the first record of each frame is the position associated
// with that frame
BYTE CBFrame::Seek (short frame)
{
long offset;
/* Make sure parameters are legal
------------------------------ */
if (!(frame >= 0 && frame < size.AxialPoints))
{
return (FALSE);
}
offset = channel_offset + 6 /* sizeof (cbDIMENSIONS) */;
offset += frame * ((long) size.WavePoints * size.RotaryPoints +
6 /* sizeof (POSL) */);
f.Seek (offset, CFile::begin);
frame_number = frame;
line_number = 0;
return (TRUE);
}
// Seek particular frame and line, and point in line
// =================================================
byte CBFrame::Seek (short frame, short line, short point)
{
long offset;
/* Make sure parameters are legal
------------------------------ */
if (!(frame >= 0 && frame < size.AxialPoints))
{
return (FALSE);
}
if (!(line >= 0 && line < size.RotaryPoints))
{
return (FALSE);
}
offset = channel_offset + 6 /* sizeof (cbDIMENSIONS) */;
offset += frame * ((long) size.WavePoints * size.RotaryPoints +
6 /* sizeof (POSL) */) + 6 /* sizeof (POSL) */;
offset += (long) line * size.WavePoints + point;
f.Seek (offset, CFile::begin);
frame_number = frame;
line_number = line;
return (TRUE);
}
// Read next line
// ==============
// Returns pointer to buffer if successful
// Returns NULL at end-of-frame, and end-of-file.
// end-of-frame can be distinquished by end-of-file by examining
// frame and line. If end-of-file, frame = line = -1.
// If end-of-frame, frame = next frame value, line = 0.
cbRETURN_CODE CBFrame::Read (short *frame, short *line, BYTE * data)
{
/* Special case if line_number = 0
-------------------------------
read in the position. This may be optionally displayed by the system */
if (line_number == 0)
{
Seek (frame_number);
if (f.Read (¤t, 6 /* sizeof (POSL) */) != 6 /* sizeof (POSL) */)
{
return cbUNKNOWN;
}
}
/* Is there another line to read in present frame?
----------------------------------------------- */
if (line_number < size.RotaryPoints)
{
*line = line_number++;
*frame = frame_number;
if (f.Read (data, size.WavePoints) != (unsigned) size.WavePoints)
{
return cbUNKNOWN;
}
return (cbOK);
}
/* Is there another frame to read?
------------------------------- */
if (frame_number < size.AxialPoints - 1)
{
*frame = ++frame_number;
*line = line_number = 0;
return cbEND_OF_FRAME;
}
/* End of file
----------- */
*frame = frame_number = -1;
*line = line_number = -1;
return cbEND_OF_DATA;
}
// This advances the frame number if possible. The parameter is
// used to indicate whether to increment or decrement the
// frame number.
BYTE CBFrame::AdvanceFrame (BYTE inc)
{
/* Special case
------------
line_number should be 0, but if not, advance frame_number */
if (line_number != 0)
{
if (frame_number < size.AxialPoints - 1)
{
++frame_number;
}
}
/* Is there another frame to read?
-------------------------------
Remember that frame_number is set at the next frame, not the
current frame */
if (inc)
{
if (frame_number < size.AxialPoints)
{
return (TRUE);
}
return (FALSE);
}
// else
{
if (frame_number > 1)
{
frame_number -= 2;
return (TRUE);
}
return (FALSE);
}
}
// This function retrieves the recorded position information
// associated with the axial slice in the given frame.
cbRETURN_CODE CBFrame::ReadFramePosition (short frame, POSL *pos)
{
if (!Seek (frame))
{
return cbUNKNOWN;
}
if (f.Read (pos, 6 /* sizeof (POSL) */))
{
return cbUNKNOWN;
}
return cbOK;
}
// Assign pointer to the Document Class
void CBFrame::SetDoc(CFLAWDoc *p)
{
pDoc = p;
}
J
|
|
|
|
|
The #include directives are a liitle convoluted but seem right af first sight. Could it be some of your safeguard #ifndef s are duplicated in your header files? (just a hunch)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
The #include directives are a liitle convoluted but seem right af first sight.
The includes are definitely convoluted. We had some serious compilation time problems (like it was always recompiliing and each time took 5 minutes or so). So I read that Large-Scale C++ Design (Lakos - great book) and finally learned how it all worked.
The trouble is, part of this project was written by a C programmer and another part by a math grad just out of school. OO is new to them and so they don't follow the whole dependancy thing. And I didn't have time to explain it all.
So I ripped out all of the #includes, and hit F7. Added the first #include or forward definition (whichever was necessary) and then hit F7 again. 250 files worth. Took a while, but finally things compile at a reasonable speed and the only stuff that needs a "rebuild-all" frequently is the new math grad's stuff.
Joaquín M López Muñoz wrote:
Could it be some of your safeguard #ifndefs are duplicated in your header files?
I don't think this is a problem but I'll check. I religiously only use one #ifndef per header and none in the .cpp files except MS's debug new stuff.
J
|
|
|
|
|
Another effective way to know wheter the code for CObjectCache is actually included is to insert an #error directive just in the middle of it. If the error does not pop up, something bad is happening
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
Another effective way to know wheter the code for CObjectCache is actually included is to insert an #error directive just in the middle of it. If the error does not pop up, something bad is happening
Excellent. I will remember this technique, thanks.
But in this case, it pops up a billion times - once for each time the file is included.
J
|
|
|
|
|
Well, this is shooting in the dark, but I guess your desperation justifies desperate measures. Try (if you like) copying and pasting the whole CObjectCache definition in one of the offending .cpp , just above the class that uses it. This is not a fix, just a test to see how the compiler behaves.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
Well, this is shooting in the dark, but I guess your desperation justifies desperate measures.
I shot, and it wasn't at all the problem, but it led me to it!!
I guess I don't quite understand templates yet... In the same way you add a forward declaration of a classA to a header file defining classB if a classB contains a pointer to classA (has-a), I had added a forward declaration of my template to one of the other header files.
When I copied the CObjectCache definition in front of the CFLAWDoc class, a bunch of things broke because of redefinitions... and in removing everything that caused the redefinitions, I came across that forward declaration.
Anyways, the forward is gone, the template definition is back to where it should be, and everything compiles and runs just fine.
Thank you sir. While you didn't actually find my problem, it probably would have taken me another day or two to find it without your suggestions.
Next time you're in Toronto, beers are on me.
J
|
|
|
|
|
Next time you're in Toronto, beers are on me.
Hey, glad to be helpful! Never been to Toronto, but came close a couple of years ago (tripped from Nova Scotia to Montreal, beautiful landscape).
The point you raised about forward declarations is interesting. As far a I know one can forward declare templates just like regular classes, and there's no VC++ bug about this feature that I know of. It'd be interesting to try to isolate this behavior in a tiny example (I'll might do it if I had some time spare), maybe you've hit a compiler bug.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ok, here's something...
When I change it to a pointer member and change the CFLAWDoc constructor to "new" it, the compiler complains about 'CObjectCache<class CDataSlice>' : class has no constructors.
Now I've seen this before but only when the compiler has only seen a forward declaration and not the entire definition. Once again, I checked the preprocessor output and everything seems to be in place.
J
|
|
|
|
|
A shot in the dark ...
try putting typename in front of your CObjectCache variable declaration. If there is some confusion on the part of the compiler, maybe that will clear it up (or output a better error message).
CodeGuy
The WTL newsgroup: over 1300 members! Be a part of it. http://groups.yahoo.com/group/wtl
|
|
|
|
|
CodeGuy wrote:
try putting typename in front of your CObjectCache variable declaration. If there is some confusion on the part of the compiler, maybe that will clear it up (or output a better error message).
Not sure what you mean really. I can't put it in front of the type in the allocation statement:
m_pCache = new typename CObjectCache<CDataslice>(2000);
because typename is only allowed inside a template. And it doesn't seem to do anything except provide an alias for a type inside the template.
J
|
|
|
|
|
Have you tried renaming the class ? I've had different problems in the past where I found my core problem was a class named after an MFC class, or a function named after one that MFC or ATL puts in there also, somewhere in the inheritance chain.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?!
- Jon Hulatt, 22/3/2002
|
|
|
|
|
There is also the problem that if you name your H file after one of the system includes, it won't check for time changes. That one is a ***** to figure out.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Tim Smith wrote:
There is also the problem that if you name your H file after one of the system includes, it won't check for time changes.
Nope, I did a full search and there isn't anything that looks like my filename in the entire VS install. Nor is there anything in a full MSDN search with the same name.
I'm totally stumped.
J
|
|
|
|
|
Christian Graus wrote:
Have you tried renaming the class ?
Just tried it. Didn't help. But thanks.
I've looked through the preprocessor output and it's sitting right there.
It's as if it knows that CObjectCache is defined, and that CContainedObject is defined, but somehow CObjectCache<CContainedObject> isn't.
Does that make any sense?
J
|
|
|
|
|
I need a routine to save an icon to disc as an .ico file, or failing that copy an icon to the clipboard. Anybody know of one?
I'm never gonna work another day in my life. The gods told me to relax, They said I'm gonna get fixed up right. Monster Magnet, Powertrip
|
|
|
|
|
lookup the ICONINFO structure and search MSDN for the article "Icons in Win32"
- Roman -
|
|
|
|
|
Thanks!
I'm never gonna work another day in my life. The gods told me to relax, They said I'm gonna get fixed up right. Monster Magnet, Powertrip
|
|
|
|
|
Hey ! Anyone know how can i display a popup menu at top of mouse cursor(from bottom to top), anytime, even if the mouse isn't at the bottom of screen, and windows doesn't have to display the menu from bottom to top.
|
|
|
|
|
Do you mean you want the menu to be outside the screen?
I'm not sure of it if that is your question....
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
no... i didn't meant that...
i meant that if the mouse cursor is too close of the top of the screen to display the menu at bottom of the cursor, and normaly, by default, from down to top...
try to install trillian, and click the trilli button, and see where the menu is going from to where...
cheers
|
|
|
|
|
How can I get the string from a CString to a char*/char????
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
strcpy() or strncpy()
I'm never gonna work another day in my life. The gods told me to relax, They said I'm gonna get fixed up right. Monster Magnet, Powertrip
|
|
|
|
|
Holy god damnit!
I was soooooo sure it wouldn't work!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|