Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC data structures

MFC data structures

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structuresquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    Hi all . Please tell me if I can integrate more object data types into a single MFC data structures ( Array , List or Map ). If I have an CStringArray object , let's say m_saType , ( CStringArray type ) , and m_saItem ( CStringArray type too ) , and m_saPerson ( CStringArray type too ) ... how can I integrate all togheter into CObList MFC object , because I want to serialize all m_saType, m_saItem, m_saPerson into a single file on disk. Thank you . I accept any ideea .

    A O 2 Replies Last reply
    0
    • _ _Flaviu

      Hi all . Please tell me if I can integrate more object data types into a single MFC data structures ( Array , List or Map ). If I have an CStringArray object , let's say m_saType , ( CStringArray type ) , and m_saItem ( CStringArray type too ) , and m_saPerson ( CStringArray type too ) ... how can I integrate all togheter into CObList MFC object , because I want to serialize all m_saType, m_saItem, m_saPerson into a single file on disk. Thank you . I accept any ideea .

      A Offline
      A Offline
      Alexandre GRANVAUD
      wrote on last edited by
      #2

      m_saType.Serialize(ar); m_saItem.Serialize(ar); m_saPerson.Serialize(ar); Of course a better way is to declare a CObject derived class CPerson with CString members m_sType, m_sItem, m_sPerson Implementing Serialize in this class the using a CObList and calling its Serialize...

      1 Reply Last reply
      0
      • _ _Flaviu

        Hi all . Please tell me if I can integrate more object data types into a single MFC data structures ( Array , List or Map ). If I have an CStringArray object , let's say m_saType , ( CStringArray type ) , and m_saItem ( CStringArray type too ) , and m_saPerson ( CStringArray type too ) ... how can I integrate all togheter into CObList MFC object , because I want to serialize all m_saType, m_saItem, m_saPerson into a single file on disk. Thank you . I accept any ideea .

        O Offline
        O Offline
        Ozer Karaagac
        wrote on last edited by
        #3

        #include class CDataPack : public CObject
        {
        public: // you can determine this access scope
        CStringArray m_saType;
        CStringArray m_saItem;
        CStringArray m_saPerson;

        const CDataPack& operator=(const CDataPack& rdp)
        {
        	m\_saType.Copy(rdp.m\_saType);
        	m\_saItem.Copy(rdp.m\_saItem);
        	m\_saPerson.Copy(rdp.m\_saPerson);
        	return \*this;
        }
        
        BOOL IsSerializable() const { return TRUE; }
        
        virtual void Serialize(CArchive& ar)
        {
        	m\_saType.Serialize(ar);
        	m\_saItem.Serialize(ar);
        	m\_saPerson.Serialize(ar);
        }
        

        };

        typedef CArray CDataPackType;

        void AnyFunc()
        {
        CString strElement(_T("An Element"));
        CDataPack pkt;

        pkt.m\_saType.Add(strElement);  // using public access
        pkt.m\_saItem.Add(strElement);
        pkt.m\_saPerson.Add(strElement);
        
        CDataPackType arrData;
        
        arrData.Add(pkt);
        
        CFile file; // TODO: you need to open the file
        CArchive ar(&file, CArchive::store);
        arrData.Serialize(ar);
        

        }

        If you don't want to use template counterpart, you can also use CObArray or even CPtrArray (or List ones such as CObList, CPtrList, see afxcoll.h). Just beware cleanup of objects.

        _ 1 Reply Last reply
        0
        • O Ozer Karaagac

          #include class CDataPack : public CObject
          {
          public: // you can determine this access scope
          CStringArray m_saType;
          CStringArray m_saItem;
          CStringArray m_saPerson;

          const CDataPack& operator=(const CDataPack& rdp)
          {
          	m\_saType.Copy(rdp.m\_saType);
          	m\_saItem.Copy(rdp.m\_saItem);
          	m\_saPerson.Copy(rdp.m\_saPerson);
          	return \*this;
          }
          
          BOOL IsSerializable() const { return TRUE; }
          
          virtual void Serialize(CArchive& ar)
          {
          	m\_saType.Serialize(ar);
          	m\_saItem.Serialize(ar);
          	m\_saPerson.Serialize(ar);
          }
          

          };

          typedef CArray CDataPackType;

          void AnyFunc()
          {
          CString strElement(_T("An Element"));
          CDataPack pkt;

          pkt.m\_saType.Add(strElement);  // using public access
          pkt.m\_saItem.Add(strElement);
          pkt.m\_saPerson.Add(strElement);
          
          CDataPackType arrData;
          
          arrData.Add(pkt);
          
          CFile file; // TODO: you need to open the file
          CArchive ar(&file, CArchive::store);
          arrData.Serialize(ar);
          

          }

          If you don't want to use template counterpart, you can also use CObArray or even CPtrArray (or List ones such as CObList, CPtrList, see afxcoll.h). Just beware cleanup of objects.

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          Thank you very much ! You are very kind ! And if gave me good ideas , I push my luck and ask more : which structure of collection data you choose if you want to clone 3 SQL tables , every one with one unique key integer type and other fiels is strings , but keep link between tables through those unique key integer ?

          O 1 Reply Last reply
          0
          • _ _Flaviu

            Thank you very much ! You are very kind ! And if gave me good ideas , I push my luck and ask more : which structure of collection data you choose if you want to clone 3 SQL tables , every one with one unique key integer type and other fiels is strings , but keep link between tables through those unique key integer ?

            O Offline
            O Offline
            Ozer Karaagac
            wrote on last edited by
            #5

            I think, you mean which collection class? If so, Array is more efficient on random access. I also think, you need to access the elements with Primary Keys/Forein Keys in master-detail relationships. If you need rows in sorted order, you can fill this array sorted. You can take advantage of SQL's SELECT with ORDER BY clause while filling. If the array is sorted, you can access its items by using binary search to speed up searches. If you just need to access items by the key, you can simply employ CMap to access its elements with key-value pair. typedef CMap<int, int, CDataPack, CDataPack&> CDataPackMap; You need to keep relationships yourself, or maybe, you may create more sophisticated structures. [edit]BTW, Not at all. :) [/edit]

            _ 1 Reply Last reply
            0
            • O Ozer Karaagac

              I think, you mean which collection class? If so, Array is more efficient on random access. I also think, you need to access the elements with Primary Keys/Forein Keys in master-detail relationships. If you need rows in sorted order, you can fill this array sorted. You can take advantage of SQL's SELECT with ORDER BY clause while filling. If the array is sorted, you can access its items by using binary search to speed up searches. If you just need to access items by the key, you can simply employ CMap to access its elements with key-value pair. typedef CMap<int, int, CDataPack, CDataPack&> CDataPackMap; You need to keep relationships yourself, or maybe, you may create more sophisticated structures. [edit]BTW, Not at all. :) [/edit]

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #6

              I think that CMap is most good ideea . Thanks again . Best wishes !

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups