Garmin Fleet Management Controller  2.19.0
DriverLoginItem.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * DriverLoginItem.cpp
5 *
6 * Copyright 2009-2012 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include "DriverLoginItem.h"
13 
14 //----------------------------------------------------------------------
16 //----------------------------------------------------------------------
18  : mParent( NULL )
19 {
20 
21 }
22 
23 //----------------------------------------------------------------------
25 //----------------------------------------------------------------------
27 {
28 }
29 
30 //----------------------------------------------------------------------
33 //----------------------------------------------------------------------
35 {
36  CString driverId;
37  TCHAR tcharName[50];
38  MultiByteToWideChar( CP_UTF8, 0, mDriverId.c_str(), -1, tcharName, 50 );
39  driverId.SetString( tcharName );
40 
41  return driverId;
42 }
43 
44 //----------------------------------------------------------------------
48 //----------------------------------------------------------------------
50 {
51  return mDriverId;
52 }
53 
54 //----------------------------------------------------------------------
57 //----------------------------------------------------------------------
59 {
60  CString driverPassword;
61  TCHAR tcharName[50];
62  MultiByteToWideChar( CP_UTF8, 0, mDriverPassword.c_str(), -1, tcharName, 50 );
63  driverPassword.SetString( tcharName );
64 
65  return driverPassword;
66 }
67 
68 //----------------------------------------------------------------------
73 //----------------------------------------------------------------------
75  (
76  std::istream &aStream
77  )
78 {
79  char temp;
80 
81  mDriverId.clear();
82  while( aStream.peek() != '\0' && !aStream.eof() )
83  {
84  aStream.read( &temp, 1 );
85  mDriverId.append( 1, temp );
86  }
87 
88  aStream.get(); // consume the '\0' inserted between mDriverId and mPassword
89 
90  mDriverPassword.clear();
91  while( aStream.peek() != '\n' && !aStream.eof() )
92  {
93  aStream.read( &temp, 1 );
94  mDriverPassword.append( 1, temp );
95  }
96 
97  aStream.get(); // consume the '\n' inserted after mPassword
98 
99  if( !aStream.eof() )
100  {
101  mIsValid = TRUE;
102  }
103 }
104 
105 //----------------------------------------------------------------------
108 //----------------------------------------------------------------------
110 {
111  if( mParent )
112  {
113  mParent->save();
114  }
115 }
116 
117 //----------------------------------------------------------------------
121 //----------------------------------------------------------------------
123  (
124  const key_type & aId
125  )
126 {
127  mDriverId = aId;
128 }
129 
130 //----------------------------------------------------------------------
134 //----------------------------------------------------------------------
136  (
138  )
139 {
140  mParent = aParent;
141 }
142 
143 //----------------------------------------------------------------------
147 //----------------------------------------------------------------------
149  (
150  const std::string & aPassword
151  )
152 {
153  mDriverPassword = aPassword;
154 
155  setValid();
156 }
157 
158 //----------------------------------------------------------------------
162 //----------------------------------------------------------------------
164  (
165  std::ofstream &aStream
166  ) const
167 {
168  aStream << mDriverId << '\0' << mDriverPassword << '\n';
169 }
void save()
Save this item.
CString getDriverId() const
Get the driver ID as a CString.
FileBackedMap< DriverLoginItem > * mParent
The map that this DriverLoginItem is a part of.
std::string mDriverId
The driver ID, UTF8 encoded.
void writeToStream(std::ofstream &aStream) const
Write a DriverLoginItem to an output stream.
void setValid(BOOL aValid=TRUE)
Set this item as valid.
void setParent(FileBackedMap< DriverLoginItem > *aParent)
Set the parent map of this item.
#define TRUE
Definition: garmin_types.h:45
DriverLoginItem()
Constructor.
uint32 key_type
key type
std::string key_type
void readFromStream(std::istream &aStream)
Read a DriverLoginItem from an input stream.
BOOL mIsValid
True if this list item is mIsValid.
void setId(const key_type &aId)
Set the ID (key) of this item.
std::string mDriverPassword
The driver password, UTF8 encoded.
CString getPassword() const
Set the ID (key) of this item.
const key_type & getId() const
Get item&#39;s ID.
void save()
Save the map to disk.
void setPassword(const std::string &aPassword)
Set the password of this driver.
virtual ~DriverLoginItem()
Destructor.