Skip to content

Commit 48790d4

Browse files
author
jason_yao
committed
update
1 parent 56acd49 commit 48790d4

580 files changed

Lines changed: 22214 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Binary file not shown.
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef _HFDP_CPP_ADAPTER_DUCK_HPP_
2+
#define _HFDP_CPP_ADAPTER_DUCK_HPP_
3+
4+
#include "Ducks.hpp"
5+
6+
namespace HeadFirstDesignPatterns {
7+
namespace Adapter {
8+
namespace Ducks {
9+
10+
class Duck {
11+
12+
public: virtual ~Duck() = 0 {
13+
}
14+
public: virtual void fly() const = 0;
15+
public: virtual void quack() const = 0;
16+
};
17+
18+
} // namespace Ducks
19+
} // namespace Adapter
20+
} // namespace HeadFirstDesignPatterns
21+
22+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#ifndef _HFDP_CPP_ADAPTER_DUCK_ADAPTER_HPP_
2+
#define _HFDP_CPP_ADAPTER_DUCK_ADAPTER_HPP_
3+
4+
#include "Ducks.hpp"
5+
#include <process.h>
6+
7+
namespace HeadFirstDesignPatterns {
8+
namespace Adapter {
9+
namespace Ducks {
10+
11+
class DuckAdapter : public Turkey {
12+
13+
private: std::auto_ptr< const Duck > _duck;
14+
private: int _random;
15+
16+
private: DuckAdapter( const DuckAdapter& ); // Disable copy constructor
17+
private: void operator=( const DuckAdapter& ); // Disable assignment operator
18+
19+
public: explicit DuckAdapter( const Duck* duck ) :
20+
_duck ( duck ) { assert( duck );
21+
srand( _getpid() );
22+
_random = rand() % 5;
23+
if( _random == 0 )
24+
_random = 1;
25+
}
26+
public: void fly() const { assert( _duck );
27+
for( int i = 0; i < _random; i++ ) {
28+
_duck->fly();
29+
}
30+
}
31+
public: void gobble() const { assert( _duck );
32+
_duck->quack();
33+
}
34+
};
35+
36+
} // namespace Ducks
37+
} // namespace Adapter
38+
} // namespace HeadFirstDesignPatterns
39+
40+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "Ducks.hpp"
2+
3+
using namespace HeadFirstDesignPatterns::Adapter::Ducks;
4+
5+
void testDuck( const Duck* duck ) {
6+
duck->quack();
7+
duck->fly();
8+
}
9+
10+
int main( int argc, char* argv[] ) {
11+
12+
std::auto_ptr< MallardDuck > duck( new MallardDuck() );
13+
14+
#ifdef _DUCK_ADAPTER_
15+
std::auto_ptr< Turkey > duckAdapter( new DuckAdapter( duck.get() ) );
16+
17+
for( int i = 0; i < 10; i++ ) {
18+
std::cout << "The DuckAdapter says..." << std::endl;
19+
duckAdapter->gobble();
20+
duckAdapter->fly();
21+
}
22+
#else
23+
std::auto_ptr< WildTurkey > turkey( new WildTurkey() );
24+
std::auto_ptr< Duck > turkeyAdapter( new TurkeyAdapter( turkey.get() ) );
25+
26+
std::cout << "The Turkey says..." << std::endl;
27+
turkey->gobble();
28+
turkey->fly();
29+
30+
std::cout << std::endl << "The Duck says..." << std::endl;
31+
testDuck( duck.get() );
32+
33+
std::cout << std::endl << "The TurkeyAdapter says..." << std::endl;
34+
testDuck( turkeyAdapter.get() );
35+
#endif
36+
37+
return 0;
38+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _HFDP_CPP_ADAPTER_BIRDS_HPP_
2+
#define _HFDP_CPP_ADAPTER_BIRDS_HPP_
3+
4+
#include "../../Standard.h"
5+
6+
#include "Duck.hpp"
7+
#include "MallardDuck.hpp"
8+
9+
#include "Turkey.hpp"
10+
#include "WildTurkey.hpp"
11+
#include "TurkeyAdapter.hpp"
12+
13+
//#define _DUCK_ADAPTER_
14+
#ifdef _DUCK_ADAPTER_
15+
#include "DuckAdapter.hpp"
16+
#endif
17+
18+
#endif
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
<?xml version="1.0" encoding="Windows-1252"?>
2+
<VisualStudioProject
3+
ProjectType="Visual C++"
4+
Version="8.00"
5+
Name="Ducks"
6+
ProjectGUID="{BCDE01C8-E042-47A7-A463-02867005E62C}"
7+
RootNamespace="Ducks"
8+
Keyword="Win32Proj"
9+
>
10+
<Platforms>
11+
<Platform
12+
Name="Win32"
13+
/>
14+
</Platforms>
15+
<ToolFiles>
16+
</ToolFiles>
17+
<Configurations>
18+
<Configuration
19+
Name="Debug|Win32"
20+
OutputDirectory="$(ConfigurationName)"
21+
IntermediateDirectory="$(ConfigurationName)"
22+
ConfigurationType="1"
23+
CharacterSet="1"
24+
>
25+
<Tool
26+
Name="VCPreBuildEventTool"
27+
/>
28+
<Tool
29+
Name="VCCustomBuildTool"
30+
/>
31+
<Tool
32+
Name="VCXMLDataGeneratorTool"
33+
/>
34+
<Tool
35+
Name="VCWebServiceProxyGeneratorTool"
36+
/>
37+
<Tool
38+
Name="VCMIDLTool"
39+
/>
40+
<Tool
41+
Name="VCCLCompilerTool"
42+
Optimization="0"
43+
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
44+
MinimalRebuild="true"
45+
BasicRuntimeChecks="3"
46+
RuntimeLibrary="1"
47+
UsePrecompiledHeader="0"
48+
WarningLevel="4"
49+
Detect64BitPortabilityProblems="true"
50+
DebugInformationFormat="4"
51+
/>
52+
<Tool
53+
Name="VCManagedResourceCompilerTool"
54+
/>
55+
<Tool
56+
Name="VCResourceCompilerTool"
57+
/>
58+
<Tool
59+
Name="VCPreLinkEventTool"
60+
/>
61+
<Tool
62+
Name="VCLinkerTool"
63+
LinkIncremental="2"
64+
GenerateDebugInformation="true"
65+
SubSystem="1"
66+
TargetMachine="1"
67+
/>
68+
<Tool
69+
Name="VCALinkTool"
70+
/>
71+
<Tool
72+
Name="VCManifestTool"
73+
/>
74+
<Tool
75+
Name="VCXDCMakeTool"
76+
/>
77+
<Tool
78+
Name="VCBscMakeTool"
79+
/>
80+
<Tool
81+
Name="VCFxCopTool"
82+
/>
83+
<Tool
84+
Name="VCAppVerifierTool"
85+
/>
86+
<Tool
87+
Name="VCWebDeploymentTool"
88+
/>
89+
<Tool
90+
Name="VCPostBuildEventTool"
91+
/>
92+
</Configuration>
93+
<Configuration
94+
Name="Release|Win32"
95+
OutputDirectory="$(ConfigurationName)"
96+
IntermediateDirectory="$(ConfigurationName)"
97+
ConfigurationType="1"
98+
CharacterSet="1"
99+
WholeProgramOptimization="1"
100+
>
101+
<Tool
102+
Name="VCPreBuildEventTool"
103+
/>
104+
<Tool
105+
Name="VCCustomBuildTool"
106+
/>
107+
<Tool
108+
Name="VCXMLDataGeneratorTool"
109+
/>
110+
<Tool
111+
Name="VCWebServiceProxyGeneratorTool"
112+
/>
113+
<Tool
114+
Name="VCMIDLTool"
115+
/>
116+
<Tool
117+
Name="VCCLCompilerTool"
118+
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
119+
RuntimeLibrary="0"
120+
UsePrecompiledHeader="0"
121+
WarningLevel="4"
122+
Detect64BitPortabilityProblems="true"
123+
DebugInformationFormat="3"
124+
/>
125+
<Tool
126+
Name="VCManagedResourceCompilerTool"
127+
/>
128+
<Tool
129+
Name="VCResourceCompilerTool"
130+
/>
131+
<Tool
132+
Name="VCPreLinkEventTool"
133+
/>
134+
<Tool
135+
Name="VCLinkerTool"
136+
LinkIncremental="1"
137+
GenerateDebugInformation="true"
138+
SubSystem="1"
139+
OptimizeReferences="2"
140+
EnableCOMDATFolding="2"
141+
TargetMachine="1"
142+
/>
143+
<Tool
144+
Name="VCALinkTool"
145+
/>
146+
<Tool
147+
Name="VCManifestTool"
148+
/>
149+
<Tool
150+
Name="VCXDCMakeTool"
151+
/>
152+
<Tool
153+
Name="VCBscMakeTool"
154+
/>
155+
<Tool
156+
Name="VCFxCopTool"
157+
/>
158+
<Tool
159+
Name="VCAppVerifierTool"
160+
/>
161+
<Tool
162+
Name="VCWebDeploymentTool"
163+
/>
164+
<Tool
165+
Name="VCPostBuildEventTool"
166+
/>
167+
</Configuration>
168+
</Configurations>
169+
<References>
170+
</References>
171+
<Files>
172+
<Filter
173+
Name="Source Files"
174+
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
175+
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
176+
>
177+
<File
178+
RelativePath=".\Ducks.cpp"
179+
>
180+
</File>
181+
</Filter>
182+
<Filter
183+
Name="Header Files"
184+
Filter="h;hpp;hxx;hm;inl;inc;xsd"
185+
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
186+
>
187+
<File
188+
RelativePath=".\Duck.hpp"
189+
>
190+
</File>
191+
<File
192+
RelativePath=".\DuckAdapter.hpp"
193+
>
194+
</File>
195+
<File
196+
RelativePath=".\Ducks.hpp"
197+
>
198+
</File>
199+
<File
200+
RelativePath=".\MallardDuck.hpp"
201+
>
202+
</File>
203+
<File
204+
RelativePath=".\Turkey.hpp"
205+
>
206+
</File>
207+
<File
208+
RelativePath=".\TurkeyAdapter.hpp"
209+
>
210+
</File>
211+
<File
212+
RelativePath=".\WildTurkey.hpp"
213+
>
214+
</File>
215+
</Filter>
216+
<Filter
217+
Name="Resource Files"
218+
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
219+
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
220+
>
221+
</Filter>
222+
</Files>
223+
<Globals>
224+
</Globals>
225+
</VisualStudioProject>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef _HFDP_CPP_ADAPTER_MALLARD_DUCK_HPP_
2+
#define _HFDP_CPP_ADAPTER_MALLARD_DUCK_HPP_
3+
4+
#include "Ducks.hpp"
5+
6+
namespace HeadFirstDesignPatterns {
7+
namespace Adapter {
8+
namespace Ducks {
9+
10+
class MallardDuck : public Duck {
11+
12+
public: void fly() const {
13+
std::cout << "I'm flying" << std::endl;
14+
}
15+
public: void quack() const {
16+
std::cout << "Quack" << std::endl;
17+
}
18+
};
19+
20+
} // namespace Ducks
21+
} // namespace Adapter
22+
} // namespace HeadFirstDesignPatterns
23+
24+
#endif
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
2+
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
3+
</assembly>

0 commit comments

Comments
 (0)