Annotation of mstools/mfc/samples/chart/dobject.cpp, revision 1.1.1.1

1.1       root        1: // dobject.cpp : Defines the class behaviors for the Chart data objects.
                      2: //
                      3: // This is a part of the Microsoft Foundation Classes C++ library.
                      4: // Copyright (C) 1992 Microsoft Corporation
                      5: // All rights reserved.
                      6: //
                      7: // This source code is only intended as a supplement to the
                      8: // Microsoft Foundation Classes Reference and Microsoft
                      9: // QuickHelp documentation provided with the library.
                     10: // See these sources for detailed information regarding the
                     11: // Microsoft Foundation Classes product.
                     12: //
                     13: 
                     14: #include "chart.h"
                     15: 
                     16: /////////////////////////////////////////////////////////////////////////////
                     17: // CChartObject
                     18: 
                     19: // CChartObject is a container class of the chart's title and list of
                     20: // data points in the graph.  The list is a CObList (see afxcoll.h)
                     21: // of CChartData points.
                     22: 
                     23: IMPLEMENT_SERIAL(CChartObject, CObject, 0)
                     24: 
                     25: // Constructor:
                     26: // Creates the list for the CChartData objects
                     27: //
                     28: CChartObject::CChartObject()
                     29: {
                     30:        m_pChartData = new CObList;
                     31:        m_nType = IDM_BAR;
                     32:        m_bDirty = FALSE;
                     33: }
                     34: 
                     35: 
                     36: // Destructor:
                     37: // Delete all the contents, too.
                     38: //
                     39: CChartObject::~CChartObject()
                     40: {
                     41:        // Removes & Deletes all objects contained in the chart data list
                     42:        //
                     43:        RemoveAll();        
                     44:        delete m_pChartData;
                     45: }
                     46: 
                     47: // Serialize:
                     48: //
                     49: void CChartObject::Serialize(CArchive& ar)
                     50: {
                     51:        // Serialize the base object first.
                     52:        //
                     53:        CObject::Serialize(ar);
                     54: 
                     55:        // Input or output our items to the archive.
                     56:        //
                     57:        if(ar.IsStoring())
                     58:        {
                     59:                ar << m_Title;
                     60:                ar << m_pChartData;
                     61:                ar << m_nType;
                     62:        }
                     63:        else
                     64:        {
                     65:                RemoveAll();
                     66:                delete m_pChartData;
                     67:                        // Delete old data before reading in new data
                     68:                ar >> m_Title;
                     69:                ar >> m_pChartData;
                     70:                ar >> m_nType;
                     71:        }
                     72: }
                     73: 
                     74: // RemoveAll:
                     75: // A quick way of clearing all of the elements in the m_pChartData member.
                     76: //
                     77: void CChartObject::RemoveAll()
                     78: {
                     79:        if (m_pChartData != NULL)
                     80:        {
                     81:                if (m_pChartData->GetCount() > 0)
                     82:                {
                     83:                        // Delete the elements.
                     84:                        //
                     85:                        while (!m_pChartData->IsEmpty())
                     86:                        {
                     87:                                CChartData* ptr;
                     88:                                ptr = (CChartData*)m_pChartData->RemoveHead();
                     89:                                delete ptr;
                     90:                        }
                     91: 
                     92:                        // Delete all the list's pointers to the now deleted elements.
                     93:                        //
                     94:                        m_pChartData->RemoveAll();
                     95:                }
                     96:        }
                     97: }
                     98: 
                     99: /////////////////////////////////////////////////////////////////////////////
                    100: // CChartData
                    101: 
                    102: // CChartData is a data point for the chart.  It contains two fields.
                    103: // The height is the value of the data point and szName is the label
                    104: // for the data point.
                    105: 
                    106: IMPLEMENT_SERIAL(CChartData, CObject, 0)
                    107: 
                    108: // Serialize:
                    109: //
                    110: void CChartData::Serialize(CArchive& ar)
                    111: {
                    112:        // Serialize the base object first.
                    113:        //
                    114:        CObject::Serialize(ar);
                    115:        
                    116:        // Input or output our items to the archive.
                    117:        //
                    118:        if(ar.IsStoring())
                    119:        {
                    120:                ar << (WORD)height;
                    121:                ar << szName;
                    122:        }
                    123:        else
                    124:        {
                    125:                WORD tmp;
                    126:                CString name;
                    127:                ar >> tmp;
                    128:                height = (short)tmp;
                    129:                ar >> name;
                    130:                strcpy(szName,name);
                    131:        }
                    132: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.