Паттерны проектирования C++ !!!!!!!!! (1115008)
Текст из файла
Паттерны проектирования C++Паттерны проектирования C++Александр СмальCS центр30 апреля 2015Санкт-Петербургhttp://compscicenter.ru1/10Паттерны проектирования C++Уже обсудили1. Singleton2. Adapter (stack, queue)3. Type-erasure (function, any)4. Tag-dispatching (алгоритмы STL)5. Traits (iterator_traits)6. Proxy access (vector<bool>)7.
Small Object Optimization8. RAII9. Smart pointers10. CRTPhttp://compscicenter.ru2/10Паттерны проектирования C++Pointer to implementationПусть у на был следующий класс.struct Book {void print ();private :std :: string m_Contents ;};Потом мы его изменили.struct Book {void print ();private :std :: string m_Contents ;std :: string m_Title ;}Это приведёт к перекомпиляции всего кода, которыйиспользует Book.http://compscicenter.ru3/10Паттерны проектирования C++Pointer to implementationПусть у на был следующий класс./* public . h */struct Book {Book ();~ Book ();void print ();private :struct BookImpl * m_p ;};/* private .
h */# include " public . h "# include < iostream >struct BookImpl {void print ();private :std :: string m_Contents ;std :: string m_Title ;}http://compscicenter.ru4/10Паттерны проектирования C++Pointer to implementationЧто мы получили:1. При изменении BookImpl нужно перекомпилироватьтолько реализацию класса Book.2. Можно скрыть реализацию BookImpl: передать библиотекус классами Book и BookImpl и заголовочный файлpublic.h.3. При раздельной компиляции можно поддерживатьбинарную совместимость, если зафиксировать класс Book.http://compscicenter.ru5/10Паттерны проектирования C++Expression Templatestring a = " Computer " ;string b = " Science " ;string c = " Center " ;string res = a + " " + b + " " + c ;template < class O1 , class O2 >struct string_expr {operator string () {}O1 & o1 ;O2 & o2 ;};string_expr < string , string >operator +( string const & a , string const & b );template < class O1 , class O2 >string_expr < string , string >operator +( string const & a , string_expr < O1 , O2 > const & b );...http://compscicenter.ru6/10Паттерны проектирования C++Named constructorstruct Game {// named constructorstatic Game c r e a t e S i n g l e P l a y e r G a m e () { return Game (0); }// named constructorstatic Game c r e a t e M u l t i P l a y e r G a m e (){ return Game (1); }protected :Game ( int game_type );};int main ( void ){// Using named constructorGame g1 = Game :: c r e a t e S i n g l e P l a y e r G a m e ();// multiplayer game; without named constructor (does not compile)Game g2 = Game (1);}http://compscicenter.ru7/10Паттерны проектирования C++Attorney-Clientstruct Foo {private :void A ( int a );void B ( float b );void C ( double c );friend class Bar ;};// Needs access to Foo::A and Foo::B onlystruct Bar { };struct Client {private :void A ( int a );void B ( float b );void C ( double c );friend struct Attorney ;};struct Attorney {private :static void callA ( Client & c , int a ){ c .
A ( a ); }static void callB ( Client & c , float b ) { c . B ( b ); }friend struct Bar ;};// Bar now has access to only Client::A and Client::B through the Attorney.struct Bar { };http://compscicenter.ru8/10Паттерны проектирования C++Strategytemplate < class T >struct NewCreator {static T * create ()static void destroy ( T * t )};{ return new T (); }{ delete t ; }template < class T >struct MallocCreator {static T * create () {void * buff = malloc ( sizeof ( T ));if ( buff == 0) return 0;return new ( buff ) T ();}static void destroy ( T * t ) { free ( t ); }};template < template < class T > CreationPolicy >struct WidgetManager : protected CreationPolicy < Widget >{...};http://compscicenter.ru9/10Паттерны проектирования C++Non-Virtual Interfacestruct Base {virtual ~ Base () {}void show () { do_show (); }void load ( std :: string const & filename ) {// Здесь можно проверить, существует ли файлdo_load ( filename );// Здесь можно проверить, валидны ли прочитанные данные}void save ( std :: string const & filename ) {do_save ( filename );// Здесь можно проверить, успешно ли прошла запись}protected :virtual void do_show () = 0;virtual void do_load ( std :: string const & filename ) = 0;virtual void do_save ( std :: string const & filename ) = 0;};int main () {Base * b = new Derived ();b - > load ( " ~/ Schema .
xml " );b - > show ();b - > save ( " ~/ Schema . xml " );}http://compscicenter.ru10/10.
Характеристики
Тип файла PDF
PDF-формат наиболее широко используется для просмотра любого типа файлов на любом устройстве. В него можно сохранить документ, таблицы, презентацию, текст, чертежи, вычисления, графики и всё остальное, что можно показать на экране любого устройства. Именно его лучше всего использовать для печати.
Например, если Вам нужно распечатать чертёж из автокада, Вы сохраните чертёж на флешку, но будет ли автокад в пункте печати? А если будет, то нужная версия с нужными библиотеками? Именно для этого и нужен формат PDF - в нём точно будет показано верно вне зависимости от того, в какой программе создали PDF-файл и есть ли нужная программа для его просмотра.