MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
common.cpp
1 /*
2  Copyright (C) 2003-2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 
20 #include "common.hpp"
21 
22 NdbOut &
23 operator << (NdbOut & out, const Employee_t & emp){
24  out << emp.EmpNo << " \"" << emp.FirstName << "\" \""
25  << emp.LastName << "\"";
26  return out;
27 }
28 
29 bool
30 operator==(const Employee_t & e1, const Employee_t & e2){
31  if(e1.EmpNo != e2.EmpNo)
32  return false;
33  if(strcmp(e1.FirstName, e2.FirstName) != 0)
34  return false;
35  return strcmp(e1.LastName, e2.LastName) == 0;
36 }
37 
38 void
39 Alter(Employee_t & emp){
40  static int updown = 0;
41  if(updown == 0){
42  for(int i = 0; i<strlen(emp.FirstName); i++)
43  toupper(emp.FirstName[i]);
44 
45  for(int i = 0; i<strlen(emp.LastName); i++)
46  toupper(emp.LastName[i]);
47  } else {
48  for(int i = 0; i<strlen(emp.FirstName); i++)
49  tolower(emp.FirstName[i]);
50 
51  for(int i = 0; i<strlen(emp.LastName); i++)
52  tolower(emp.LastName[i]);
53  }
54  updown = 1 - updown;
55 }
56 
57 void
58 CompareRows(Employee_t * data1,
59  int rows,
60  Employee_t * data2){
61  for(int i = 0; i<rows; i++){
62  if(!(data1[i] == data2[i])){
63  ndbout << data1[i] << endl
64  << data2[i] << endl;
65  }
66  }
67 }
68 
69 void
70 AlterRows(Employee_t * data1, int rows){
71  for(int i = 0; i<rows; i++){
72  Alter(data1[i]);
73  }
74 }
75 
76 inline
77 NdbOut &
78 operator << (NdbOut & out, const Address_t & adr){
79  out << adr.EmpNo << " \"" << adr.StreetName << "\" "
80  << adr.StreetNo << " \"" << adr.City << "\"";
81  return out;
82 }
83 
84 inline
85 bool
86 operator==(const Address_t & a1, const Address_t & a2){
87  if(a1.EmpNo != a2.EmpNo)
88  return false;
89  if(a1.StreetNo != a2.StreetNo)
90  return false;
91  if(strcmp(a1.StreetName, a2.StreetName) != 0)
92  return false;
93  return strcmp(a1.City, a2.City) == 0;
94 }
95 
96 inline
97 void
98 Alter(Address_t & emp){
99  static int updown = 0;
100  if(updown == 0){
101  for(int i = 0; i<strlen(emp.StreetName); i++)
102  toupper(emp.StreetName[i]);
103 
104  for(int i = 0; i<strlen(emp.City); i++)
105  toupper(emp.City[i]);
106  } else {
107  for(int i = 0; i<strlen(emp.StreetName); i++)
108  tolower(emp.StreetName[i]);
109 
110  for(int i = 0; i<strlen(emp.City); i++)
111  tolower(emp.City[i]);
112  }
113  emp.StreetNo *= emp.EmpNo;
114  updown = 1 - updown;
115 }
116 
117 void
118 CompareRows(Address_t * data1,
119  int rows,
120  Address_t * data2){
121  for(int i = 0; i<rows; i++){
122  if(!(data1[i] == data2[i])){
123  ndbout << data1[i] << endl
124  << data2[i] << endl;
125  }
126  }
127 }
128 
129 void
130 AlterRows(Address_t * data1, int rows){
131  for(int i = 0; i<rows; i++){
132  Alter(data1[i]);
133  }
134 }
135