Click here to Skip to main content
15,905,028 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralTool tip text Pin
8-Apr-02 11:11
suss8-Apr-02 11:11 
GeneralRe: Tool tip text Pin
Joaquín M López Muñoz8-Apr-02 11:20
Joaquín M López Muñoz8-Apr-02 11:20 
GeneralRe: Tool tip text Pin
Alexandru Savescu8-Apr-02 22:22
Alexandru Savescu8-Apr-02 22:22 
Generaltemplate members Pin
Jamie Hale8-Apr-02 10:25
Jamie Hale8-Apr-02 10:25 
GeneralRe: template members Pin
Joaquín M López Muñoz8-Apr-02 10:25
Joaquín M López Muñoz8-Apr-02 10:25 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 4:53
Jamie Hale9-Apr-02 4:53 
GeneralRe: template members Pin
Joaquín M López Muñoz9-Apr-02 5:05
Joaquín M López Muñoz9-Apr-02 5:05 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 5:17
Jamie Hale9-Apr-02 5:17 
Ok, it's gigantic though. Smile | :) Apologies for posting so much, but I have a feeling even this isn't enough to see the whole problem...

What follows is three class definitions. The first is the template that handles caching. This class has been transplanted to several other contexts and compiles just fine. The second class is one of the classes I'm trying to contain in the cache template. It just houses a bunch of data - you probably don't need to worry about the details. The third class is the MFC document object. It aggregates one of the cache templates for caching CDataSlice objects.

The compile error is:

flawdoc.h(51) : error C2079: 'm_SliceCache' uses undefined class 'CObjectCache<class CDataSlice>'

and it occurs in every file that includes flawdoc.h (which is most of the project). Line 51 is the line that defines the contained CObjectCache<CDataSlice> m_SliceCache in CFLAWDoc.

Thanks for taking the time, Joaquin. If you can find anything, I'll owe you big time. Smile | :)

J

/* ObjectCache.h
*
*
*/

#ifndef _OBJECTCACHE_H_
#define _OBJECTCACHE_H_

#include <list>

/* CObjectCache
*
* This class provides cached objects. Initialization simply ensures that
* there is at least one block's worth of objects available. New object
* are acquired through GetFreeObject(). When objects are no longer needed,
* they can be returned to the cache through ReleaseObject(). The destructor
* makes sure that all memory gets cleaned up nicely.
*/
template <class T>
class CObjectCache {

// Block Size
//
// m_nBlockSize is the size of block set for this instance of the cache.
// It represents the number of objects to be stored in each cache block.
int m_nBlockSize;

// Block List
//
// This is a list of pointers to object blocks allocated by the cache.
// When a new block needs to be added, it is allocated and initialized,
// and then its base pointer is added to this list. Blocks are only
// removed from this list when the cache is destroyed.
std::list<byte *> m_listBlocks;

// Free List
//
// This is a list of unused objects. Objects are removed from the front of
// this list when required, and they are cleared and placed on the back
// of this list when released.
std::list<T *> m_listFree;

// AddBlock()
//
// This helper routine allocates a new block of objects, clears them, and
// then adds a pointer to each one to the free list. It returns true if
// successful - false if the allocation fails.
bool AddBlock() {

byte *pBase;
T *pT;

pBase = new byte[m_nBlockSize * sizeof(T)];
if(pBase == NULL) return false;
memset(pBase, 0, m_nBlockSize * sizeof(T));
m_listBlocks.push_back(pBase);

for(int i = 0; i < m_nBlockSize; i++) {
pT = new ((void *) &pBase[i * sizeof(T)]) T();
pT->Clear();
m_listFree.push_back(pT);
}

return true;
}

public:
CObjectCache(int nBlockSize = 1000) :
m_nBlockSize(nBlockSize) {}
virtual ~CObjectCache() {

std::list<byte *>::iterator b;

for(b = m_listBlocks.begin(); b != m_listBlocks.end(); b++) {
delete [] *b;
*b = NULL;
}
m_listBlocks.clear();

m_listFree.clear();
}


// Initialization
//
// This routine fills the free list with one block of empty slices.
bool Initialize(int nBlockCount = 1) {

if(m_listFree.size() == 0) {
for(int i = 0; i < nBlockCount; i++)
if(!AddBlock()) return false;
return true;
}

return true;
}

// Acquisition
//
// This routine returns the next available free object. If the free list
// is empty, a new block is added. If AddBlock() fails, this routine
// returns NULL.
T *GetFreeObject() {

T *pT;

if(m_listFree.empty()) {
if(!AddBlock()) {
return NULL;
}
}

pT = m_listFree.front();
m_listFree.pop_front();
return pT;
}

// Release
//
// This routine clears and returns the passed object to the free list.
void ReleaseSlice(T *pT) {

ASSERT(pT);

pT->Clear();
m_listFree.push_back(pT);
}
};

