home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / VISBUILD / RAPSHEET / CPPOV23 / ISUSREC.CPP < prev    next >
Text File  |  1995-05-14  |  17KB  |  523 lines

  1. //****************************************************************************
  2. // ISuspectRecord - C++ Source File (isusrec.cpp)                            *
  3. //                                                                           *
  4. // COPYRIGHT: Copyright (C) International Business Machines Corp., 1994,1995 *
  5. //                                                                           *
  6. // DISCLAIMER OF WARRANTIES:                                                 *
  7. //   The following [enclosed] code is sample code created by IBM             *
  8. //   Corporation.  This sample code is not part of any standard IBM product  *
  9. //   and is provided to you solely for the purpose of assisting you in the   *
  10. //   development of your applications.  The code is provided "AS IS",        *
  11. //   without warranty of any kind.  IBM shall not be liable for any damages  *
  12. //   arising out of your use of the sample code, even if they have been      *
  13. //   advised of the possibility of such damages.                             *
  14. //****************************************************************************
  15. //NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
  16. //
  17.  
  18. #include "isusrec.hpp"     // ISuspectRecord header file
  19.  
  20. #ifndef _ISTRING_
  21.   #include <istring.hpp>
  22. #endif
  23.  
  24. #ifndef _IRAP_
  25. #include <rap.h>
  26. #endif
  27.  
  28.  
  29. //******************************************************************
  30. // Manager Member Functions (constructors/destructor)
  31. //******************************************************************
  32.  
  33.  
  34. //******************************************************************************
  35. //  Default initialization of the record data IString is okay.
  36. //  Call IRecord's (superclass') constructor
  37. //******************************************************************************
  38. ISuspectRecord :: ISuspectRecord() : IRecord(), dMySize(sizeof(SUSPECT_STRUCT))
  39. {
  40.   dParentSize = size();
  41.   setSize( dParentSize + dMySize );            // pad with '\x00'
  42. }
  43.  
  44.  
  45. //******************************************************************************
  46. // Copy the passed in data string via IRecord's constructor
  47. //******************************************************************************
  48. ISuspectRecord :: ISuspectRecord ( const IString & stringData ) :
  49.                   IRecord (), dMySize(sizeof(SUSPECT_STRUCT))
  50. {
  51.   dParentSize = size();
  52.   setSize ( dParentSize + dMySize );           //truncate or pad as appropriate
  53.   *this = stringData.subString(1, size());
  54. }
  55.  
  56.  
  57. //******************************************************************************
  58. // Copy the passed in record data via IRecord's constructor
  59. //******************************************************************************
  60. ISuspectRecord :: ISuspectRecord ( const ISuspectRecord & aRecord ) :
  61.                   IRecord (), dMySize(sizeof(SUSPECT_STRUCT))
  62. {
  63.   dParentSize = size();
  64.   *this = aRecord;
  65.  
  66.   dParentSize = size();
  67.   *this = aRecord;
  68.  
  69.   //
  70.   //NOTE:  this record would have gotten set with the correct size
  71.   //       if had called the IRecord (aRecord) constructor, but
  72.   //       need to determine what dParentSize is (the assignment
  73.   //       operators need this info).
  74.   //
  75. }
  76.  
  77.  
  78. //******************************************************************************
  79. // The implementation IString is automatically deleted.             (destructor)
  80. //******************************************************************************
  81. ISuspectRecord :: ~ISuspectRecord()
  82. {
  83.   ;
  84. }
  85.  
  86. /*------------------------------------------------------------------------------
  87. | ISuspectRecord::asDebugInfo                                                  |
  88. |                                                                              |
  89. | Generate a string that identifies for debugging purposes what data           |
  90. | an ISuspectRecord instance contains.                                         |
  91. |                                                                              |
  92. ------------------------------------------------------------------------------*/
  93. IString ISuspectRecord :: asDebugInfo () const
  94. {
  95.   IString debugInfo("size=" + IString(dMySize) + ",");
  96.   debugInfo += "bookNum=" + IString(bookNumber()) + ",";
  97.   debugInfo += "lName=" + lastName() + ",";
  98.   debugInfo += "fName=" + firstName() + ",";
  99.   debugInfo += "eyeColor=" + IString(eyeColor()) + ",";
  100.   debugInfo += "gender=" + IString(gender()) + ",";
  101.   debugInfo += "hairColor=" + IString(hairColor()) + ",";
  102.   debugInfo += "height=" + IString(height()) + ",";
  103.   debugInfo += "weight=" + IString(weight()) + ",";
  104.   debugInfo += "mugLeft=" + IString(mugLeft()) + ",";
  105.   debugInfo += "mugFront=" + IString(mugFront()) + ",";
  106.   debugInfo += "mugRight=" + IString(mugRight()) + ",";
  107.   debugInfo += "hasMole=" + IString(hasMole()) + ",";
  108.   debugInfo += "hasScar=" + IString(hasScar()) + ",";
  109.   debugInfo += "hasTattoo=" + IString(hasTattoo()) + ",";
  110.   debugInfo += "bdate=" + birthDate() + ",";
  111.   debugInfo += "street=" + street() + ",";
  112.   debugInfo += "city=" + city() + ",";
  113. //debugInfo += "county=" + county() + ",";
  114.   debugInfo += "state=" + state() + ",";
  115.   debugInfo += "zip=" + zip() + ".";
  116.  
  117.   return debugInfo;
  118. }
  119.  
  120. /*********************************************************************************
  121.  * Access Member Functions
  122.  *********************************************************************************/
  123.  
  124. //**************************
  125. // suspect last name
  126. //**************************
  127. IString ISuspectRecord :: lastName () const
  128. {
  129.   IString buffer;
  130.   return field(buffer, offsetof(SUSPECT_STRUCT, lastName)+1, LAST_NAME_LEN);   //pad with NULLs
  131. }
  132.  
  133. ISuspectRecord & ISuspectRecord :: setLastName (const IString & aSuspectLastName)
  134. {
  135.   setField(aSuspectLastName, offsetof(SUSPECT_STRUCT, lastName)+1, LAST_NAME_LEN);   //pad with NULLs
  136.   return *this;
  137. }
  138.  
  139. //**************************
  140. // suspect first name
  141. //**************************
  142. IString ISuspectRecord :: firstName () const
  143. {
  144.   IString buffer;
  145.   return field(buffer, offsetof(SUSPECT_STRUCT, firstName)+1, FIRST_NAME_LEN);   //pad with NULLs
  146. }
  147.  
  148. ISuspectRecord & ISuspectRecord :: setFirstName (const IString & aSuspectFirstName)
  149. {
  150.   setField(aSuspectFirstName, offsetof(SUSPECT_STRUCT, firstName)+1, FIRST_NAME_LEN);   //pad with NULLs
  151.   return *this;
  152. }
  153.  
  154. //**************************
  155. // suspect street
  156. //**************************
  157. IString ISuspectRecord :: street() const
  158. {
  159.   IString buffer;
  160.   return field(buffer, offsetof(SUSPECT_STRUCT, street)+1, ADDRESS_STREET_LEN);   //pad with NULLs
  161. }
  162.  
  163. ISuspectRecord & ISuspectRecord :: setStreet(const IString & aSuspectStreet)
  164. {
  165.   setField(aSuspectStreet, offsetof(SUSPECT_STRUCT, street)+1, ADDRESS_STREET_LEN);   //pad with NULLs
  166.   return *this;
  167. }
  168.  
  169. //**************************
  170. // suspect city
  171. //**************************
  172. IString ISuspectRecord :: city() const
  173. {
  174.   IString buffer;
  175.   return field(buffer, offsetof(SUSPECT_STRUCT, city)+1, ADDRESS_CITY_LEN);   //pad with NULLs
  176. }
  177.  
  178. ISuspectRecord & ISuspectRecord :: setCity(const IString & aSuspectCity)
  179. {
  180.   setField(aSuspectCity, offsetof(SUSPECT_STRUCT, city)+1, ADDRESS_CITY_LEN);   //pad with NULLs
  181.   return *this;
  182. }
  183.  
  184. //**************************
  185. // suspect county
  186. //**************************
  187. IString ISuspectRecord :: county() const
  188. {
  189.   IString buffer;
  190.   return field(buffer, offsetof(SUSPECT_STRUCT, county)+1, ADDRESS_COUNTY_LEN);   //pad with NULLs
  191. }
  192.  
  193. ISuspectRecord & ISuspectRecord :: setCounty(const IString & aSuspectCounty)
  194. {
  195.   setField(aSuspectCounty, offsetof(SUSPECT_STRUCT, county)+1, ADDRESS_COUNTY_LEN);   //pad with NULLs
  196.   return *this;
  197. }
  198.  
  199. //**************************
  200. // suspect state
  201. //**************************
  202. IString ISuspectRecord :: state() const
  203. {
  204.   IString buffer;
  205.   return field(buffer, offsetof(SUSPECT_STRUCT, state)+1, ADDRESS_STATE_LEN);   //pad with NULLs
  206. }
  207.  
  208. ISuspectRecord & ISuspectRecord :: setState(const IString & aSuspectState)
  209. {
  210.   setField(aSuspectState, offsetof(SUSPECT_STRUCT, state)+1, ADDRESS_STATE_LEN);   //pad with NULLs
  211.   return *this;
  212. }
  213.  
  214. //**************************
  215. // suspect zip
  216. //**************************
  217. IString ISuspectRecord :: zip() const
  218. {
  219.   IString buffer;
  220.   return field(buffer, offsetof(SUSPECT_STRUCT, zip)+1, ADDRESS_ZIP_LEN);   //pad with NULLs
  221. }
  222.  
  223. ISuspectRecord & ISuspectRecord :: setZip(const IString & aSuspectZip)
  224. {
  225.   setField(aSuspectZip, offsetof(SUSPECT_STRUCT, zip)+1, ADDRESS_ZIP_LEN);   //pad with NULLs
  226.   return *this;
  227. }
  228.  
  229. //**************************
  230. // suspect description
  231. //**************************
  232. IString ISuspectRecord :: description() const
  233. {
  234.   IString buffer;
  235.   return field(buffer, offsetof(SUSPECT_STRUCT, info)+1, SUSPECT_INFO_LEN);   //pad with NULLs
  236. }
  237.  
  238. ISuspectRecord & ISuspectRecord :: setDescription(const IString & aSuspectInfo)
  239. {
  240.   setField(aSuspectInfo, offsetof(SUSPECT_STRUCT, info)+1, SUSPECT_INFO_LEN);   //pad with NULLs
  241.   return *this;
  242. }
  243.  
  244. //**************************
  245. // suspect book Number
  246. //**************************
  247. unsigned long ISuspectRecord :: bookNumber() const
  248. {
  249.    unsigned long buffer;
  250.    return field(buffer, offsetof(SUSPECT_STRUCT, book_number)+1);
  251. }
  252.  
  253. ISuspectRecord & ISuspectRecord :: setBookNumber(unsigned long aSuspectBookNumber)
  254. {
  255.    setField(aSuspectBookNumber, offsetof(SUSPECT_STRUCT, book_number)+1);
  256.    return *this;
  257. }
  258.  
  259. //**************************
  260. // suspect gender
  261. //**************************
  262. unsigned short ISuspectRecord :: gender() const
  263. {
  264.    unsigned short buffer;
  265.    return field(buffer, offsetof(SUSPECT_STRUCT, gender)+1);
  266. }
  267.  
  268. ISuspectRecord & ISuspectRecord :: setGender(unsigned short aSuspectGender)
  269. {
  270.    setField(aSuspectGender, offsetof(SUSPECT_STRUCT, gender)+1);
  271.    return *this;
  272. }
  273.  
  274. //**************************
  275. // suspect height
  276. //**************************
  277. unsigned short ISuspectRecord :: height() const
  278. {
  279.    unsigned short buffer;
  280.    return field(buffer, offsetof(SUSPECT_STRUCT, height)+1);
  281. }
  282.  
  283. ISuspectRecord & ISuspectRecord :: setHeight(unsigned short aSuspectHeight)
  284. {
  285.    setField(aSuspectHeight, offsetof(SUSPECT_STRUCT, height)+1);
  286.    return *this;
  287. }
  288.  
  289. //**************************
  290. // suspect weight
  291. //**************************
  292. unsigned short ISuspectRecord :: weight() const
  293. {
  294.    unsigned short buffer;
  295.    return field(buffer, offsetof(SUSPECT_STRUCT, weight)+1);
  296. }
  297. ISuspectRecord & ISuspectRecord :: setWeight(unsigned short aSuspectWeight)
  298. {
  299.    setField(aSuspectWeight, offsetof(SUSPECT_STRUCT, weight)+1);
  300.    return *this;
  301. }
  302.  
  303. //**************************
  304. // suspect hair color
  305. //**************************
  306. unsigned short ISuspectRecord :: hairColor() const
  307. {
  308.    unsigned short buffer;
  309.    return field(buffer, offsetof(SUSPECT_STRUCT, hairColor)+1);
  310. }
  311.  
  312. ISuspectRecord & ISuspectRecord :: setHairColor(unsigned short aSuspectHairColor)
  313. {
  314.    setField(aSuspectHairColor, offsetof(SUSPECT_STRUCT, hairColor)+1);
  315.    return *this;
  316. }
  317.  
  318. //**************************
  319. // suspect eye color
  320. //**************************
  321. unsigned short ISuspectRecord :: eyeColor() const
  322. {
  323.    unsigned short buffer;
  324.    return field(buffer, offsetof(SUSPECT_STRUCT, eyeColor)+1);
  325. }
  326.  
  327. ISuspectRecord & ISuspectRecord :: setEyeColor(unsigned short aSuspectEyeColor)
  328. {
  329.    setField(aSuspectEyeColor, offsetof(SUSPECT_STRUCT, eyeColor)+1);
  330.    return *this;
  331. }
  332.  
  333. //**************************
  334. // suspect has mole
  335. //**************************
  336. unsigned short ISuspectRecord :: hasMole() const
  337. {
  338.    unsigned short buffer;
  339.    return field(buffer, offsetof(SUSPECT_STRUCT, hasMole)+1);
  340. }
  341.  
  342. ISuspectRecord & ISuspectRecord :: enableHasMole(unsigned short suspectHasMole)
  343. {
  344.    setField(suspectHasMole, offsetof(SUSPECT_STRUCT, hasMole)+1);
  345.    return *this;
  346. }
  347.  
  348. //**************************
  349. // suspect has scar
  350. //**************************
  351. unsigned short ISuspectRecord :: hasScar() const
  352. {
  353.    unsigned short buffer;
  354.    return field(buffer, offsetof(SUSPECT_STRUCT, hasScar)+1);
  355. }
  356. ISuspectRecord & ISuspectRecord :: enableHasScar(unsigned short suspectHasScar) 
  357. {
  358.    setField(suspectHasScar, offsetof(SUSPECT_STRUCT, hasScar)+1);
  359.    return *this;
  360. }
  361.  
  362. //**************************
  363. // suspect has tattoo
  364. //**************************
  365. unsigned short ISuspectRecord :: hasTattoo() const
  366. {
  367.    unsigned short buffer;
  368.    return field(buffer, offsetof(SUSPECT_STRUCT, hasTattoo)+1);
  369. }
  370. ISuspectRecord & ISuspectRecord :: enableHasTattoo(unsigned short suspectHasTattoo)
  371. {
  372.    setField(suspectHasTattoo, offsetof(SUSPECT_STRUCT, hasTattoo)+1);
  373.    return *this;
  374. }
  375.  
  376. //**************************
  377. // suspect mug front
  378. //**************************
  379. unsigned short ISuspectRecord :: mugFront() const
  380. {
  381.    unsigned short buffer;
  382.    return field(buffer, offsetof(SUSPECT_STRUCT, mugFront)+1);
  383. }
  384.  
  385. ISuspectRecord & ISuspectRecord :: setMugFront(unsigned short aSuspectMugFront)
  386. {
  387.    setField(aSuspectMugFront, offsetof(SUSPECT_STRUCT, mugFront)+1);
  388.    return *this;
  389. }
  390.  
  391. //**************************
  392. // suspect mug right
  393. //**************************
  394. unsigned short ISuspectRecord :: mugRight() const
  395. {
  396.    unsigned short buffer;
  397.    return field(buffer, offsetof(SUSPECT_STRUCT, mugRight)+1);
  398. }
  399. ISuspectRecord & ISuspectRecord :: setMugRight(unsigned short aSuspectMugRight)
  400. {
  401.    setField(aSuspectMugRight, offsetof(SUSPECT_STRUCT, mugRight)+1);
  402.    return *this;
  403. }
  404.  
  405. //**************************
  406. // suspect mug left
  407. //**************************
  408. unsigned short ISuspectRecord :: mugLeft() const
  409. {
  410.    unsigned short buffer;
  411.    return field(buffer, offsetof(SUSPECT_STRUCT, mugLeft)+1);
  412. }
  413.  
  414. ISuspectRecord & ISuspectRecord :: setMugLeft(unsigned short aSuspectMugLeft)
  415. {
  416.    setField(aSuspectMugLeft, offsetof(SUSPECT_STRUCT, mugLeft)+1);
  417.    return *this;
  418. }
  419.  
  420. //**************************
  421. // suspect birthdate
  422. //**************************
  423. IString ISuspectRecord :: birthDate() const
  424. {
  425.   IString buffer;
  426.   return field(buffer, offsetof(SUSPECT_STRUCT, birthDate)+1, DATE_LEN); //pad with NULLs
  427. }
  428.  
  429. ISuspectRecord & ISuspectRecord :: setBirthDate(const IString & aSuspectBirthDate)
  430. {
  431.   setField(aSuspectBirthDate, offsetof(SUSPECT_STRUCT, birthDate)+1, DATE_LEN);   //pad with NULLs return *this;
  432.   return *this;
  433. }
  434.  
  435. //**************************
  436. // suspect mo
  437. //**************************
  438. IString ISuspectRecord :: MO() const
  439. {
  440.   IString buffer;
  441.   return field(buffer, offsetof(SUSPECT_STRUCT, MO)+1, SUSPECT_MO_DESC_LEN);   //pad with NULLs
  442. }
  443.  
  444. ISuspectRecord & ISuspectRecord :: setMO(const IString & aSuspectMO)
  445. {
  446.   setField(aSuspectMO, offsetof(SUSPECT_STRUCT, MO)+1, SUSPECT_MO_DESC_LEN);   //pad with NULLs
  447.   return *this;
  448. }
  449.  
  450. //**************************
  451. // suspect mole description
  452. //**************************
  453. IString ISuspectRecord :: moleDescription() const
  454. {
  455.   IString buffer;
  456.   return field(buffer, offsetof(SUSPECT_STRUCT, moleDescription)+1, SUSPECT_TRAIT_DESC_LEN); //pad with NULLs
  457. }
  458.  
  459. ISuspectRecord & ISuspectRecord :: setMoleDescription(const IString & aSuspectMoleDescription)
  460. {
  461.   setField(aSuspectMoleDescription, offsetof(SUSPECT_STRUCT, moleDescription)+1, SUSPECT_TRAIT_DESC_LEN); //pad with NULLs
  462.   return *this;
  463. }
  464.  
  465. //**************************
  466. // suspect scar description
  467. //**************************
  468. IString ISuspectRecord :: scarDescription() const
  469. {
  470.   IString buffer;
  471.   return field(buffer, offsetof(SUSPECT_STRUCT, scarDescription)+1, SUSPECT_TRAIT_DESC_LEN); //pad with NULLs
  472. }
  473.  
  474. ISuspectRecord & ISuspectRecord :: setScarDescription(const IString & aSuspectScarDescription)
  475. {
  476.   setField(aSuspectScarDescription, offsetof(SUSPECT_STRUCT, scarDescription)+1, SUSPECT_TRAIT_DESC_LEN); //pad with NULLs
  477.   return *this;
  478. }
  479.  
  480. //**************************
  481. // suspect tattoo description
  482. //**************************
  483. IString ISuspectRecord :: tattooDescription() const
  484. {
  485.   IString buffer;
  486.   return field(buffer, offsetof(SUSPECT_STRUCT, tattooDescription)+1, SUSPECT_TRAIT_DESC_LEN); //pad with NULLs
  487. }
  488.  
  489. ISuspectRecord & ISuspectRecord :: setTattooDescription(const IString & aSuspectTattooDescription)
  490. {
  491.   setField(aSuspectTattooDescription, offsetof(SUSPECT_STRUCT, tattooDescription)+1, SUSPECT_TRAIT_DESC_LEN); //pad with NULLs
  492.   return *this;
  493. }
  494.  
  495.  
  496. /*******************************************************************
  497.  * Implementor Member Functions
  498.  *******************************************************************/
  499. /*------------------------------------------------------------------------------
  500. | Function Name: ISuspectRecord :: operator =
  501. |
  502. | Implementation:
  503. |   Replace our data with the source ISuspectRecord data.
  504. ------------------------------------------------------------------------------*/
  505. ISuspectRecord & ISuspectRecord :: operator = ( const ISuspectRecord & aRecord )
  506. {
  507.   IRecord::operator=(aRecord);
  508.   return( *this );
  509. }
  510.  
  511. /*------------------------------------------------------------------------------
  512. | Function Name: ISuspectRecord :: operator =
  513. |
  514. | Implementation:
  515. |   Replace our data with the source IString data.
  516. ------------------------------------------------------------------------------*/
  517. ISuspectRecord & ISuspectRecord :: operator = ( const IString & aString )
  518. {
  519.   IRecord::operator=(aString);
  520.   setSize (dParentSize + dMySize);
  521.   return( *this );
  522. }
  523.