1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
|
#include "stdafx.h"
#include "CSToBOMProc.h"
CCSToBOM_Proc::CCSToBOM_Proc()
{
// Constructor Does nothing
}
CCSToBOM_Proc::~CCSToBOM_Proc()
{
// Destructor does nothing
}
void CCSToBOM_Proc::AddRef(CString addRef, CString addPart, CString Height)
{
CCSToBOM_RefObj *myObj ;
myObj = new CCSToBOM_RefObj;
myObj->RefName = addRef;
myObj->PartName = addPart;
myObj->Height = Height;
// Try insert way
//m_RefObj.insert( m_RefObj.end( ), *myObj);
this->m_RefObj.push_back( *myObj );
/* // some debug stuff
char buf[1024];
std::vector<class CCSToBOM_RefObj>::size_type m;
m = m_RefObj.size( );
CFile fileTmp("C:\\tmp.txt", CFile::modeWrite);
fileTmp.SeekToEnd();
sprintf(buf, " Ref size=%d \r\n\r\n", m );
fileTmp.Write(buf, strlen(buf));
fileTmp.Close();
*/
// Delete original object as it's been put in the vector.
delete (myObj);
}
void CCSToBOM_Proc::AddAttrib(CString addType, CString addValue)
{
// Reference an itterator to the end of the REF components, note -1 as the end is a place holder for a new component in the list
std::vector<class CCSToBOM_RefObj>::const_iterator i=this->m_RefObj.end() - 1;
CCSToBOM_RefObj RefObj = *i;
// Create a new structure of the attribute class
CCSToBOM_AttribObj *myObjAtt = new CCSToBOM_AttribObj;
myObjAtt->AttribType = addType;
myObjAtt->AttribValue = addValue;
// Don't think this line works as .Size returns just 1, never increments ???
RefObj.m_AttribObj.push_back( *myObjAtt );
// Try insert way.
// Create an itterator for the end of the attribte list
//std::vector<class CCSToBOM_AttribObj>::iterator n=RefObj.m_AttribObj.end();
// Insert new data into the list at the end.
//RefObj.m_AttribObj.insert( n, *myObjAtt);
//RefObj.m_AttribObj.insert(RefObj.m_AttribObj.end(), *myObjAtt);
/*
// Some debug, size does not increas, stuck at one
char buf[1024];
std::vector<class CCSToBOM_AttribObj>::size_type m;
m = RefObj.m_AttribObj.size( );
CFile fileTmp("C:\\tmp.txt", CFile::modeWrite);
fileTmp.SeekToEnd();
////sprintf(buf, "RefObj=%d Attr=%d type=%s value=%s size=%d \r\n", RefObj, RefObj.m_AttribObj, addType, addValue , m );
//sprintf(buf, "type=%s value=%s ", addType, addValue );
//fileTmp.Write(buf, strlen(buf));
//sprintf(buf, "RefObj=%d Attr=%d ", RefObj, RefObj.m_AttribObj );
//fileTmp.Write(buf, strlen(buf));
sprintf(buf, "Ref=%s ", RefObj.RefName );
fileTmp.Write(buf, strlen(buf));
sprintf(buf, "size=%d \r\n\r\n", m );
fileTmp.Write(buf, strlen(buf));
fileTmp.Close();
*/
// Delete the tmp structure as it's in the list now.
delete (myObjAtt);
}
void CCSToBOM_Proc::Save(CFile *file)
{
//int i;
char buf[1024];
// Loop round the references printing out the parts.
std::vector<class CCSToBOM_RefObj>::const_iterator i=m_RefObj.begin();
for (; i!=m_RefObj.end(); i++)
{
CCSToBOM_RefObj RefObj = *i;
sprintf(buf, "%s, ", RefObj.RefName);
file->Write(buf, strlen(buf));
sprintf(buf, "%s, ", RefObj.PartName);
file->Write(buf, strlen(buf));
// Walk through the attributes in the list.
std::vector<class CCSToBOM_AttribObj>::const_iterator n=RefObj.m_AttribObj.begin();
for (; n!=RefObj.m_AttribObj.end(); n++)
{
CCSToBOM_AttribObj AttribObj = *n;
sprintf(buf, "%s(%s), ", AttribObj.AttribType, AttribObj.AttribValue );
file->Write(buf, strlen(buf));
}
file->Write("\r\n", 2);
}
}
CCSToBOM_RefObj::CCSToBOM_RefObj()
{
// Constructor
}
CCSToBOM_RefObj::~CCSToBOM_RefObj()
{
// Destructor
}
CCSToBOM_AttribObj::CCSToBOM_AttribObj()
{
// Constructor
}
CCSToBOM_AttribObj::~CCSToBOM_AttribObj()
{
// Destructor
}
|