/* DataSlice.h
*
*
*/

#ifndef _DATASLICE_H_
#define _DATASLICE_H_

#include "PythonObject.h"
#include "Interfaces.h"
#include "ObjectCache.h"

class CProbeCorrection;
class CSoftwareGain;
class CPosF;

/* CDataSlice
*
* This class represents a single rotary slice of data in one channel of a
* C-Scan.
* The best way to use this class is to create a new instance passing the
* transformed axial position and raw encoder count. Then, call Load()
* passing and open and properly positioned file stream and a valid CPosF
* object representing the stage 0 offsets that are needed.
*/
class CDataSlice : public ICScanSlice, public CPythonObject {

PO_DECLARE_OBJECT();

// Clear
//
// This flag is set when the slice has been cleared. It allows you to call
// Initialize() and pass the axial position. I didn't want anyone calling
// a mutator like SetAxialPosition() at any time because it could
// possibly mess a few things up.
bool m_bClear;

// Stage 0
//
// At this stage, the data consists of the raw points loaded out of the
// file with the station-specific and inspection-head-specific offsets
// applied. The encoder count value is the raw value loaded from the file
// and is not propagated to stages 1 and 2.
int m_nEncoderCount;
float m_fStage0AxialPosition;
byte m_byStage0Min;
byte m_byStage0Max;
byte m_abyStage0Data[3600];

// Stage 1
//
// At this stage, the data consists of the stage 0 data with the probe
// corrections applied.
float m_fStage1AxialPosition;
byte m_abyStage1Data[3600];

// Stage 2
//
// At this stage, the data consists of the stage 1 data with the software
// gain applied. (Arguably, we probably don't need m_fStage2AxialPosition
// because at present, no further transformations are applied and the
// position will always be the same as the stage 1 position.)
float m_fStage2AxialPosition;
byte m_byStage2Min;
byte m_byStage2Max;
byte m_abyStage2Data[3600];

// ApplyRotaryOffset
//
// This helper routine applies the given rotary offset to the source data
// array while copying to the destination data array.
void ApplyRotaryOffset(byte *abyDest, byte *abySource, int nRotary);

// ApplyAxialOffset
//
// This helper routine applies the given axial offset to the axial
// position variable pointed to by pfDest.
void ApplyAxialOffset(float *pfDest, float fAxial);

// ApplyGain
//
// This helper routine applies the given multiplier gain to all the points
// in the source data array as it is being copied to the destination data
// array.
void ApplyGain(byte *abyDest, byte *abySource, float fMultiplier);

// PrepareStage1
//
// This helper routine clears all data from stage 1 and rebuilds it from
// stage 0 data and the passed probe correction.
void PrepareStage1(CProbeCorrection *pPC);

// PrepareStage2
//
// This helper routine clears all data from stage 2 and rebuilds it from
// stage 1 data and the passed software gain.
void PrepareStage2(CSoftwareGain *pSG);

// Hidden Constructor and Destructor
//
// We only want the slice cache to be able to construct and destroy data
// slices. We make them private but allow the cache to be our friend.
public: // TODO: put this back the way it was!!
//friend class CObjectCache<CDataSlice>;
CDataSlice();
virtual ~CDataSlice();

public:

// Placement operator new()
//
// It looks like we don't need this. This type of initialization is new to
// me, and I haven't figured out what the compiler generates for me. But
// I can compile and run the application just fine with this override
// commented out, I'm guessing the compiler has figured it out.
//inline void *operator new(size_t, void *p) {return p;}

// Initialization
//
inline void Initialize(float fAxialPosition, int nEncoderCount) {
ASSERT(m_bClear);
m_nEncoderCount = nEncoderCount;
m_fStage0AxialPosition = fAxialPosition;
}

// Clear()
//
void Clear();

// ReapplyEnvironment
//
// This routine rebuilds both stage 1 and 2 data sets based on the passed
// probe correction and software gain. Until this is called for the
// first time (after loading), all retrieved data will be zeros.
void ReapplyEnvironment(CProbeCorrection *pPC, CSoftwareGain *pSG);

// ReapplySoftwareGain
//
// This routine rebuilds stage 2 data based on the passed software gain.
void ReapplySoftwareGain(CSoftwareGain *pSG);

// Load
//
// This routine loads a full slice of data into stage 0 from the given
// file stream. It also applies the passed offset. After loading data,
// always remember to reapply the environment settings.
bool Load(CFile *pFile, CPosF &rposOffset);

// operator<()
//
// This operator is used when sorting data slices. It compares axial
// positions, and returns true if the axial position of this slice is
// less than the axial position of the passed slice.
bool operator<(const CDataSlice &s);

// ICScanSlice
//
// These methods implement the ICScanSlice interface.
inline int GetEncoderCount() const {return m_nEncoderCount;}
inline float GetAxialPosition() const {return m_fStage2AxialPosition;}
inline byte GetMin() const {return m_byStage2Min;}
inline byte GetMax() const {return m_byStage2Max;}
inline byte *GetData() {return m_abyStage2Data;}
inline byte GetDataAt(int nIndex) const {
ASSERT(nIndex >= 0);
ASSERT(nIndex < 3600);
return m_abyStage2Data[nIndex];
}

// Python Access
//
PO_DECLARE_GETATTR();
};

