├── README.md ├── 21th_strongpointer_weakpointer ├── 02th │ ├── include │ │ ├── cutils │ │ │ ├── log.h │ │ │ ├── partition_utils.h │ │ │ ├── dir_hash.h │ │ │ ├── open_memstream.h │ │ │ ├── android_reboot.h │ │ │ ├── cpu_info.h │ │ │ ├── uevent.h │ │ │ ├── iosched_policy.h │ │ │ ├── process_name.h │ │ │ ├── multiuser.h │ │ │ ├── ashmem.h │ │ │ ├── record_stream.h │ │ │ ├── misc.h │ │ │ ├── memory.h │ │ │ └── compiler.h │ │ └── utils │ │ │ ├── Atomic.h │ │ │ ├── SystemClock.h │ │ │ ├── Functor.h │ │ │ ├── Endian.h │ │ │ ├── threads.h │ │ │ ├── misc.h │ │ │ └── ashmem.h │ ├── person9.cpp │ └── Makefile ├── 03th │ ├── include │ │ ├── cutils │ │ │ ├── log.h │ │ │ ├── partition_utils.h │ │ │ ├── dir_hash.h │ │ │ ├── open_memstream.h │ │ │ ├── android_reboot.h │ │ │ ├── cpu_info.h │ │ │ ├── uevent.h │ │ │ ├── iosched_policy.h │ │ │ ├── process_name.h │ │ │ ├── multiuser.h │ │ │ ├── ashmem.h │ │ │ ├── record_stream.h │ │ │ ├── misc.h │ │ │ ├── memory.h │ │ │ └── compiler.h │ │ └── utils │ │ │ ├── Atomic.h │ │ │ ├── SystemClock.h │ │ │ ├── Functor.h │ │ │ ├── Endian.h │ │ │ ├── threads.h │ │ │ ├── misc.h │ │ │ └── ashmem.h │ ├── person9.cpp │ └── Makefile ├── 04th │ ├── include │ │ ├── cutils │ │ │ ├── log.h │ │ │ ├── partition_utils.h │ │ │ ├── dir_hash.h │ │ │ ├── open_memstream.h │ │ │ ├── android_reboot.h │ │ │ ├── cpu_info.h │ │ │ ├── uevent.h │ │ │ ├── iosched_policy.h │ │ │ ├── process_name.h │ │ │ ├── multiuser.h │ │ │ ├── ashmem.h │ │ │ ├── record_stream.h │ │ │ ├── misc.h │ │ │ └── memory.h │ │ └── utils │ │ │ ├── Atomic.h │ │ │ ├── SystemClock.h │ │ │ ├── Functor.h │ │ │ ├── Endian.h │ │ │ ├── threads.h │ │ │ ├── misc.h │ │ │ └── ashmem.h │ ├── person9.cpp │ └── Makefile ├── 05th │ ├── include │ │ ├── cutils │ │ │ ├── log.h │ │ │ ├── partition_utils.h │ │ │ ├── dir_hash.h │ │ │ ├── open_memstream.h │ │ │ ├── android_reboot.h │ │ │ ├── cpu_info.h │ │ │ ├── uevent.h │ │ │ ├── iosched_policy.h │ │ │ ├── process_name.h │ │ │ ├── multiuser.h │ │ │ ├── ashmem.h │ │ │ ├── record_stream.h │ │ │ ├── misc.h │ │ │ └── memory.h │ │ └── utils │ │ │ ├── Atomic.h │ │ │ ├── SystemClock.h │ │ │ ├── Functor.h │ │ │ ├── Endian.h │ │ │ ├── threads.h │ │ │ ├── misc.h │ │ │ └── ashmem.h │ ├── person9.cpp │ └── Makefile └── 01th │ └── person9.cpp ├── 07th_static ├── person.cpp └── person2.cpp ├── 09th_operator ├── person.cpp └── point.cpp ├── 16th_template ├── max4.cpp ├── max5.cpp ├── max3.cpp ├── max.cpp ├── max2.cpp ├── max6.cpp ├── max8.cpp ├── max7.cpp ├── max9.cpp ├── max10.cpp ├── max11.cpp └── max12.cpp ├── 22th_singleton ├── README.md ├── Singleton2.cpp ├── Singleton3.cpp ├── Singleton4.cpp ├── Singleton5.cpp ├── Singleton6.cpp ├── Singleton7.cpp └── Singleton.cpp ├── 06th_constructor ├── person2.cpp ├── person3.cpp ├── person4.cpp ├── person5.cpp ├── person6.cpp └── person.cpp ├── 10th_inheritance ├── person.cpp ├── father_son.cpp ├── father_son2.cpp ├── father_son3.cpp ├── father_son4.cpp ├── father_son5.cpp ├── father_son6.cpp └── person_student.cpp ├── 19th_smartpointer ├── person4.cpp ├── person7.cpp ├── person8.cpp ├── person9.cpp ├── person.cpp ├── person2.cpp ├── person3.cpp └── person5.cpp ├── 14th_convert ├── convert5_Human.cpp ├── convert6_Human.cpp ├── convert.c ├── convert2.c ├── convert3.cpp └── convert4.cpp ├── 03th_ProgramStructure ├── 04th │ ├── main.cpp │ ├── Makefile │ ├── dog.h │ ├── person.h │ ├── dog.cpp │ └── person.cpp ├── 02th │ ├── Makefile │ ├── person.h │ ├── main.cpp │ └── person.cpp ├── 03th │ ├── Makefile │ ├── dog.h │ ├── person.h │ ├── main.cpp │ ├── dog.cpp │ └── person.cpp ├── 05th │ ├── Makefile │ ├── dog.h │ ├── person.h │ ├── main.cpp │ ├── dog.cpp │ └── person.cpp ├── 06th │ ├── Makefile │ ├── dog.h │ ├── person.h │ ├── main.cpp │ ├── dog.cpp │ └── person.cpp └── 01th │ └── person.cpp ├── 11th_multi_inheritance ├── Sofabed2.cpp ├── Sofabed.cpp └── Sofabed3.cpp ├── 20th_light_smartpointer └── person9.cpp ├── 15th_abstract ├── 2th │ ├── Makefile │ ├── main.cpp │ ├── Chinese.h │ ├── Englishman.h │ ├── Chinese.cpp │ └── Englishman.cpp ├── 3th │ ├── 1th │ │ ├── Makefile │ │ ├── main.cpp │ │ ├── Chinese.h │ │ ├── Englishman.h │ │ ├── Chinese.cpp │ │ └── Englishman.cpp │ └── 2th │ │ ├── Makefile │ │ ├── Human.cpp │ │ ├── main.cpp │ │ ├── Human.h │ │ ├── Chinese.h │ │ ├── Englishman.h │ │ ├── Chinese.cpp │ │ └── Englishman.cpp ├── 4th │ ├── Makefile │ ├── Human.cpp │ ├── Chinese.h │ ├── Englishman.h │ ├── main.cpp │ ├── Chinese.cpp │ ├── Englishman.cpp │ └── Human.h ├── 5th │ ├── Makefile │ ├── Human.cpp │ ├── Chinese.h │ ├── Englishman.h │ ├── main.cpp │ ├── Chinese.cpp │ ├── Englishman.cpp │ └── Human.h ├── 6th │ ├── Human.cpp │ ├── Makefile │ ├── Chinese.h │ ├── Englishman.h │ ├── main.cpp │ ├── Chinese.cpp │ ├── Englishman.cpp │ └── Human.h ├── 7th │ ├── Human.cpp │ ├── Makefile │ ├── Chinese.h │ ├── Chinese.cpp │ ├── main.cpp │ ├── Human.h │ ├── Englishman.h │ └── Englishman.cpp ├── 8th │ ├── Human.cpp │ ├── Makefile │ ├── Chinese.h │ ├── main.cpp │ ├── Englishman.h │ ├── Chinese.cpp │ ├── Human.h │ └── Englishman.cpp ├── 9th │ ├── Human.cpp │ ├── Makefile │ ├── Chinese.h │ ├── main.cpp │ ├── Chinese.cpp │ ├── Englishman.h │ ├── Human.h │ └── Englishman.cpp └── 1th │ ├── Human.cpp │ └── Human2.cpp ├── 01th_oop ├── person.c ├── person2.c ├── person5.cpp ├── person6.cpp ├── person4.c └── person3.c ├── 18th_exception ├── exception.cpp ├── exception2.cpp ├── exception3.cpp ├── exception4.cpp └── exception6.cpp ├── 02th_accesscontrol ├── person.cpp └── person2.cpp ├── 05th_pointer_reference └── main.cpp ├── 17th_class_template ├── template.cpp └── template2.cpp ├── 13th_Polymorphism ├── Human.cpp ├── Human2.cpp ├── Human3.cpp ├── Human4.cpp ├── Human5.cpp └── Human6.cpp ├── 04th_overload └── main.cpp ├── 08th_friend ├── point.cpp └── point2.cpp └── 23th_bridge_mode ├── Bridge.cpp └── Bridge2.cpp /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/README.md -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/cutils/log.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/log.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/log.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/log.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /07th_static/person.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/07th_static/person.cpp -------------------------------------------------------------------------------- /07th_static/person2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/07th_static/person2.cpp -------------------------------------------------------------------------------- /09th_operator/person.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/09th_operator/person.cpp -------------------------------------------------------------------------------- /16th_template/max4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/16th_template/max4.cpp -------------------------------------------------------------------------------- /16th_template/max5.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/16th_template/max5.cpp -------------------------------------------------------------------------------- /22th_singleton/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/22th_singleton/README.md -------------------------------------------------------------------------------- /06th_constructor/person2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/06th_constructor/person2.cpp -------------------------------------------------------------------------------- /06th_constructor/person3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/06th_constructor/person3.cpp -------------------------------------------------------------------------------- /06th_constructor/person4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/06th_constructor/person4.cpp -------------------------------------------------------------------------------- /06th_constructor/person5.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/06th_constructor/person5.cpp -------------------------------------------------------------------------------- /06th_constructor/person6.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/06th_constructor/person6.cpp -------------------------------------------------------------------------------- /10th_inheritance/person.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/person.cpp -------------------------------------------------------------------------------- /19th_smartpointer/person4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/19th_smartpointer/person4.cpp -------------------------------------------------------------------------------- /19th_smartpointer/person7.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/19th_smartpointer/person7.cpp -------------------------------------------------------------------------------- /19th_smartpointer/person8.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/19th_smartpointer/person8.cpp -------------------------------------------------------------------------------- /19th_smartpointer/person9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/19th_smartpointer/person9.cpp -------------------------------------------------------------------------------- /22th_singleton/Singleton2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/22th_singleton/Singleton2.cpp -------------------------------------------------------------------------------- /22th_singleton/Singleton3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/22th_singleton/Singleton3.cpp -------------------------------------------------------------------------------- /22th_singleton/Singleton4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/22th_singleton/Singleton4.cpp -------------------------------------------------------------------------------- /22th_singleton/Singleton5.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/22th_singleton/Singleton5.cpp -------------------------------------------------------------------------------- /22th_singleton/Singleton6.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/22th_singleton/Singleton6.cpp -------------------------------------------------------------------------------- /22th_singleton/Singleton7.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/22th_singleton/Singleton7.cpp -------------------------------------------------------------------------------- /10th_inheritance/father_son.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/father_son.cpp -------------------------------------------------------------------------------- /14th_convert/convert5_Human.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/14th_convert/convert5_Human.cpp -------------------------------------------------------------------------------- /14th_convert/convert6_Human.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/14th_convert/convert6_Human.cpp -------------------------------------------------------------------------------- /10th_inheritance/father_son2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/father_son2.cpp -------------------------------------------------------------------------------- /10th_inheritance/father_son3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/father_son3.cpp -------------------------------------------------------------------------------- /10th_inheritance/father_son4.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/father_son4.cpp -------------------------------------------------------------------------------- /10th_inheritance/father_son5.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/father_son5.cpp -------------------------------------------------------------------------------- /10th_inheritance/father_son6.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/father_son6.cpp -------------------------------------------------------------------------------- /03th_ProgramStructure/04th/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/03th_ProgramStructure/04th/main.cpp -------------------------------------------------------------------------------- /10th_inheritance/person_student.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/10th_inheritance/person_student.cpp -------------------------------------------------------------------------------- /11th_multi_inheritance/Sofabed2.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/11th_multi_inheritance/Sofabed2.cpp -------------------------------------------------------------------------------- /20th_light_smartpointer/person9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/20th_light_smartpointer/person9.cpp -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/01th/person9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/21th_strongpointer_weakpointer/01th/person9.cpp -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/person9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/21th_strongpointer_weakpointer/02th/person9.cpp -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/person9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/21th_strongpointer_weakpointer/03th/person9.cpp -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/person9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/21th_strongpointer_weakpointer/04th/person9.cpp -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/person9.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/weidongshan/cpp_projects/HEAD/21th_strongpointer_weakpointer/05th/person9.cpp -------------------------------------------------------------------------------- /03th_ProgramStructure/02th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person: main.o person.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o person -------------------------------------------------------------------------------- /03th_ProgramStructure/03th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person: main.o person.o dog.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o person -------------------------------------------------------------------------------- /03th_ProgramStructure/04th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person: main.o person.o dog.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o person -------------------------------------------------------------------------------- /03th_ProgramStructure/05th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person: main.o person.o dog.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o person -------------------------------------------------------------------------------- /03th_ProgramStructure/06th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person: main.o person.o dog.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o person -------------------------------------------------------------------------------- /15th_abstract/2th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o Chinese.o Englishman.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o Human -------------------------------------------------------------------------------- /15th_abstract/3th/1th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o Chinese.o Englishman.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o Human -------------------------------------------------------------------------------- /15th_abstract/4th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o Chinese.o Englishman.o Human.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o Human -------------------------------------------------------------------------------- /15th_abstract/5th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o Chinese.o Englishman.o Human.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o Human -------------------------------------------------------------------------------- /15th_abstract/3th/2th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o Chinese.o Englishman.o Human.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< 7 | 8 | clean: 9 | rm -f *.o Human -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person9: person9.o RefBase.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< -I include 7 | 8 | clean: 9 | rm -f *.o person9 -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person9: person9.o RefBase.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< -I include 7 | 8 | clean: 9 | rm -f *.o person9 -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person9: person9.o RefBase.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< -I include 7 | 8 | clean: 9 | rm -f *.o person9 -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | person9: person9.o RefBase.o 3 | g++ -o $@ $^ 4 | 5 | %.o : %.cpp 6 | g++ -c -o $@ $< -I include 7 | 8 | clean: 9 | rm -f *.o person9 -------------------------------------------------------------------------------- /15th_abstract/4th/Human.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | 4 | void Human::setName(char *name) 5 | { 6 | this->name = name; 7 | } 8 | 9 | char *Human::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /15th_abstract/5th/Human.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | 4 | void Human::setName(char *name) 5 | { 6 | this->name = name; 7 | } 8 | 9 | char *Human::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /15th_abstract/6th/Human.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | 4 | void Human::setName(char *name) 5 | { 6 | this->name = name; 7 | } 8 | 9 | char *Human::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /15th_abstract/7th/Human.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | 4 | void Human::setName(char *name) 5 | { 6 | this->name = name; 7 | } 8 | 9 | char *Human::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /15th_abstract/8th/Human.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | 4 | void Human::setName(char *name) 5 | { 6 | this->name = name; 7 | } 8 | 9 | char *Human::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /15th_abstract/9th/Human.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | 4 | void Human::setName(char *name) 5 | { 6 | this->name = name; 7 | } 8 | 9 | char *Human::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /15th_abstract/3th/2th/Human.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | 4 | void Human::setName(char *name) 5 | { 6 | this->name = name; 7 | } 8 | 9 | char *Human::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /15th_abstract/2th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Englishman.h" 3 | #include "Chinese.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | Englishman e; 8 | Chinese c; 9 | 10 | e.eating(); 11 | c.eating(); 12 | 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /15th_abstract/3th/1th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Englishman.h" 3 | #include "Chinese.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | Englishman e; 8 | Chinese c; 9 | 10 | e.eating(); 11 | c.eating(); 12 | 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /15th_abstract/6th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o libHuman.so 3 | g++ -o $@ $< -L./ -lHuman 4 | 5 | %.o : %.cpp 6 | g++ -fPIC -c -o $@ $< 7 | 8 | libHuman.so : Englishman.o Chinese.o Human.o 9 | g++ -shared -o $@ $^ 10 | 11 | clean: 12 | rm -f *.o Human -------------------------------------------------------------------------------- /15th_abstract/7th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o libHuman.so 3 | g++ -o $@ $< -L./ -lHuman 4 | 5 | %.o : %.cpp 6 | g++ -fPIC -c -o $@ $< 7 | 8 | libHuman.so : Englishman.o Chinese.o Human.o 9 | g++ -shared -o $@ $^ 10 | 11 | clean: 12 | rm -f *.o Human -------------------------------------------------------------------------------- /15th_abstract/8th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o libHuman.so 3 | g++ -o $@ $< -L./ -lHuman 4 | 5 | %.o : %.cpp 6 | g++ -fPIC -c -o $@ $< 7 | 8 | libHuman.so : Englishman.o Chinese.o Human.o 9 | g++ -shared -o $@ $^ 10 | 11 | clean: 12 | rm -f *.o Human -------------------------------------------------------------------------------- /15th_abstract/9th/Makefile: -------------------------------------------------------------------------------- 1 | 2 | Human: main.o libHuman.so 3 | g++ -o $@ $< -L./ -lHuman 4 | 5 | %.o : %.cpp 6 | g++ -fPIC -c -o $@ $< 7 | 8 | libHuman.so : Englishman.o Chinese.o Human.o 9 | g++ -shared -o $@ $^ 10 | 11 | clean: 12 | rm -f *.o Human -------------------------------------------------------------------------------- /03th_ProgramStructure/02th/person.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | class Person { 5 | private: 6 | char *name; 7 | int age; 8 | char *work; 9 | 10 | public: 11 | void setName(char *name); 12 | int setAge(int age); 13 | void printInfo(void); 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /03th_ProgramStructure/03th/dog.h: -------------------------------------------------------------------------------- 1 | 2 | namespace C { 3 | 4 | class Dog { 5 | private: 6 | char *name; 7 | int age; 8 | public: 9 | void setName(char *name); 10 | int setAge(int age); 11 | void printInfo(void); 12 | }; 13 | 14 | void printVersion(void); 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /03th_ProgramStructure/04th/dog.h: -------------------------------------------------------------------------------- 1 | 2 | namespace C { 3 | 4 | class Dog { 5 | private: 6 | char *name; 7 | int age; 8 | public: 9 | void setName(char *name); 10 | int setAge(int age); 11 | void printInfo(void); 12 | }; 13 | 14 | void printVersion(void); 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /03th_ProgramStructure/05th/dog.h: -------------------------------------------------------------------------------- 1 | 2 | namespace C { 3 | 4 | class Dog { 5 | private: 6 | char *name; 7 | int age; 8 | public: 9 | void setName(char *name); 10 | int setAge(int age); 11 | void printInfo(void); 12 | }; 13 | 14 | void printVersion(void); 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /03th_ProgramStructure/06th/dog.h: -------------------------------------------------------------------------------- 1 | 2 | namespace C { 3 | 4 | class Dog { 5 | private: 6 | char *name; 7 | int age; 8 | public: 9 | void setName(char *name); 10 | int setAge(int age); 11 | void printInfo(void); 12 | }; 13 | 14 | void printVersion(void); 15 | 16 | } 17 | 18 | -------------------------------------------------------------------------------- /03th_ProgramStructure/02th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | Person per; 8 | 9 | //per.name = "zhangsan"; 10 | per.setName("zhangsan"); 11 | per.setAge(200); 12 | per.printInfo(); 13 | 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /15th_abstract/3th/2th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Englishman.h" 3 | #include "Chinese.h" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | Englishman e; 8 | Chinese c; 9 | 10 | e.setName("Bill"); 11 | c.setName("zhangsan"); 12 | 13 | e.eating(); 14 | c.eating(); 15 | 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /14th_convert/convert.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | double d = 100.1; 7 | int i = d; // doubleתΪint 8 | char *str = "100ask.taobao.com"; 9 | int *p = str; // char *תΪint * 10 | 11 | printf("i = %d, str = 0x%x, p = 0x%x\n", i, str, p); 12 | 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /03th_ProgramStructure/03th/person.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | namespace A { 5 | 6 | class Person { 7 | private: 8 | char *name; 9 | int age; 10 | char *work; 11 | 12 | public: 13 | void setName(char *name); 14 | int setAge(int age); 15 | void printInfo(void); 16 | }; 17 | 18 | void printVersion(void); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /03th_ProgramStructure/04th/person.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | namespace A { 5 | 6 | class Person { 7 | private: 8 | char *name; 9 | int age; 10 | char *work; 11 | 12 | public: 13 | void setName(char *name); 14 | int setAge(int age); 15 | void printInfo(void); 16 | }; 17 | 18 | void printVersion(void); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /03th_ProgramStructure/05th/person.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | namespace A { 5 | 6 | class Person { 7 | private: 8 | char *name; 9 | int age; 10 | char *work; 11 | 12 | public: 13 | void setName(char *name); 14 | int setAge(int age); 15 | void printInfo(void); 16 | }; 17 | 18 | void printVersion(void); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /03th_ProgramStructure/06th/person.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | namespace A { 5 | 6 | class Person { 7 | private: 8 | char *name; 9 | int age; 10 | char *work; 11 | 12 | public: 13 | void setName(char *name); 14 | int setAge(int age); 15 | void printInfo(void); 16 | }; 17 | 18 | void printVersion(void); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /15th_abstract/2th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | class Chinese{ 12 | public: 13 | void eating(void); 14 | void wearing(void); 15 | void driving(void); 16 | ~Chinese(); 17 | }; 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /01th_oop/person.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | char *zs_name = "zhangsan"; 7 | int zs_age = 10; 8 | 9 | char *ls_name = "lisi"; 10 | int ls_age = 16; 11 | 12 | printf("name = %s, age = %d\n", zs_name, zs_age); 13 | printf("name = %s, age = %d\n", ls_name, ls_age); 14 | 15 | return 0; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /14th_convert/convert2.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | double d = 100.1; 7 | int i = d; // doubleתΪint 8 | char *str = "100ask.taobao.com"; 9 | int *p = (int *)str; // char *תΪint * 10 | 11 | printf("i = %d, str = 0x%x, p = 0x%x\n", i, (unsigned int)str, (unsigned int)p); 12 | 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /15th_abstract/3th/2th/Human.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _HUMAN_H 4 | #define _HUMAN_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Human { 13 | private: 14 | char *name; 15 | 16 | public: 17 | void setName(char *name); 18 | char *getName(void); 19 | 20 | }; 21 | 22 | #endif 23 | 24 | -------------------------------------------------------------------------------- /15th_abstract/2th/Englishman.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENGLISHMAN_H 3 | #define _ENGLISHMAN_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | class Englishman { 12 | public: 13 | void eating(void); 14 | void wearing(void); 15 | void driving(void); 16 | ~Englishman(); 17 | }; 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /01th_oop/person2.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | char *names[] = {"zhangsan", "lisi"}; 7 | char ages[] = {10, 16}; 8 | char *work[] = {"teacher", "doctor"}; 9 | 10 | int i; 11 | 12 | for (i = 0; i < 2; i++) 13 | { 14 | printf("name = %s, age = %d\n", names[i], ages[i]); 15 | } 16 | 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /15th_abstract/4th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Chinese : public Human{ 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Chinese(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/5th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Chinese : public Human{ 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Chinese(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/6th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Chinese : public Human{ 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Chinese(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/7th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Chinese : public Human{ 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Chinese(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/8th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Chinese : public Human{ 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Chinese(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/3th/2th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Chinese : public Human{ 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Chinese(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/9th/Chinese.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _CHINESE_H 3 | #define _CHINESE_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Chinese : public Human{ 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | virtual ~Chinese(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/4th/Englishman.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENGLISHMAN_H 3 | #define _ENGLISHMAN_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Englishman : public Human { 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Englishman(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/5th/Englishman.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENGLISHMAN_H 3 | #define _ENGLISHMAN_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Englishman : public Human { 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Englishman(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/6th/Englishman.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENGLISHMAN_H 3 | #define _ENGLISHMAN_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Englishman : public Human { 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Englishman(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/3th/2th/Englishman.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENGLISHMAN_H 3 | #define _ENGLISHMAN_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Englishman : public Human { 14 | public: 15 | void eating(void); 16 | void wearing(void); 17 | void driving(void); 18 | ~Englishman(); 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /14th_convert/convert3.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | int main(int argc, char **argv) 5 | { 6 | double d = 100.1; 7 | int i = d; // doubleתΪint 8 | char *str = "100ask.taobao.com"; 9 | int *p = reinterpret_cast(str); // char *תΪint * 10 | 11 | printf("i = %d, str = 0x%x, p = 0x%x\n", i, reinterpret_cast(str), reinterpret_cast(p)); 12 | 13 | return 0; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /15th_abstract/4th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | #include "Englishman.h" 4 | #include "Chinese.h" 5 | 6 | void test_eating(Human *h) 7 | { 8 | h->eating(); 9 | } 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | Englishman e; 15 | Chinese c; 16 | 17 | Human* h[2] = {&e, &c}; 18 | int i; 19 | for (i = 0; i < 2; i++) 20 | test_eating(h[i]); 21 | 22 | 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /15th_abstract/5th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | #include "Englishman.h" 4 | #include "Chinese.h" 5 | 6 | void test_eating(Human *h) 7 | { 8 | h->eating(); 9 | } 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | Englishman e; 15 | Chinese c; 16 | 17 | Human* h[2] = {&e, &c}; 18 | int i; 19 | for (i = 0; i < 2; i++) 20 | test_eating(h[i]); 21 | 22 | 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /15th_abstract/6th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | #include "Englishman.h" 4 | #include "Chinese.h" 5 | 6 | void test_eating(Human *h) 7 | { 8 | h->eating(); 9 | } 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | Englishman e; 15 | Chinese c; 16 | 17 | Human* h[2] = {&e, &c}; 18 | int i; 19 | for (i = 0; i < 2; i++) 20 | test_eating(h[i]); 21 | 22 | 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /03th_ProgramStructure/03th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | #include "dog.h" 5 | 6 | int main(int argc, char **argv) 7 | { 8 | A::Person per; 9 | per.setName("zhangsan"); 10 | per.setAge(16); 11 | per.printInfo(); 12 | 13 | C::Dog dog; 14 | dog.setName("wangcai"); 15 | dog.setAge(1); 16 | dog.printInfo(); 17 | 18 | A::printVersion(); 19 | C::printVersion(); 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /15th_abstract/2th/Chinese.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Chinese.h" 3 | 4 | void Chinese::eating(void) 5 | { 6 | cout<<"use chopsticks to eat"< 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | class Chinese{ 12 | private: 13 | char *name; 14 | public: 15 | void setName(char *name); 16 | char *getName(void); 17 | void eating(void); 18 | void wearing(void); 19 | void driving(void); 20 | ~Chinese(); 21 | }; 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /15th_abstract/3th/2th/Englishman.cpp: -------------------------------------------------------------------------------- 1 | #include "Englishman.h" 2 | 3 | 4 | void Englishman::eating(void) 5 | { 6 | cout<<"use knife to eat"<eating(); 9 | } 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | Englishman e("Bill", 10, "sfwqerfsdfas"); 15 | Chinese c; 16 | 17 | Human* h[2] = {&e, &c}; 18 | int i; 19 | for (i = 0; i < 2; i++) 20 | test_eating(h[i]); 21 | 22 | 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /15th_abstract/3th/1th/Englishman.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENGLISHMAN_H 3 | #define _ENGLISHMAN_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace std; 10 | 11 | class Englishman { 12 | private: 13 | char *name; 14 | public: 15 | void setName(char *name); 16 | char *getName(void); 17 | void eating(void); 18 | void wearing(void); 19 | void driving(void); 20 | ~Englishman(); 21 | }; 22 | 23 | #endif 24 | 25 | -------------------------------------------------------------------------------- /18th_exception/exception.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | void C() 9 | { 10 | throw 1; 11 | } 12 | 13 | void B() 14 | { 15 | C(); 16 | } 17 | 18 | void A() 19 | { 20 | try { 21 | B(); 22 | } catch (int i) 23 | { 24 | cout<<"catch exception "< 3 | 4 | int main(int argc, char **argv) 5 | { 6 | double d = 100.1; 7 | int i = d; // doubleתΪint 8 | const char *str = "100ask.taobao.com"; 9 | char *str2 = const_cast(str); 10 | int *p = reinterpret_cast(str2); // char *תΪint * 11 | 12 | printf("i = %d, str = 0x%x, p = 0x%x\n", i, reinterpret_cast(str), reinterpret_cast(p)); 13 | 14 | return 0; 15 | } 16 | 17 | -------------------------------------------------------------------------------- /15th_abstract/5th/Human.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _HUMAN_H 4 | #define _HUMAN_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Human { 13 | private: 14 | char *name; 15 | 16 | public: 17 | void setName(char *name); 18 | char *getName(void); 19 | virtual void eating(void) = 0; 20 | virtual void wearing(void) = 0; 21 | virtual void driving(void) = 0; 22 | 23 | }; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /15th_abstract/6th/Human.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _HUMAN_H 4 | #define _HUMAN_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Human { 13 | private: 14 | char *name; 15 | 16 | public: 17 | void setName(char *name); 18 | char *getName(void); 19 | virtual void eating(void) = 0; 20 | virtual void wearing(void) = 0; 21 | virtual void driving(void) = 0; 22 | 23 | }; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /15th_abstract/7th/Human.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _HUMAN_H 4 | #define _HUMAN_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Human { 13 | private: 14 | char *name; 15 | 16 | public: 17 | void setName(char *name); 18 | char *getName(void); 19 | virtual void eating(void) = 0; 20 | virtual void wearing(void) = 0; 21 | virtual void driving(void) = 0; 22 | 23 | }; 24 | 25 | #endif 26 | 27 | -------------------------------------------------------------------------------- /03th_ProgramStructure/02th/person.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | 5 | void Person::setName(char *name) 6 | { 7 | this->name = name; 8 | } 9 | 10 | int Person::setAge(int age) 11 | { 12 | if (age < 0 || age > 150) 13 | { 14 | this->age = 0; 15 | return -1; 16 | } 17 | this->age = age; 18 | return 0; 19 | } 20 | 21 | void Person::printInfo(void) 22 | { 23 | printf("name = %s, age = %d, work = %s\n", name, age, work); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /15th_abstract/4th/Human.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef _HUMAN_H 4 | #define _HUMAN_H 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Human { 13 | private: 14 | char *name; 15 | 16 | public: 17 | void setName(char *name); 18 | char *getName(void); 19 | virtual void eating(void){cout<<"use hand to eat"< 3 | 4 | struct person { 5 | char *name; 6 | int age; 7 | char *work; 8 | 9 | void printInfo(void) 10 | { 11 | printf("name = %s, age = %d, work = %s\n", name, age, work); 12 | } 13 | }; 14 | 15 | int main(int argc, char **argv) 16 | { 17 | struct person persons[] = { 18 | {"zhangsan", 10, "teacher"}, 19 | {"lisi", 16, "doctor"}, 20 | }; 21 | 22 | persons[0].printInfo(); 23 | persons[1].printInfo(); 24 | 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /15th_abstract/8th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | //#include "Englishman.h" 4 | //#include "Chinese.h" 5 | 6 | void test_eating(Human *h) 7 | { 8 | h->eating(); 9 | } 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | Human& e = CreateEnglishman("Bill", 10, "sfwqerfsdfas"); 15 | Human& c = CreateChinese("zhangsan", 11, "beijing"); 16 | 17 | Human* h[2] = {&e, &c}; 18 | int i; 19 | for (i = 0; i < 2; i++) 20 | test_eating(h[i]); 21 | 22 | 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /01th_oop/person6.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | class person { 5 | public: 6 | char *name; 7 | int age; 8 | char *work; 9 | 10 | void printInfo(void) 11 | { 12 | printf("name = %s, age = %d, work = %s\n", name, age, work); 13 | } 14 | }; 15 | 16 | int main(int argc, char **argv) 17 | { 18 | struct person persons[] = { 19 | {"zhangsan", 10, "teacher"}, 20 | {"lisi", 16, "doctor"}, 21 | }; 22 | 23 | persons[0].printInfo(); 24 | persons[1].printInfo(); 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /11th_multi_inheritance/Sofabed.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Sofa { 8 | public: 9 | void watchTV(void) { cout<<"watch TV"< 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Englishman : public Human { 14 | private: 15 | char address[100]; 16 | int age; 17 | public: 18 | void eating(void); 19 | void wearing(void); 20 | void driving(void); 21 | Englishman(); 22 | Englishman(char *name, int age, char *address); 23 | ~Englishman(); 24 | }; 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /15th_abstract/8th/Englishman.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENGLISHMAN_H 3 | #define _ENGLISHMAN_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Englishman : public Human { 14 | private: 15 | char address[100]; 16 | int age; 17 | public: 18 | void eating(void); 19 | void wearing(void); 20 | void driving(void); 21 | Englishman(); 22 | Englishman(char *name, int age, char *address); 23 | ~Englishman(); 24 | }; 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /15th_abstract/9th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Human.h" 3 | //#include "Englishman.h" 4 | //#include "Chinese.h" 5 | 6 | void test_eating(Human *h) 7 | { 8 | h->eating(); 9 | } 10 | 11 | 12 | int main(int argc, char **argv) 13 | { 14 | Human& e = CreateEnglishman("Bill", 10, "sfwqerfsdfas"); 15 | Human& c = CreateChinese("zhangsan", 11, "beijing"); 16 | 17 | Human* h[2] = {&e, &c}; 18 | int i; 19 | for (i = 0; i < 2; i++) 20 | test_eating(h[i]); 21 | 22 | delete &e; 23 | delete &c; 24 | 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /15th_abstract/8th/Chinese.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Chinese.h" 3 | 4 | 5 | void Chinese::eating(void) 6 | { 7 | cout<<"use chopsticks to eat"< 6 | #include 7 | #include 8 | 9 | #include "Human.h" 10 | 11 | using namespace std; 12 | 13 | class Englishman : public Human { 14 | private: 15 | char address[100]; 16 | int age; 17 | public: 18 | void eating(void); 19 | void wearing(void); 20 | void driving(void); 21 | Englishman(); 22 | Englishman(char *name, int age, char *address); 23 | virtual ~Englishman(); 24 | }; 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /03th_ProgramStructure/05th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | #include "dog.h" 5 | 6 | using namespace A; 7 | using namespace C; 8 | 9 | int main(int argc, char **argv) 10 | { 11 | /* local namespace */ 12 | //using A::Person; 13 | //using C::Dog; 14 | 15 | Person per; 16 | per.setName("zhangsan"); 17 | per.setAge(16); 18 | per.printInfo(); 19 | 20 | Dog dog; 21 | dog.setName("wangcai"); 22 | dog.setAge(1); 23 | dog.printInfo(); 24 | 25 | A::printVersion(); 26 | C::printVersion(); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /03th_ProgramStructure/06th/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | #include "dog.h" 5 | 6 | using namespace A; 7 | using namespace C; 8 | 9 | int main(int argc, char **argv) 10 | { 11 | /* local namespace */ 12 | //using A::Person; 13 | //using C::Dog; 14 | 15 | Person per; 16 | per.setName("zhangsan"); 17 | per.setAge(16); 18 | per.printInfo(); 19 | 20 | Dog dog; 21 | dog.setName("wangcai"); 22 | dog.setAge(1); 23 | dog.printInfo(); 24 | 25 | A::printVersion(); 26 | C::printVersion(); 27 | return 0; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /03th_ProgramStructure/03th/dog.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "dog.h" 4 | 5 | namespace C { 6 | 7 | void Dog::setName(char *name) 8 | { 9 | this->name = name; 10 | } 11 | 12 | int Dog::setAge(int age) 13 | { 14 | if (age < 0 || age > 20) 15 | { 16 | this->age = 0; 17 | return -1; 18 | } 19 | this->age = age; 20 | return 0; 21 | } 22 | 23 | void Dog::printInfo(void) 24 | { 25 | printf("name = %s, age = %d\n", name, age); 26 | } 27 | 28 | void printVersion(void) 29 | { 30 | printf("Dog v1, by weidongshan\n"); 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /03th_ProgramStructure/04th/dog.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "dog.h" 4 | 5 | namespace C { 6 | 7 | void Dog::setName(char *name) 8 | { 9 | this->name = name; 10 | } 11 | 12 | int Dog::setAge(int age) 13 | { 14 | if (age < 0 || age > 20) 15 | { 16 | this->age = 0; 17 | return -1; 18 | } 19 | this->age = age; 20 | return 0; 21 | } 22 | 23 | void Dog::printInfo(void) 24 | { 25 | printf("name = %s, age = %d\n", name, age); 26 | } 27 | 28 | void printVersion(void) 29 | { 30 | printf("Dog v1, by weidongshan\n"); 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /03th_ProgramStructure/05th/dog.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "dog.h" 4 | 5 | namespace C { 6 | 7 | void Dog::setName(char *name) 8 | { 9 | this->name = name; 10 | } 11 | 12 | int Dog::setAge(int age) 13 | { 14 | if (age < 0 || age > 20) 15 | { 16 | this->age = 0; 17 | return -1; 18 | } 19 | this->age = age; 20 | return 0; 21 | } 22 | 23 | void Dog::printInfo(void) 24 | { 25 | printf("name = %s, age = %d\n", name, age); 26 | } 27 | 28 | void printVersion(void) 29 | { 30 | printf("Dog v1, by weidongshan\n"); 31 | } 32 | 33 | } 34 | 35 | -------------------------------------------------------------------------------- /03th_ProgramStructure/03th/person.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | 5 | namespace A { 6 | 7 | void Person::setName(char *name) 8 | { 9 | this->name = name; 10 | } 11 | 12 | int Person::setAge(int age) 13 | { 14 | if (age < 0 || age > 150) 15 | { 16 | this->age = 0; 17 | return -1; 18 | } 19 | this->age = age; 20 | return 0; 21 | } 22 | 23 | void Person::printInfo(void) 24 | { 25 | printf("name = %s, age = %d, work = %s\n", name, age, work); 26 | } 27 | 28 | void printVersion(void) 29 | { 30 | printf("Person v1, by weidongshan\n"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /03th_ProgramStructure/04th/person.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | 5 | namespace A { 6 | 7 | void Person::setName(char *name) 8 | { 9 | this->name = name; 10 | } 11 | 12 | int Person::setAge(int age) 13 | { 14 | if (age < 0 || age > 150) 15 | { 16 | this->age = 0; 17 | return -1; 18 | } 19 | this->age = age; 20 | return 0; 21 | } 22 | 23 | void Person::printInfo(void) 24 | { 25 | printf("name = %s, age = %d, work = %s\n", name, age, work); 26 | } 27 | 28 | void printVersion(void) 29 | { 30 | printf("Person v1, by weidongshan\n"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /03th_ProgramStructure/05th/person.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | 5 | namespace A { 6 | 7 | void Person::setName(char *name) 8 | { 9 | this->name = name; 10 | } 11 | 12 | int Person::setAge(int age) 13 | { 14 | if (age < 0 || age > 150) 15 | { 16 | this->age = 0; 17 | return -1; 18 | } 19 | this->age = age; 20 | return 0; 21 | } 22 | 23 | void Person::printInfo(void) 24 | { 25 | printf("name = %s, age = %d, work = %s\n", name, age, work); 26 | } 27 | 28 | void printVersion(void) 29 | { 30 | printf("Person v1, by weidongshan\n"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /03th_ProgramStructure/06th/dog.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "dog.h" 4 | 5 | namespace C { 6 | 7 | using namespace std; 8 | 9 | void Dog::setName(char *name) 10 | { 11 | this->name = name; 12 | } 13 | 14 | int Dog::setAge(int age) 15 | { 16 | if (age < 0 || age > 20) 17 | { 18 | this->age = 0; 19 | return -1; 20 | } 21 | this->age = age; 22 | return 0; 23 | } 24 | 25 | void Dog::printInfo(void) 26 | { 27 | cout<<"name = "<name = name; 7 | } 8 | 9 | char *Chinese::getName(void) 10 | { 11 | return this->name; 12 | } 13 | 14 | 15 | void Chinese::eating(void) 16 | { 17 | cout<<"use chopsticks to eat"< 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Human { 13 | private: 14 | char *name; 15 | 16 | public: 17 | void setName(char *name); 18 | char *getName(void); 19 | virtual void eating(void) = 0; 20 | virtual void wearing(void) = 0; 21 | virtual void driving(void) = 0; 22 | 23 | }; 24 | 25 | Human& CreateEnglishman(char *name, int age, char *address); 26 | Human& CreateChinese(char *name, int age, char *address); 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /15th_abstract/3th/1th/Englishman.cpp: -------------------------------------------------------------------------------- 1 | #include "Englishman.h" 2 | 3 | void Englishman::setName(char *name) 4 | { 5 | this->name = name; 6 | } 7 | 8 | char *Englishman::getName(void) 9 | { 10 | return this->name; 11 | } 12 | 13 | void Englishman::eating(void) 14 | { 15 | cout<<"use knife to eat"< 3 | 4 | struct person { 5 | char *name; 6 | int age; 7 | char *work; 8 | 9 | void (*printInfo)(struct person *per); 10 | }; 11 | 12 | void printInfo(struct person *per) 13 | { 14 | printf("name = %s, age = %d, work = %s\n", per->name, per->age, per->work); 15 | } 16 | int main(int argc, char **argv) 17 | { 18 | struct person persons[] = { 19 | {"zhangsan", 10, "teacher", printInfo}, 20 | {"lisi", 16, "doctor", printInfo}, 21 | }; 22 | 23 | persons[0].printInfo(&persons[0]); 24 | persons[1].printInfo(&persons[1]); 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /03th_ProgramStructure/06th/person.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "person.h" 4 | 5 | namespace A { 6 | 7 | void Person::setName(char *name) 8 | { 9 | this->name = name; 10 | } 11 | 12 | int Person::setAge(int age) 13 | { 14 | if (age < 0 || age > 150) 15 | { 16 | this->age = 0; 17 | return -1; 18 | } 19 | this->age = age; 20 | return 0; 21 | } 22 | 23 | void Person::printInfo(void) 24 | { 25 | std::cout<<"name = "< 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | 12 | class Human { 13 | private: 14 | char *name; 15 | 16 | public: 17 | void setName(char *name); 18 | char *getName(void); 19 | virtual void eating(void) = 0; 20 | virtual void wearing(void) = 0; 21 | virtual void driving(void) = 0; 22 | virtual ~Human() {cout<<"~Human"< 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | class Person { 9 | 10 | public: 11 | 12 | Person() { 13 | cout <<"Pserson()"<printInfo(); 31 | } 32 | 33 | int main(int argc, char **argv) 34 | { 35 | int i; 36 | 37 | for (i = 0; i < 2; i++) 38 | test_func(); 39 | return 0; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /15th_abstract/7th/Englishman.cpp: -------------------------------------------------------------------------------- 1 | #include "Englishman.h" 2 | 3 | 4 | void Englishman::eating(void) 5 | { 6 | cout<<"use knife to eat"<age = age; 29 | memset(this->address, 0, 100); 30 | strcpy(this->address, address); 31 | } 32 | 33 | 34 | -------------------------------------------------------------------------------- /19th_smartpointer/person2.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | class Person { 9 | 10 | public: 11 | 12 | Person() { 13 | cout <<"Pserson()"< 3 | 4 | struct person { 5 | char *name; 6 | int age; 7 | char *work; 8 | 9 | void (*printInfo)(struct person *per); 10 | }; 11 | 12 | void printInfo(struct person *per) 13 | { 14 | printf("name = %s, age = %d, work = %s\n", per->name, persons[i].age, persons[i].work); 15 | } 16 | int main(int argc, char **argv) 17 | { 18 | struct person persons[] = { 19 | {"zhangsan", 10, "teacher"}, 20 | {"lisi", 16, "doctor"}, 21 | }; 22 | 23 | 24 | int i; 25 | 26 | for (i = 0; i < 2; i++) 27 | { 28 | printf("name = %s, age = %d, work = %s\n", persons[i].name, persons[i].age, persons[i].work); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | -------------------------------------------------------------------------------- /16th_template/max3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<__PRETTY_FUNCTION__< 3 | 4 | class Person { 5 | private: 6 | char *name; 7 | int age; 8 | char *work; 9 | 10 | public: 11 | void setName(char *n) 12 | { 13 | name = n; 14 | } 15 | int setAge(int a) 16 | { 17 | if (a < 0 || a > 150) 18 | { 19 | age = 0; 20 | return -1; 21 | } 22 | age = a; 23 | return 0; 24 | } 25 | void printInfo(void) 26 | { 27 | printf("name = %s, age = %d, work = %s\n", name, age, work); 28 | } 29 | }; 30 | 31 | int main(int argc, char **argv) 32 | { 33 | Person per; 34 | 35 | //per.name = "zhangsan"; 36 | per.setName("zhangsan"); 37 | per.setAge(200); 38 | per.printInfo(); 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /05th_pointer_reference/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | int add_one(int a) 7 | { 8 | a = a+1; 9 | return a; 10 | } 11 | 12 | int add_one(int *a) 13 | { 14 | *a = *a + 1; 15 | return *a; 16 | } 17 | 18 | int add_one_ref(int &b) 19 | { 20 | b = b+1; 21 | return b; 22 | } 23 | 24 | int main(int argc, char **argv) 25 | { 26 | int a = 99; 27 | int &c = a; 28 | cout< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | 8 | template 9 | class AAA { 10 | private: 11 | T t; 12 | public: 13 | void test_func(const T &t); 14 | void print(void); 15 | }; 16 | 17 | template void AAA::test_func(const T &t) 18 | { 19 | this->t = t; 20 | } 21 | 22 | template 23 | void AAA::print(void) 24 | { 25 | cout< a; 31 | 32 | a.test_func(1); 33 | a.print(); 34 | 35 | AAA b; 36 | 37 | b.test_func(1.23); 38 | b.print(); 39 | 40 | return 0; 41 | } 42 | 43 | -------------------------------------------------------------------------------- /13th_Polymorphism/Human.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Human { 8 | public: 9 | void eating(void) { cout<<"use hand to eat"< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | T& mymax(T& a, T& b) 26 | { 27 | cout<<__PRETTY_FUNCTION__< 3 | 4 | using namespace std; 5 | 6 | class Singleton; 7 | 8 | Singleton *gInstance; 9 | 10 | 11 | class Singleton { 12 | public: 13 | static Singleton *getInstance() 14 | { 15 | if (NULL == gInstance) 16 | gInstance = new Singleton; 17 | return gInstance; 18 | } 19 | 20 | Singleton() 21 | { 22 | cout<<"Singleton()"<printInfo(); 33 | 34 | Singleton *s2 = Singleton::getInstance(); 35 | s2->printInfo(); 36 | 37 | Singleton *s3 = Singleton::getInstance(); 38 | s3->printInfo(); 39 | 40 | return 0; 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /04th_overload/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | int add(int a, int b) 7 | { 8 | cout<<"add int+int"<age = age; 29 | memset(this->address, 0, 100); 30 | strcpy(this->address, address); 31 | } 32 | 33 | Human& CreateEnglishman(char *name, int age, char *address) 34 | { 35 | return *(new Englishman(name, age, address)); 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /15th_abstract/9th/Englishman.cpp: -------------------------------------------------------------------------------- 1 | #include "Englishman.h" 2 | 3 | 4 | void Englishman::eating(void) 5 | { 6 | cout<<"use knife to eat"<age = age; 29 | memset(this->address, 0, 100); 30 | strcpy(this->address, address); 31 | } 32 | 33 | Human& CreateEnglishman(char *name, int age, char *address) 34 | { 35 | return *(new Englishman(name, age, address)); 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /08th_friend/point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Point { 8 | private: 9 | int x; 10 | int y; 11 | 12 | public: 13 | Point() {} 14 | Point(int x, int y) : x(x), y(y) {} 15 | 16 | int getX(){ return x; } 17 | int getY(){ return y; } 18 | void setX(int x){ this->x = x; } 19 | void setY(int y){ this->y = y; } 20 | void printInfo() 21 | { 22 | cout<<"("< 3 | 4 | class Person { 5 | private: 6 | char *name; 7 | int age; 8 | char *work; 9 | 10 | public: 11 | void setName(char *name); 12 | int setAge(int age); 13 | void printInfo(void); 14 | }; 15 | 16 | void Person::setName(char *name) 17 | { 18 | this->name = name; 19 | } 20 | 21 | int Person::setAge(int age) 22 | { 23 | if (age < 0 || age > 150) 24 | { 25 | this->age = 0; 26 | return -1; 27 | } 28 | this->age = age; 29 | return 0; 30 | } 31 | 32 | void Person::printInfo(void) 33 | { 34 | printf("name = %s, age = %d, work = %s\n", name, age, work); 35 | } 36 | 37 | int main(int argc, char **argv) 38 | { 39 | Person per; 40 | 41 | //per.name = "zhangsan"; 42 | per.setName("zhangsan"); 43 | per.setAge(200); 44 | per.printInfo(); 45 | 46 | return 0; 47 | } 48 | 49 | -------------------------------------------------------------------------------- /08th_friend/point2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Point { 8 | private: 9 | int x; 10 | int y; 11 | 12 | public: 13 | Point() {} 14 | Point(int x, int y) : x(x), y(y) {} 15 | 16 | int getX(){ return x; } 17 | int getY(){ return y; } 18 | void setX(int x){ this->x = x; } 19 | void setY(int y){ this->y = y; } 20 | void printInfo() 21 | { 22 | cout<<"("< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | T& mymax(T& a, T& b) 26 | { 27 | cout<<__PRETTY_FUNCTION__< 21 | 22 | #endif // ANDROID_UTILS_ATOMIC_H 23 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/utils/Atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_ATOMIC_H 18 | #define ANDROID_UTILS_ATOMIC_H 19 | 20 | #include 21 | 22 | #endif // ANDROID_UTILS_ATOMIC_H 23 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/utils/Atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_ATOMIC_H 18 | #define ANDROID_UTILS_ATOMIC_H 19 | 20 | #include 21 | 22 | #endif // ANDROID_UTILS_ATOMIC_H 23 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/utils/Atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_ATOMIC_H 18 | #define ANDROID_UTILS_ATOMIC_H 19 | 20 | #include 21 | 22 | #endif // ANDROID_UTILS_ATOMIC_H 23 | -------------------------------------------------------------------------------- /13th_Polymorphism/Human2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Human { 8 | private: 9 | int a; 10 | public: 11 | virtual void eating(void) { cout<<"use hand to eat"<"< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<"1: "<<__PRETTY_FUNCTION__< 32 | const T& mymax(T& a, T& b) 33 | { 34 | cout<<"2: "<<__PRETTY_FUNCTION__< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | 8 | template 9 | class AAA { 10 | private: 11 | T t; 12 | public: 13 | void test_func(const T &t); 14 | void print(void); 15 | }; 16 | 17 | template void AAA::test_func(const T &t) 18 | { 19 | this->t = t; 20 | } 21 | 22 | template 23 | void AAA::print(void) 24 | { 25 | cout< 30 | class AAA { 31 | public: 32 | void test_func_int(const int & t) 33 | { 34 | cout<::print_int(void) 40 | { 41 | cout<<"for test"< a; 47 | 48 | a.test_func_int(1); 49 | a.print_int(); 50 | 51 | AAA b; 52 | 53 | b.test_func(1.23); 54 | b.print(); 55 | 56 | return 0; 57 | } 58 | 59 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/cutils/partition_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_PARTITION_WIPED_H__ 18 | #define __CUTILS_PARTITION_WIPED_H__ 19 | 20 | __BEGIN_DECLS 21 | 22 | int partition_wiped(char *source); 23 | void erase_footer(const char *dev_path, long long size); 24 | 25 | __END_DECLS 26 | 27 | #endif /* __CUTILS_PARTITION_WIPED_H__ */ 28 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/partition_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_PARTITION_WIPED_H__ 18 | #define __CUTILS_PARTITION_WIPED_H__ 19 | 20 | __BEGIN_DECLS 21 | 22 | int partition_wiped(char *source); 23 | void erase_footer(const char *dev_path, long long size); 24 | 25 | __END_DECLS 26 | 27 | #endif /* __CUTILS_PARTITION_WIPED_H__ */ 28 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/partition_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_PARTITION_WIPED_H__ 18 | #define __CUTILS_PARTITION_WIPED_H__ 19 | 20 | __BEGIN_DECLS 21 | 22 | int partition_wiped(char *source); 23 | void erase_footer(const char *dev_path, long long size); 24 | 25 | __END_DECLS 26 | 27 | #endif /* __CUTILS_PARTITION_WIPED_H__ */ 28 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/partition_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_PARTITION_WIPED_H__ 18 | #define __CUTILS_PARTITION_WIPED_H__ 19 | 20 | __BEGIN_DECLS 21 | 22 | int partition_wiped(char *source); 23 | void erase_footer(const char *dev_path, long long size); 24 | 25 | __END_DECLS 26 | 27 | #endif /* __CUTILS_PARTITION_WIPED_H__ */ 28 | -------------------------------------------------------------------------------- /06th_constructor/person.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | class Person { 6 | private: 7 | char *name; 8 | int age; 9 | char *work; 10 | 11 | public: 12 | 13 | Person() {cout <<"Pserson()"<name = name; 18 | } 19 | 20 | Person(char *name, int age) 21 | { 22 | cout <<"Pserson(char*, int)"<name = name; 24 | this->age = age; 25 | } 26 | 27 | void setName(char *n) 28 | { 29 | name = n; 30 | } 31 | int setAge(int a) 32 | { 33 | if (a < 0 || a > 150) 34 | { 35 | age = 0; 36 | return -1; 37 | } 38 | age = a; 39 | return 0; 40 | } 41 | void printInfo(void) 42 | { 43 | //printf("name = %s, age = %d, work = %s\n", name, age, work); 44 | cout<<"name = "< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<"1: "<<__PRETTY_FUNCTION__< 32 | const T& mymax(T& a, T& b) 33 | { 34 | cout<<"2: "<<__PRETTY_FUNCTION__< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Human { 8 | private: 9 | int a; 10 | public: 11 | virtual void eating(void) { cout<<"use hand to eat"<eating(); 45 | delete p[i]; 46 | } 47 | 48 | 49 | return 0; 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /09th_operator/point.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Point { 8 | private: 9 | int x; 10 | int y; 11 | 12 | public: 13 | Point() {} 14 | Point(int x, int y) : x(x), y(y) {} 15 | 16 | int getX(){ return x; } 17 | int getY(){ return y; } 18 | void setX(int x){ this->x = x; } 19 | void setY(int y){ this->y = y; } 20 | void printInfo() 21 | { 22 | cout<<"("< 21 | #include 22 | 23 | namespace android { 24 | 25 | int64_t uptimeMillis(); 26 | int64_t elapsedRealtime(); 27 | int64_t elapsedRealtimeNano(); 28 | 29 | }; // namespace android 30 | 31 | #endif // ANDROID_UTILS_SYSTEMCLOCK_H 32 | 33 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/utils/SystemClock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_SYSTEMCLOCK_H 18 | #define ANDROID_UTILS_SYSTEMCLOCK_H 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | int64_t uptimeMillis(); 26 | int64_t elapsedRealtime(); 27 | int64_t elapsedRealtimeNano(); 28 | 29 | }; // namespace android 30 | 31 | #endif // ANDROID_UTILS_SYSTEMCLOCK_H 32 | 33 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/utils/SystemClock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_SYSTEMCLOCK_H 18 | #define ANDROID_UTILS_SYSTEMCLOCK_H 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | int64_t uptimeMillis(); 26 | int64_t elapsedRealtime(); 27 | int64_t elapsedRealtimeNano(); 28 | 29 | }; // namespace android 30 | 31 | #endif // ANDROID_UTILS_SYSTEMCLOCK_H 32 | 33 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/utils/SystemClock.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_UTILS_SYSTEMCLOCK_H 18 | #define ANDROID_UTILS_SYSTEMCLOCK_H 19 | 20 | #include 21 | #include 22 | 23 | namespace android { 24 | 25 | int64_t uptimeMillis(); 26 | int64_t elapsedRealtime(); 27 | int64_t elapsedRealtimeNano(); 28 | 29 | }; // namespace android 30 | 31 | #endif // ANDROID_UTILS_SYSTEMCLOCK_H 32 | 33 | -------------------------------------------------------------------------------- /19th_smartpointer/person3.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | class Person { 9 | 10 | public: 11 | 12 | Person() { 13 | cout <<"Pserson()"<() 48 | { 49 | return p; 50 | } 51 | 52 | }; 53 | 54 | void test_func(void) 55 | { 56 | sp s = new Person(); 57 | 58 | s->printInfo(); 59 | 60 | //Person *p = new Person(); 61 | //p->printInfo(); 62 | //delete p; 63 | 64 | 65 | } 66 | 67 | int main(int argc, char **argv) 68 | { 69 | int i; 70 | 71 | for (i = 0; i < 2; i++) 72 | test_func(); 73 | return 0; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/cutils/dir_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | typedef enum { 18 | SHA_1, 19 | } HashAlgorithm; 20 | 21 | int get_file_hash(HashAlgorithm algorithm, const char *path, 22 | char *output_string, size_t max_output_string); 23 | 24 | int get_recursive_hash_manifest(HashAlgorithm algorithm, 25 | const char *directory_path, 26 | char **output_string); 27 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/utils/Functor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_FUNCTOR_H 18 | #define ANDROID_FUNCTOR_H 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | class Functor { 25 | public: 26 | Functor() {} 27 | virtual ~Functor() {} 28 | virtual status_t operator ()(int /*what*/, void* /*data*/) { return NO_ERROR; } 29 | }; 30 | 31 | }; // namespace android 32 | 33 | #endif // ANDROID_FUNCTOR_H 34 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/dir_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | typedef enum { 18 | SHA_1, 19 | } HashAlgorithm; 20 | 21 | int get_file_hash(HashAlgorithm algorithm, const char *path, 22 | char *output_string, size_t max_output_string); 23 | 24 | int get_recursive_hash_manifest(HashAlgorithm algorithm, 25 | const char *directory_path, 26 | char **output_string); 27 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/utils/Functor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_FUNCTOR_H 18 | #define ANDROID_FUNCTOR_H 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | class Functor { 25 | public: 26 | Functor() {} 27 | virtual ~Functor() {} 28 | virtual status_t operator ()(int /*what*/, void* /*data*/) { return NO_ERROR; } 29 | }; 30 | 31 | }; // namespace android 32 | 33 | #endif // ANDROID_FUNCTOR_H 34 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/dir_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | typedef enum { 18 | SHA_1, 19 | } HashAlgorithm; 20 | 21 | int get_file_hash(HashAlgorithm algorithm, const char *path, 22 | char *output_string, size_t max_output_string); 23 | 24 | int get_recursive_hash_manifest(HashAlgorithm algorithm, 25 | const char *directory_path, 26 | char **output_string); 27 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/utils/Functor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_FUNCTOR_H 18 | #define ANDROID_FUNCTOR_H 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | class Functor { 25 | public: 26 | Functor() {} 27 | virtual ~Functor() {} 28 | virtual status_t operator ()(int /*what*/, void* /*data*/) { return NO_ERROR; } 29 | }; 30 | 31 | }; // namespace android 32 | 33 | #endif // ANDROID_FUNCTOR_H 34 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/dir_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | typedef enum { 18 | SHA_1, 19 | } HashAlgorithm; 20 | 21 | int get_file_hash(HashAlgorithm algorithm, const char *path, 22 | char *output_string, size_t max_output_string); 23 | 24 | int get_recursive_hash_manifest(HashAlgorithm algorithm, 25 | const char *directory_path, 26 | char **output_string); 27 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/utils/Functor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_FUNCTOR_H 18 | #define ANDROID_FUNCTOR_H 19 | 20 | #include 21 | 22 | namespace android { 23 | 24 | class Functor { 25 | public: 26 | Functor() {} 27 | virtual ~Functor() {} 28 | virtual status_t operator ()(int /*what*/, void* /*data*/) { return NO_ERROR; } 29 | }; 30 | 31 | }; // namespace android 32 | 33 | #endif // ANDROID_FUNCTOR_H 34 | -------------------------------------------------------------------------------- /18th_exception/exception3.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | void C(int i) 10 | { 11 | int a = 1; 12 | double b= 1.2; 13 | float c = 1.3; 14 | 15 | if (i == 0) 16 | { 17 | cout<<"In C, it is OK"<"< 21 | 22 | #ifndef HAVE_OPEN_MEMSTREAM 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | FILE* open_memstream(char** bufp, size_t* sizep); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /*!HAVE_OPEN_MEMSTREAM*/ 35 | 36 | #endif /*__CUTILS_OPEN_MEMSTREAM_H__*/ 37 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/open_memstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_OPEN_MEMSTREAM_H__ 18 | #define __CUTILS_OPEN_MEMSTREAM_H__ 19 | 20 | #include 21 | 22 | #ifndef HAVE_OPEN_MEMSTREAM 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | FILE* open_memstream(char** bufp, size_t* sizep); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /*!HAVE_OPEN_MEMSTREAM*/ 35 | 36 | #endif /*__CUTILS_OPEN_MEMSTREAM_H__*/ 37 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/open_memstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_OPEN_MEMSTREAM_H__ 18 | #define __CUTILS_OPEN_MEMSTREAM_H__ 19 | 20 | #include 21 | 22 | #ifndef HAVE_OPEN_MEMSTREAM 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | FILE* open_memstream(char** bufp, size_t* sizep); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /*!HAVE_OPEN_MEMSTREAM*/ 35 | 36 | #endif /*__CUTILS_OPEN_MEMSTREAM_H__*/ 37 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/open_memstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_OPEN_MEMSTREAM_H__ 18 | #define __CUTILS_OPEN_MEMSTREAM_H__ 19 | 20 | #include 21 | 22 | #ifndef HAVE_OPEN_MEMSTREAM 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | FILE* open_memstream(char** bufp, size_t* sizep); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /*!HAVE_OPEN_MEMSTREAM*/ 35 | 36 | #endif /*__CUTILS_OPEN_MEMSTREAM_H__*/ 37 | -------------------------------------------------------------------------------- /16th_template/max7.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<"1: "<<__PRETTY_FUNCTION__< 32 | const T& mymax(T& a, T& b) 33 | { 34 | cout<<"2: "<<__PRETTY_FUNCTION__< 47 | const T mymax(T a, T b) 48 | { 49 | cout<<"4: "<<__PRETTY_FUNCTION__< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<"1: "<<__PRETTY_FUNCTION__< 32 | const T& mymax(T& a, T& b) 33 | { 34 | cout<<"2: "<<__PRETTY_FUNCTION__< 39 | const T mymax(T * a, T* b) 40 | { 41 | cout<<"4: "<<__PRETTY_FUNCTION__< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<"1: "<<__PRETTY_FUNCTION__< 32 | const T& mymax(T& a, T& b) 33 | { 34 | cout<<"2: "<<__PRETTY_FUNCTION__< 39 | const T mymax(const T * a, const T* b) 40 | { 41 | cout<<"4: "<<__PRETTY_FUNCTION__< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Human { 8 | private: 9 | int a; 10 | public: 11 | virtual void eating(void) { cout<<"use hand to eat"< 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int uevent_open_socket(int buf_sz, bool passcred); 28 | ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length); 29 | ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* __CUTILS_UEVENT_H */ 36 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/uevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_UEVENT_H 18 | #define __CUTILS_UEVENT_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int uevent_open_socket(int buf_sz, bool passcred); 28 | ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length); 29 | ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* __CUTILS_UEVENT_H */ 36 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/uevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_UEVENT_H 18 | #define __CUTILS_UEVENT_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int uevent_open_socket(int buf_sz, bool passcred); 28 | ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length); 29 | ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* __CUTILS_UEVENT_H */ 36 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/uevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_UEVENT_H 18 | #define __CUTILS_UEVENT_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | int uevent_open_socket(int buf_sz, bool passcred); 28 | ssize_t uevent_kernel_multicast_recv(int socket, void *buffer, size_t length); 29 | ssize_t uevent_kernel_multicast_uid_recv(int socket, void *buffer, size_t length, uid_t *uid); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif /* __CUTILS_UEVENT_H */ 36 | -------------------------------------------------------------------------------- /19th_smartpointer/person5.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | class Person { 9 | 10 | public: 11 | 12 | Person() { 13 | cout <<"Pserson()"<() 54 | { 55 | return p; 56 | } 57 | 58 | }; 59 | 60 | void test_func(sp &other) 61 | { 62 | sp s = other; 63 | 64 | s->printInfo(); 65 | 66 | //Person *p = new Person(); 67 | //p->printInfo(); 68 | //delete p; 69 | 70 | 71 | } 72 | 73 | int main(int argc, char **argv) 74 | { 75 | int i; 76 | 77 | sp other = new Person(); 78 | 79 | for (i = 0; i < 2; i++) 80 | test_func(other); 81 | return 0; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /16th_template/max11.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<"1: "<<__PRETTY_FUNCTION__< 33 | const T& mymax(T& a, T& b) 34 | { 35 | cout<<"2: "<<__PRETTY_FUNCTION__< 41 | const T mymax(const T * a, const T* b) 42 | { 43 | cout<<"4: "<<__PRETTY_FUNCTION__< 26 | 27 | #else /*not HAVE_ENDIAN_H*/ 28 | 29 | #define __BIG_ENDIAN 0x1000 30 | #define __LITTLE_ENDIAN 0x0001 31 | 32 | #if defined(HAVE_LITTLE_ENDIAN) 33 | # define __BYTE_ORDER __LITTLE_ENDIAN 34 | #else 35 | # define __BYTE_ORDER __BIG_ENDIAN 36 | #endif 37 | 38 | #endif /*not HAVE_ENDIAN_H*/ 39 | 40 | #endif /*_LIBS_UTILS_ENDIAN_H*/ 41 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/utils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREADS_H 18 | #define _LIBS_UTILS_THREADS_H 19 | 20 | /* 21 | * Please, DO NOT USE! 22 | * 23 | * This file is here only for legacy reasons. Instead, include directly 24 | * the headers you need below. 25 | * 26 | */ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #endif // _LIBS_UTILS_THREADS_H 39 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/utils/Endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Android endian-ness defines. 19 | // 20 | #ifndef _LIBS_UTILS_ENDIAN_H 21 | #define _LIBS_UTILS_ENDIAN_H 22 | 23 | #if defined(HAVE_ENDIAN_H) 24 | 25 | #include 26 | 27 | #else /*not HAVE_ENDIAN_H*/ 28 | 29 | #define __BIG_ENDIAN 0x1000 30 | #define __LITTLE_ENDIAN 0x0001 31 | 32 | #if defined(HAVE_LITTLE_ENDIAN) 33 | # define __BYTE_ORDER __LITTLE_ENDIAN 34 | #else 35 | # define __BYTE_ORDER __BIG_ENDIAN 36 | #endif 37 | 38 | #endif /*not HAVE_ENDIAN_H*/ 39 | 40 | #endif /*_LIBS_UTILS_ENDIAN_H*/ 41 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/utils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREADS_H 18 | #define _LIBS_UTILS_THREADS_H 19 | 20 | /* 21 | * Please, DO NOT USE! 22 | * 23 | * This file is here only for legacy reasons. Instead, include directly 24 | * the headers you need below. 25 | * 26 | */ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #endif // _LIBS_UTILS_THREADS_H 39 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/utils/Endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Android endian-ness defines. 19 | // 20 | #ifndef _LIBS_UTILS_ENDIAN_H 21 | #define _LIBS_UTILS_ENDIAN_H 22 | 23 | #if defined(HAVE_ENDIAN_H) 24 | 25 | #include 26 | 27 | #else /*not HAVE_ENDIAN_H*/ 28 | 29 | #define __BIG_ENDIAN 0x1000 30 | #define __LITTLE_ENDIAN 0x0001 31 | 32 | #if defined(HAVE_LITTLE_ENDIAN) 33 | # define __BYTE_ORDER __LITTLE_ENDIAN 34 | #else 35 | # define __BYTE_ORDER __BIG_ENDIAN 36 | #endif 37 | 38 | #endif /*not HAVE_ENDIAN_H*/ 39 | 40 | #endif /*_LIBS_UTILS_ENDIAN_H*/ 41 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/utils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREADS_H 18 | #define _LIBS_UTILS_THREADS_H 19 | 20 | /* 21 | * Please, DO NOT USE! 22 | * 23 | * This file is here only for legacy reasons. Instead, include directly 24 | * the headers you need below. 25 | * 26 | */ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #endif // _LIBS_UTILS_THREADS_H 39 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/utils/Endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Android endian-ness defines. 19 | // 20 | #ifndef _LIBS_UTILS_ENDIAN_H 21 | #define _LIBS_UTILS_ENDIAN_H 22 | 23 | #if defined(HAVE_ENDIAN_H) 24 | 25 | #include 26 | 27 | #else /*not HAVE_ENDIAN_H*/ 28 | 29 | #define __BIG_ENDIAN 0x1000 30 | #define __LITTLE_ENDIAN 0x0001 31 | 32 | #if defined(HAVE_LITTLE_ENDIAN) 33 | # define __BYTE_ORDER __LITTLE_ENDIAN 34 | #else 35 | # define __BYTE_ORDER __BIG_ENDIAN 36 | #endif 37 | 38 | #endif /*not HAVE_ENDIAN_H*/ 39 | 40 | #endif /*_LIBS_UTILS_ENDIAN_H*/ 41 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/utils/threads.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _LIBS_UTILS_THREADS_H 18 | #define _LIBS_UTILS_THREADS_H 19 | 20 | /* 21 | * Please, DO NOT USE! 22 | * 23 | * This file is here only for legacy reasons. Instead, include directly 24 | * the headers you need below. 25 | * 26 | */ 27 | 28 | #include 29 | 30 | #ifdef __cplusplus 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #endif // _LIBS_UTILS_THREADS_H 39 | -------------------------------------------------------------------------------- /13th_Polymorphism/Human6.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Human { 8 | private: 9 | int a; 10 | public: 11 | virtual void eating(void) { cout<<"use hand to eat"< 24 | 25 | /* get #of elements in a static array */ 26 | #ifndef NELEM 27 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 28 | #endif 29 | 30 | namespace android { 31 | 32 | typedef void (*sysprop_change_callback)(void); 33 | void add_sysprop_change_callback(sysprop_change_callback cb, int priority); 34 | void report_sysprop_change(); 35 | 36 | }; // namespace android 37 | 38 | #endif // _LIBS_UTILS_MISC_H 39 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/utils/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Handy utility functions and portability code. 19 | // 20 | #ifndef _LIBS_UTILS_MISC_H 21 | #define _LIBS_UTILS_MISC_H 22 | 23 | #include 24 | 25 | /* get #of elements in a static array */ 26 | #ifndef NELEM 27 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 28 | #endif 29 | 30 | namespace android { 31 | 32 | typedef void (*sysprop_change_callback)(void); 33 | void add_sysprop_change_callback(sysprop_change_callback cb, int priority); 34 | void report_sysprop_change(); 35 | 36 | }; // namespace android 37 | 38 | #endif // _LIBS_UTILS_MISC_H 39 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/utils/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Handy utility functions and portability code. 19 | // 20 | #ifndef _LIBS_UTILS_MISC_H 21 | #define _LIBS_UTILS_MISC_H 22 | 23 | #include 24 | 25 | /* get #of elements in a static array */ 26 | #ifndef NELEM 27 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 28 | #endif 29 | 30 | namespace android { 31 | 32 | typedef void (*sysprop_change_callback)(void); 33 | void add_sysprop_change_callback(sysprop_change_callback cb, int priority); 34 | void report_sysprop_change(); 35 | 36 | }; // namespace android 37 | 38 | #endif // _LIBS_UTILS_MISC_H 39 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/utils/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2005 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // 18 | // Handy utility functions and portability code. 19 | // 20 | #ifndef _LIBS_UTILS_MISC_H 21 | #define _LIBS_UTILS_MISC_H 22 | 23 | #include 24 | 25 | /* get #of elements in a static array */ 26 | #ifndef NELEM 27 | # define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 28 | #endif 29 | 30 | namespace android { 31 | 32 | typedef void (*sysprop_change_callback)(void); 33 | void add_sysprop_change_callback(sysprop_change_callback cb, int priority); 34 | void report_sysprop_change(); 35 | 36 | }; // namespace android 37 | 38 | #endif // _LIBS_UTILS_MISC_H 39 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/cutils/multiuser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_MULTIUSER_H 18 | #define __CUTILS_MULTIUSER_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | // NOTE: keep in sync with android.os.UserId 27 | 28 | #define MULTIUSER_APP_PER_USER_RANGE 100000 29 | 30 | typedef uid_t userid_t; 31 | typedef uid_t appid_t; 32 | 33 | extern userid_t multiuser_get_user_id(uid_t uid); 34 | extern appid_t multiuser_get_app_id(uid_t uid); 35 | extern uid_t multiuser_get_uid(userid_t userId, appid_t appId); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* __CUTILS_MULTIUSER_H */ 42 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/multiuser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_MULTIUSER_H 18 | #define __CUTILS_MULTIUSER_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | // NOTE: keep in sync with android.os.UserId 27 | 28 | #define MULTIUSER_APP_PER_USER_RANGE 100000 29 | 30 | typedef uid_t userid_t; 31 | typedef uid_t appid_t; 32 | 33 | extern userid_t multiuser_get_user_id(uid_t uid); 34 | extern appid_t multiuser_get_app_id(uid_t uid); 35 | extern uid_t multiuser_get_uid(userid_t userId, appid_t appId); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* __CUTILS_MULTIUSER_H */ 42 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/multiuser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_MULTIUSER_H 18 | #define __CUTILS_MULTIUSER_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | // NOTE: keep in sync with android.os.UserId 27 | 28 | #define MULTIUSER_APP_PER_USER_RANGE 100000 29 | 30 | typedef uid_t userid_t; 31 | typedef uid_t appid_t; 32 | 33 | extern userid_t multiuser_get_user_id(uid_t uid); 34 | extern appid_t multiuser_get_app_id(uid_t uid); 35 | extern uid_t multiuser_get_uid(userid_t userId, appid_t appId); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* __CUTILS_MULTIUSER_H */ 42 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/multiuser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __CUTILS_MULTIUSER_H 18 | #define __CUTILS_MULTIUSER_H 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | // NOTE: keep in sync with android.os.UserId 27 | 28 | #define MULTIUSER_APP_PER_USER_RANGE 100000 29 | 30 | typedef uid_t userid_t; 31 | typedef uid_t appid_t; 32 | 33 | extern userid_t multiuser_get_user_id(uid_t uid); 34 | extern appid_t multiuser_get_app_id(uid_t uid); 35 | extern uid_t multiuser_get_uid(userid_t userId, appid_t appId); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* __CUTILS_MULTIUSER_H */ 42 | -------------------------------------------------------------------------------- /15th_abstract/1th/Human.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Human { 8 | private: 9 | int a; 10 | public: 11 | virtual void eating(void) = 0; 12 | virtual void wearing(void) = 0; 13 | virtual void driving(void) = 0; 14 | virtual ~Human() { cout<<"~Human()"< 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class MyException { 10 | public: 11 | void what(void) { cout<<"This is MyException"<"< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | /* 8 | int& max(int& a, int& b) 9 | { 10 | return (a < b)? b : a; 11 | } 12 | 13 | double& max(double& a, double& b) 14 | { 15 | return (a < b)? b : a; 16 | } 17 | 18 | float& max(float& a, float& b) 19 | { 20 | return (a < b)? b : a; 21 | } 22 | */ 23 | 24 | template 25 | const T& mymax(const T& a, const T& b) 26 | { 27 | cout<<"1: "<<__PRETTY_FUNCTION__< 33 | const T& mymax(T& a, T& b) 34 | { 35 | cout<<"2: "<<__PRETTY_FUNCTION__< 41 | const T mymax(T * a, T* b) 42 | { 43 | cout<<"4: "<<__PRETTY_FUNCTION__< 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int ashmem_create_region(const char *name, size_t size); 20 | int ashmem_set_prot_region(int fd, int prot); 21 | int ashmem_pin_region(int fd, size_t offset, size_t len); 22 | int ashmem_unpin_region(int fd, size_t offset, size_t len); 23 | int ashmem_get_size_region(int fd); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #ifndef __ASHMEMIOC /* in case someone included too */ 30 | 31 | #define ASHMEM_NAME_LEN 256 32 | 33 | #define ASHMEM_NAME_DEF "dev/ashmem" 34 | 35 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 36 | #define ASHMEM_NOT_PURGED 0 37 | #define ASHMEM_WAS_PURGED 1 38 | 39 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 40 | #define ASHMEM_IS_UNPINNED 0 41 | #define ASHMEM_IS_PINNED 1 42 | 43 | #endif /* ! __ASHMEMIOC */ 44 | 45 | #endif /* _CUTILS_ASHMEM_H */ 46 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* cutils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _CUTILS_ASHMEM_H 11 | #define _CUTILS_ASHMEM_H 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int ashmem_create_region(const char *name, size_t size); 20 | int ashmem_set_prot_region(int fd, int prot); 21 | int ashmem_pin_region(int fd, size_t offset, size_t len); 22 | int ashmem_unpin_region(int fd, size_t offset, size_t len); 23 | int ashmem_get_size_region(int fd); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #ifndef __ASHMEMIOC /* in case someone included too */ 30 | 31 | #define ASHMEM_NAME_LEN 256 32 | 33 | #define ASHMEM_NAME_DEF "dev/ashmem" 34 | 35 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 36 | #define ASHMEM_NOT_PURGED 0 37 | #define ASHMEM_WAS_PURGED 1 38 | 39 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 40 | #define ASHMEM_IS_UNPINNED 0 41 | #define ASHMEM_IS_PINNED 1 42 | 43 | #endif /* ! __ASHMEMIOC */ 44 | 45 | #endif /* _CUTILS_ASHMEM_H */ 46 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* cutils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _CUTILS_ASHMEM_H 11 | #define _CUTILS_ASHMEM_H 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int ashmem_create_region(const char *name, size_t size); 20 | int ashmem_set_prot_region(int fd, int prot); 21 | int ashmem_pin_region(int fd, size_t offset, size_t len); 22 | int ashmem_unpin_region(int fd, size_t offset, size_t len); 23 | int ashmem_get_size_region(int fd); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #ifndef __ASHMEMIOC /* in case someone included too */ 30 | 31 | #define ASHMEM_NAME_LEN 256 32 | 33 | #define ASHMEM_NAME_DEF "dev/ashmem" 34 | 35 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 36 | #define ASHMEM_NOT_PURGED 0 37 | #define ASHMEM_WAS_PURGED 1 38 | 39 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 40 | #define ASHMEM_IS_UNPINNED 0 41 | #define ASHMEM_IS_PINNED 1 42 | 43 | #endif /* ! __ASHMEMIOC */ 44 | 45 | #endif /* _CUTILS_ASHMEM_H */ 46 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* cutils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _CUTILS_ASHMEM_H 11 | #define _CUTILS_ASHMEM_H 12 | 13 | #include 14 | 15 | #ifdef __cplusplus 16 | extern "C" { 17 | #endif 18 | 19 | int ashmem_create_region(const char *name, size_t size); 20 | int ashmem_set_prot_region(int fd, int prot); 21 | int ashmem_pin_region(int fd, size_t offset, size_t len); 22 | int ashmem_unpin_region(int fd, size_t offset, size_t len); 23 | int ashmem_get_size_region(int fd); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #ifndef __ASHMEMIOC /* in case someone included too */ 30 | 31 | #define ASHMEM_NAME_LEN 256 32 | 33 | #define ASHMEM_NAME_DEF "dev/ashmem" 34 | 35 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 36 | #define ASHMEM_NOT_PURGED 0 37 | #define ASHMEM_WAS_PURGED 1 38 | 39 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 40 | #define ASHMEM_IS_UNPINNED 0 41 | #define ASHMEM_IS_PINNED 1 42 | 43 | #endif /* ! __ASHMEMIOC */ 44 | 45 | #endif /* _CUTILS_ASHMEM_H */ 46 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/cutils/record_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * A simple utility for reading fixed records out of a stream fd 19 | */ 20 | 21 | #ifndef _CUTILS_RECORD_STREAM_H 22 | #define _CUTILS_RECORD_STREAM_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | typedef struct RecordStream RecordStream; 30 | 31 | extern RecordStream *record_stream_new(int fd, size_t maxRecordLen); 32 | extern void record_stream_free(RecordStream *p_rs); 33 | 34 | extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord, 35 | size_t *p_outRecordLen); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | 42 | #endif /*_CUTILS_RECORD_STREAM_H*/ 43 | 44 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/record_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * A simple utility for reading fixed records out of a stream fd 19 | */ 20 | 21 | #ifndef _CUTILS_RECORD_STREAM_H 22 | #define _CUTILS_RECORD_STREAM_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | typedef struct RecordStream RecordStream; 30 | 31 | extern RecordStream *record_stream_new(int fd, size_t maxRecordLen); 32 | extern void record_stream_free(RecordStream *p_rs); 33 | 34 | extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord, 35 | size_t *p_outRecordLen); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | 42 | #endif /*_CUTILS_RECORD_STREAM_H*/ 43 | 44 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/record_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * A simple utility for reading fixed records out of a stream fd 19 | */ 20 | 21 | #ifndef _CUTILS_RECORD_STREAM_H 22 | #define _CUTILS_RECORD_STREAM_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | typedef struct RecordStream RecordStream; 30 | 31 | extern RecordStream *record_stream_new(int fd, size_t maxRecordLen); 32 | extern void record_stream_free(RecordStream *p_rs); 33 | 34 | extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord, 35 | size_t *p_outRecordLen); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | 42 | #endif /*_CUTILS_RECORD_STREAM_H*/ 43 | 44 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/record_stream.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * A simple utility for reading fixed records out of a stream fd 19 | */ 20 | 21 | #ifndef _CUTILS_RECORD_STREAM_H 22 | #define _CUTILS_RECORD_STREAM_H 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | typedef struct RecordStream RecordStream; 30 | 31 | extern RecordStream *record_stream_new(int fd, size_t maxRecordLen); 32 | extern void record_stream_free(RecordStream *p_rs); 33 | 34 | extern int record_stream_get_next (RecordStream *p_rs, void ** p_outRecord, 35 | size_t *p_outRecordLen); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | 42 | #endif /*_CUTILS_RECORD_STREAM_H*/ 43 | 44 | -------------------------------------------------------------------------------- /23th_bridge_mode/Bridge.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | class OS { 7 | public: 8 | virtual void Install() = 0; 9 | }; 10 | 11 | class LinuxOS : public OS { 12 | public: 13 | virtual void Install() { cout<<"Install Linux OS"< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class Human { 8 | private: 9 | int a; 10 | public: 11 | virtual void eating(void) = 0; 12 | virtual void wearing(void) = 0; 13 | virtual void driving(void) = 0; 14 | virtual ~Human() { cout<<"~Human()"< 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* size is given in bytes and must be multiple of 2 */ 28 | void android_memset16(uint16_t* dst, uint16_t value, size_t size); 29 | 30 | /* size is given in bytes and must be multiple of 4 */ 31 | void android_memset32(uint32_t* dst, uint32_t value, size_t size); 32 | 33 | #if !HAVE_STRLCPY 34 | /* Declaration of strlcpy() for platforms that don't already have it. */ 35 | size_t strlcpy(char *dst, const char *src, size_t size); 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | #endif // ANDROID_CUTILS_MEMORY_H 43 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_MEMORY_H 18 | #define ANDROID_CUTILS_MEMORY_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* size is given in bytes and must be multiple of 2 */ 28 | void android_memset16(uint16_t* dst, uint16_t value, size_t size); 29 | 30 | /* size is given in bytes and must be multiple of 4 */ 31 | void android_memset32(uint32_t* dst, uint32_t value, size_t size); 32 | 33 | #if !HAVE_STRLCPY 34 | /* Declaration of strlcpy() for platforms that don't already have it. */ 35 | size_t strlcpy(char *dst, const char *src, size_t size); 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | #endif // ANDROID_CUTILS_MEMORY_H 43 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/cutils/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_MEMORY_H 18 | #define ANDROID_CUTILS_MEMORY_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* size is given in bytes and must be multiple of 2 */ 28 | void android_memset16(uint16_t* dst, uint16_t value, size_t size); 29 | 30 | /* size is given in bytes and must be multiple of 4 */ 31 | void android_memset32(uint32_t* dst, uint32_t value, size_t size); 32 | 33 | #if !HAVE_STRLCPY 34 | /* Declaration of strlcpy() for platforms that don't already have it. */ 35 | size_t strlcpy(char *dst, const char *src, size_t size); 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | #endif // ANDROID_CUTILS_MEMORY_H 43 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/cutils/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_MEMORY_H 18 | #define ANDROID_CUTILS_MEMORY_H 19 | 20 | #include 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* size is given in bytes and must be multiple of 2 */ 28 | void android_memset16(uint16_t* dst, uint16_t value, size_t size); 29 | 30 | /* size is given in bytes and must be multiple of 4 */ 31 | void android_memset32(uint32_t* dst, uint32_t value, size_t size); 32 | 33 | #if !HAVE_STRLCPY 34 | /* Declaration of strlcpy() for platforms that don't already have it. */ 35 | size_t strlcpy(char *dst, const char *src, size_t size); 36 | #endif 37 | 38 | #ifdef __cplusplus 39 | } // extern "C" 40 | #endif 41 | 42 | #endif // ANDROID_CUTILS_MEMORY_H 43 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/02th/include/utils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* utils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _UTILS_ASHMEM_H 11 | #define _UTILS_ASHMEM_H 12 | 13 | #include 14 | #include 15 | 16 | #define ASHMEM_NAME_LEN 256 17 | 18 | #define ASHMEM_NAME_DEF "dev/ashmem" 19 | 20 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 21 | #define ASHMEM_NOT_REAPED 0 22 | #define ASHMEM_WAS_REAPED 1 23 | 24 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 25 | #define ASHMEM_NOW_UNPINNED 0 26 | #define ASHMEM_NOW_PINNED 1 27 | 28 | #define __ASHMEMIOC 0x77 29 | 30 | #define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) 31 | #define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) 32 | #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) 33 | #define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) 34 | #define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) 35 | #define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) 36 | #define ASHMEM_PIN _IO(__ASHMEMIOC, 7) 37 | #define ASHMEM_UNPIN _IO(__ASHMEMIOC, 8) 38 | #define ASHMEM_ISPINNED _IO(__ASHMEMIOC, 9) 39 | #define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) 40 | 41 | #endif /* _UTILS_ASHMEM_H */ 42 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/utils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* utils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _UTILS_ASHMEM_H 11 | #define _UTILS_ASHMEM_H 12 | 13 | #include 14 | #include 15 | 16 | #define ASHMEM_NAME_LEN 256 17 | 18 | #define ASHMEM_NAME_DEF "dev/ashmem" 19 | 20 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 21 | #define ASHMEM_NOT_REAPED 0 22 | #define ASHMEM_WAS_REAPED 1 23 | 24 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 25 | #define ASHMEM_NOW_UNPINNED 0 26 | #define ASHMEM_NOW_PINNED 1 27 | 28 | #define __ASHMEMIOC 0x77 29 | 30 | #define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) 31 | #define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) 32 | #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) 33 | #define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) 34 | #define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) 35 | #define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) 36 | #define ASHMEM_PIN _IO(__ASHMEMIOC, 7) 37 | #define ASHMEM_UNPIN _IO(__ASHMEMIOC, 8) 38 | #define ASHMEM_ISPINNED _IO(__ASHMEMIOC, 9) 39 | #define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) 40 | 41 | #endif /* _UTILS_ASHMEM_H */ 42 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/04th/include/utils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* utils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _UTILS_ASHMEM_H 11 | #define _UTILS_ASHMEM_H 12 | 13 | #include 14 | #include 15 | 16 | #define ASHMEM_NAME_LEN 256 17 | 18 | #define ASHMEM_NAME_DEF "dev/ashmem" 19 | 20 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 21 | #define ASHMEM_NOT_REAPED 0 22 | #define ASHMEM_WAS_REAPED 1 23 | 24 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 25 | #define ASHMEM_NOW_UNPINNED 0 26 | #define ASHMEM_NOW_PINNED 1 27 | 28 | #define __ASHMEMIOC 0x77 29 | 30 | #define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) 31 | #define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) 32 | #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) 33 | #define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) 34 | #define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) 35 | #define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) 36 | #define ASHMEM_PIN _IO(__ASHMEMIOC, 7) 37 | #define ASHMEM_UNPIN _IO(__ASHMEMIOC, 8) 38 | #define ASHMEM_ISPINNED _IO(__ASHMEMIOC, 9) 39 | #define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) 40 | 41 | #endif /* _UTILS_ASHMEM_H */ 42 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/05th/include/utils/ashmem.h: -------------------------------------------------------------------------------- 1 | /* utils/ashmem.h 2 | ** 3 | ** Copyright 2008 The Android Open Source Project 4 | ** 5 | ** This file is dual licensed. It may be redistributed and/or modified 6 | ** under the terms of the Apache 2.0 License OR version 2 of the GNU 7 | ** General Public License. 8 | */ 9 | 10 | #ifndef _UTILS_ASHMEM_H 11 | #define _UTILS_ASHMEM_H 12 | 13 | #include 14 | #include 15 | 16 | #define ASHMEM_NAME_LEN 256 17 | 18 | #define ASHMEM_NAME_DEF "dev/ashmem" 19 | 20 | /* Return values from ASHMEM_PIN: Was the mapping purged while unpinned? */ 21 | #define ASHMEM_NOT_REAPED 0 22 | #define ASHMEM_WAS_REAPED 1 23 | 24 | /* Return values from ASHMEM_UNPIN: Is the mapping now pinned or unpinned? */ 25 | #define ASHMEM_NOW_UNPINNED 0 26 | #define ASHMEM_NOW_PINNED 1 27 | 28 | #define __ASHMEMIOC 0x77 29 | 30 | #define ASHMEM_SET_NAME _IOW(__ASHMEMIOC, 1, char[ASHMEM_NAME_LEN]) 31 | #define ASHMEM_GET_NAME _IOR(__ASHMEMIOC, 2, char[ASHMEM_NAME_LEN]) 32 | #define ASHMEM_SET_SIZE _IOW(__ASHMEMIOC, 3, size_t) 33 | #define ASHMEM_GET_SIZE _IO(__ASHMEMIOC, 4) 34 | #define ASHMEM_SET_PROT_MASK _IOW(__ASHMEMIOC, 5, unsigned long) 35 | #define ASHMEM_GET_PROT_MASK _IO(__ASHMEMIOC, 6) 36 | #define ASHMEM_PIN _IO(__ASHMEMIOC, 7) 37 | #define ASHMEM_UNPIN _IO(__ASHMEMIOC, 8) 38 | #define ASHMEM_ISPINNED _IO(__ASHMEMIOC, 9) 39 | #define ASHMEM_PURGE_ALL_CACHES _IO(__ASHMEMIOC, 10) 40 | 41 | #endif /* _UTILS_ASHMEM_H */ 42 | -------------------------------------------------------------------------------- /23th_bridge_mode/Bridge2.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | using namespace std; 5 | 6 | class OS { 7 | public: 8 | virtual void InstallOS_impl() = 0; 9 | }; 10 | 11 | class LinuxOS : public OS { 12 | public: 13 | virtual void InstallOS_impl() { cout<<"Install Linux OS"<impl = impl; } 37 | void InstallOS() { printInfo(); impl->InstallOS_impl(); }; 38 | private: 39 | OS *impl; 40 | }; 41 | 42 | 43 | 44 | class Lenovo : public Computer { 45 | public: 46 | virtual void printInfo() { cout<<"This is Lenovo, ";} 47 | Lenovo(OS *impl) { this->impl = impl; } 48 | void InstallOS() { printInfo(); impl->InstallOS_impl(); }; 49 | private: 50 | OS *impl; 51 | }; 52 | 53 | 54 | int main() 55 | { 56 | OS *os1 = new LinuxOS(); 57 | OS *os2 = new WindowsOS(); 58 | OS *os3 = new UnixOS(); 59 | 60 | Computer *c1 = new MAC(os1); 61 | Computer *c2 = new Lenovo(os2); 62 | Computer *c3 = new Lenovo(os3); 63 | 64 | c1->InstallOS(); 65 | c2->InstallOS(); 66 | c3->InstallOS(); 67 | 68 | return 0; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /18th_exception/exception6.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | class MyException { 10 | public: 11 | virtual void what(void) { cout<<"This is MyException"<"< 39 | * class ANDROID_API Singleton { } 40 | */ 41 | 42 | #define ANDROID_API __attribute__((visibility("default"))) 43 | 44 | #endif // ANDROID_CUTILS_COMPILER_H 45 | -------------------------------------------------------------------------------- /21th_strongpointer_weakpointer/03th/include/cutils/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef ANDROID_CUTILS_COMPILER_H 18 | #define ANDROID_CUTILS_COMPILER_H 19 | 20 | /* 21 | * helps the compiler's optimizer predicting branches 22 | */ 23 | 24 | #ifdef __cplusplus 25 | # define CC_LIKELY( exp ) (__builtin_expect( !!(exp), true )) 26 | # define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), false )) 27 | #else 28 | # define CC_LIKELY( exp ) (__builtin_expect( !!(exp), 1 )) 29 | # define CC_UNLIKELY( exp ) (__builtin_expect( !!(exp), 0 )) 30 | #endif 31 | 32 | /** 33 | * exports marked symbols 34 | * 35 | * if used on a C++ class declaration, this macro must be inserted 36 | * after the "class" keyword. For instance: 37 | * 38 | * template 39 | * class ANDROID_API Singleton { } 40 | */ 41 | 42 | #define ANDROID_API __attribute__((visibility("default"))) 43 | 44 | #endif // ANDROID_CUTILS_COMPILER_H 45 | --------------------------------------------------------------------------------