~ubuntu-branches/ubuntu/gutsy/libcorelinux/gutsy

« back to all changes in this revision

Viewing changes to src/testdrivers/ex18/UpperCaseCommand.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2001-12-29 17:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20011229174334-ejlsuilsiro5vmzr
Tags: 0.4.32-4
* fix config.{guess,sub} out of date on hppa and s390 (closes: #124296,#121830)
* try to be more descriptive in the description of the package  (closes: #115758)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  CoreLinux++ 
 
3
  Copyright (C) 2000 CoreLinux Consortium
 
4
  
 
5
   The CoreLinux++ Library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public License as
 
7
   published by the Free Software Foundation; either version 2 of the
 
8
   License, or (at your option) any later version.
 
9
 
 
10
   The CoreLinux++ Library Library is distributed in the hope that it will 
 
11
   be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public
 
16
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
 
17
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
   Boston, MA 02111-1307, USA.  
 
19
*/   
 
20
 
 
21
 
 
22
#if   !defined(__COMMON_HPP)
 
23
#include <corelinux/Common.hpp>
 
24
#endif
 
25
 
 
26
#if   !defined(__UPPERCASECOMMAND_HPP)
 
27
#include <UpperCaseCommand.hpp>
 
28
#endif
 
29
 
 
30
#if   !defined(__RESTORECASECOMMAND_HPP)
 
31
#include <RestoreCaseCommand.hpp>
 
32
#endif
 
33
 
 
34
using namespace corelinux;
 
35
 
 
36
// Default constructor
 
37
 
 
38
UpperCaseCommand::UpperCaseCommand( void )
 
39
   throw ( Assertion )
 
40
   :
 
41
   Command(),
 
42
   theOriginalValue( NULLPTR ),
 
43
   theNewValue( NULLPTR )
 
44
{
 
45
   NEVER_GET_HERE;
 
46
}
 
47
 
 
48
// Proper constructor
 
49
 
 
50
UpperCaseCommand::UpperCaseCommand( const std::string & aValue )
 
51
   :
 
52
   Command(),
 
53
   theOriginalValue( new std::string(aValue) ),
 
54
   theNewValue( new std::string("") )
 
55
{
 
56
   ;  // do nothing
 
57
}
 
58
 
 
59
// Copy constructor
 
60
 
 
61
UpperCaseCommand::UpperCaseCommand( UpperCaseCommandCref aUpCaseCmd )
 
62
   :
 
63
   Command( aUpCaseCmd ),
 
64
   theOriginalValue( new std::string(aUpCaseCmd.getOriginalValue()) ),
 
65
   theNewValue( new std::string("") )
 
66
{
 
67
   ;  // do nothing
 
68
}
 
69
 
 
70
// Destructor
 
71
 
 
72
UpperCaseCommand::~UpperCaseCommand( void )
 
73
{
 
74
   if( theOriginalValue != NULLPTR )
 
75
   {
 
76
      delete theOriginalValue;
 
77
      theOriginalValue = NULLPTR;
 
78
   }
 
79
   else
 
80
   {
 
81
      ;  // do nothing
 
82
   }
 
83
 
 
84
   if( theNewValue != NULLPTR )
 
85
   {
 
86
      delete theNewValue;
 
87
      theNewValue = NULLPTR;
 
88
   }
 
89
   else
 
90
   {
 
91
      ;  // do nothing
 
92
   }
 
93
}
 
94
 
 
95
// Assignment operator
 
96
 
 
97
UpperCaseCommandRef UpperCaseCommand::operator=
 
98
   ( 
 
99
      UpperCaseCommandCref aUpCaseCmd 
 
100
   )
 
101
{
 
102
   if( *this == aUpCaseCmd )
 
103
   {
 
104
      ;  // do nothing, its us
 
105
   }
 
106
   else
 
107
   {
 
108
      *theOriginalValue = aUpCaseCmd.getOriginalValue() ;
 
109
      *theNewValue = "";
 
110
   }
 
111
 
 
112
   return (*this);
 
113
}
 
114
 
 
115
// Equality operator
 
116
 
 
117
bool UpperCaseCommand::operator==( UpperCaseCommandCref aUpCaseCmd ) const
 
118
{
 
119
   return ( this == &aUpCaseCmd );
 
120
}
 
121
 
 
122
// Access for original
 
123
 
 
124
const std::string &  UpperCaseCommand::getOriginalValue( void ) const
 
125
{
 
126
   return *theOriginalValue;
 
127
}
 
128
 
 
129
// Access for results
 
130
 
 
131
const std::string &  UpperCaseCommand::getNewValue( void ) const
 
132
{
 
133
   return *theNewValue;
 
134
}
 
135
 
 
136
void  UpperCaseCommand::setReverseCommand( AbstractCommandPtr aCmdPtr )
 
137
{
 
138
   if( dynamic_cast<RestoreCaseCommandPtr>(aCmdPtr) != NULLPTR )
 
139
   {
 
140
      dynamic_cast<RestoreCaseCommandPtr>(aCmdPtr)->setValues
 
141
         ( 
 
142
            &theOriginalValue, 
 
143
            &theNewValue 
 
144
         );
 
145
   }
 
146
   else
 
147
   {
 
148
      ;  // do nothing
 
149
   }
 
150
 
 
151
   Command::setReverseCommand( aCmdPtr );
 
152
}
 
153
 
 
154
// Do the work
 
155
 
 
156
void  UpperCaseCommand::execute( void ) 
 
157
{
 
158
   size_t   len = theOriginalValue->length();
 
159
 
 
160
   *theNewValue = "";
 
161
   if( len != 0 )
 
162
   {
 
163
      for( size_t x = 0; x < len; ++x )
 
164
      {
 
165
         *theNewValue += toupper((*theOriginalValue)[x]);
 
166
      }
 
167
   }
 
168
   else
 
169
   {
 
170
      ; // do nothing
 
171
   }
 
172
}
 
173
 
 
174
/*
 
175
   Common rcs information do not modify
 
176
   $Author: frankc $
 
177
   $Revision: 1.1 $
 
178
   $Date: 2000/05/04 05:41:59 $
 
179
   $Locker:  $
 
180
*/
 
181