#endif


#endif

/* FLAWDoc.h
*
*
*/

#ifndef _FLAWDOC_H_
#define _FLAWDOC_H_

#include "Doc.h"
#include "Interfaces.h"
#include "PythonObject.h"

#include "DataSet.h"
#include "DataChannel.h"

#include "Environ.h"
#include "RevData.h"

#include "AnnotationCollection.h"

#include "ObjectCache.h"
#include "DataSlice.h"

/* CFLAWDoc
*
*/
class CFLAWDoc :
public CDoc,
public ICScanDocument,
public CPythonObject,
public IEnvironChangeListener
{

PO_DECLARE_OBJECT();

// New Data
//
// This is the collection of channels - each a collection of slices - all
// pre-transformed and ready to be merged for drawing. Each slice
// contains three levels of data: raw (including station and head
// offsets), probe-corrected and software-gained.
CDataSet *m_pData;

// Data Slice Cache
//
// This cache stores preallocated CDataSlice objects. It speeds the load
// process. Slice objects need to be returned here when they are no
// longer needed.
//typedef CObjectCache<CDataSlice> SliceCache;
//SliceCache m_SliceCache;
CObjectCache<CDataSlice> m_SliceCache;

// Environment
//
// This is the environment that the user is currently using.
CEnviron m_ENV;

// Indications
//
CAnnotationCollection m_AnnotationCollection;

// Helpers
//
void LoadCScanProperties();
void LoadBScanProperties();

protected:
DECLARE_DYNCREATE(CFLAWDoc)

// _GetDocumentType
//
// This routine is overridden from CDoc and provides the type of the
// document.
virtual inline DocType _GetDocumentType() {return C_SCAN;}

// _QueryInterface
//
// This routine returns the CScan document interface if C_SCAN is passed.
// Otherwise it returns NULL. This routine is for conversion of interface
// pointers. If you have an IDocument pointer and you know it's a CScan
// document (from calling GetDocumentType()), you can query for the
// ICScanDocument interface by calling this routine.
virtual inline void *_QueryInterface(DocType t) {
if(t == C_SCAN) return static_cast<ICScanDocument *>(this);
return NULL;
}

// Error State
void _DumpState(CCrashDump &cd);

public:
CFLAWDoc();
virtual ~CFLAWDoc();

// ICScanDocument
//
// These routines implement the ICScanDocument interface.
inline int GetChannelCount() const {return m_pData->GetChannelCount();}
inline ICScanChannel *GetChannel(int nIndex) const {
ASSERT(nIndex >= 0);
ASSERT(nIndex < m_pData->GetChannelCount());
return m_pData->GetChannel(nIndex);
}

// Internal ICScanDocument Equivalents
//
// Use these methods when accessing the channels from within the Flaw
// application (as opposed to from an extension command library).
inline CDataChannel *InternalGetChannel(int nIndex) const {return m_pData->GetChannel(nIndex);}

// GetData()
//
// This method provides access to all channels of data directly.
inline CDataSet *GetData() const {return m_pData;}

// GetNumRecords()
//
// This routine returns the number of slices in the first channel. It's
// here to save a bit of clutter.
inline int GetNumRecords() {
if(m_pData == NULL) return 0;
return m_pData->GetChannel(0)->GetSliceCount();
}

// UpdateRawData()
//
// This routine updates the document's state from the data file. If the
// file has not changed, nothing happens. Otherwise, the new data is
// loaded and displayed.
bool UpdateRawData(bool bShowProgress = true);

// Environment Access
//
inline CEnviron &GetEnv() {return m_ENV;}
void SetEnv(CEnviron &env);

// IEnvironChangeListener
//
// These routines implement the IEnvironChangeListener interface.
void OnEnvironProbeCorrectionChanged(int nChannel);
void OnEnvironSoftwareGainChanged(int nChannel);

// Python
//
PO_DECLARE_GETATTR();
PO_DECLARE_SETATTR();

//{{AFX_VIRTUAL(CFLAWDoc)
public:
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual void DeleteContents();
virtual BOOL OnNewDocument();
//}}AFX_VIRTUAL

#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:
//{{AFX_MSG(CFLAWDoc)
afx_msg void OnUpdateViewProperties(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}

#endif




J

GeneralRe: template members Pin
Joaquín M López Muñoz9-Apr-02 5:41
Joaquín M López Muñoz9-Apr-02 5:41 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 5:45
Jamie Hale9-Apr-02 5:45 
GeneralRe: template members Pin
Joaquín M López Muñoz9-Apr-02 6:12
Joaquín M López Muñoz9-Apr-02 6:12 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 6:38
Jamie Hale9-Apr-02 6:38 
GeneralRe: template members Pin
Joaquín M López Muñoz9-Apr-02 6:15
Joaquín M López Muñoz9-Apr-02 6:15 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 6:39
Jamie Hale9-Apr-02 6:39 
GeneralRe: template members Pin
Joaquín M López Muñoz9-Apr-02 7:07
Joaquín M López Muñoz9-Apr-02 7:07 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 7:34
Jamie Hale9-Apr-02 7:34 
GeneralRe: template members Pin
Joaquín M López Muñoz9-Apr-02 7:44
Joaquín M López Muñoz9-Apr-02 7:44 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 6:18
Jamie Hale9-Apr-02 6:18 
GeneralRe: template members Pin
CodeGuy9-Apr-02 6:28
CodeGuy9-Apr-02 6:28 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 6:44
Jamie Hale9-Apr-02 6:44 
GeneralRe: template members Pin
Christian Graus8-Apr-02 10:26
protectorChristian Graus8-Apr-02 10:26 
GeneralRe: template members Pin
Tim Smith8-Apr-02 10:42
Tim Smith8-Apr-02 10:42 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 4:57
Jamie Hale9-Apr-02 4:57 
GeneralRe: template members Pin
Jamie Hale9-Apr-02 4:55
Jamie Hale9-Apr-02 4:55 
GeneralSaving Icons Pin
Shog98-Apr-02 9:00
sitebuilderShog98-Apr-02 9:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.