实例介绍
C++ Reactive Programming ISBN 139781788629775 Praseed Pai, Peter Abraham June 2018
C++ Reactive Programming Copyright o 2018 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means without the prior written permission of the publisher except in the case of brief quotations embedded in critical articles or reviews Every effort has been made in the preparation of this book to ensure the accuracy of the information presented However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or allege have been caused directly or indirectly by this book Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information Commissioning Editor: Richa Tripathi Acquisition Editor: Sandeep Mishra Content Development Editor: Rohit Singh Technical Editor: Ketan Kamble Copy Editor: Safis Editing Project Coordinator: Vaidehi Sawant Proofreader: Safis editing Indexer: Aishwarya gangawane Graphics: Jason Monteiro Production Coordinator: Shraddha Falebhai First published June 2018 Production reference: 1280618 Published by packt Publishing ltd Livery place 35 Livery street Birmingham B3 2PB, UK ISBN978-1-78862-977-5 www.pAcktpub.com Mapt mapt.lo Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website Why subscribe? Spend less time learning and more time coding with practical eBooks and Videos from over 4, 000 industry professionals Improve your learning with Skill Plans built especially for you Get a free e Book or video every month Mapt is fully searchable Copy and paste, print, and bookmark content PacktPub, com Did you know that Packt offers e Book versions of every book published with PDF and epubfilesavailableYoucanupgradetotheebooKversionatwww.Packtpub.comandasa print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@packtpub com for more details Atwww.packtpub.com,youcanalsoreadacollectionoffreetechnicalarticlessignupfora range of free newsletters and receive exclusive discounts and offers on packt books and books Contributors About the authors Praseed Pai has been working in the software industry for the last 25 years starting his career as a Ms-DOS systems programmer using ANSI C. He has been actively involved in developing large-scale, cross-platform, native code-based systems using C++ on Windows, GNU Linux, and macOs X. He has experience in COM+ and COrba programming using C++. In the last decade, he has worked with Java-and.NET-based systems He is the primary implementer of the slang. net compilation system, which has been ported to C++ with an LLvm backend. He coauthored. NET Design Patterns, by Packt Publishing g Peter abraham has been a performance fanatic and a c/C++ programming language enthusiast right from his college days, where he excelled in Microsoft Windows programming and GNu Linux programming He garnered experience in working with CUDA, image processing, and computer graphics programs by virtue of working with companies such as Quest Global, Siemens, and Tektronics Peter has been eagerly following the C++ standard and rx Cpp libraries as part of his profession. He has worked with cross-platform GUI toolkits such as Qt, WxWidgets, and FOX toolkit About the reviewer Sumant Tambe is a software engineer, researcher open source contributor blogger speaker, author, and gamer he is experienced in using modern c++, Kafka, data distribution service, reactive programming, and stream processing to solve new problems in big data and industrial Iot He has authored C++ Truths blog and the more C++ idioms wikibook. He shares his learnings on his blog and at local code camps, meetups, and conferences. He has been a recipient of the microsoft mvp award in development technologies for 5 years. he has a phd in computer science from vanderbilt University Packt is searching for authors like you IfyoureinterestedinbecominganauthorforPackt,pleasevisitauthorspacktpub.com and apply today. We have worked with thousands of developers and tech professionals just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea Table of contents Preface Chapter 1: Reactive Programming Model-Overview and History Event-driven programming model Event-driven programming on X Windows Event-driven programming on Microsoft Windows 6779 Event-driven programming under Qt Event-driven programming under MFC 12 Other event-driven programming models 13 Limitations of classical event processing models 13 Reactive programming mode 14 Functional reactive programming 14 The key interfaces of a reactive program 15 Pull-versus push-based reactive programming The IEnumerable/oBservable duality 17 Converting events to observable<t> 21 The philosophy of our book 25 Summar 27 Chapter 2: A Tour of Modern C++ and its Key Idioms 28 The key concerns of the C++ programming language 29 Zero cost abstraction 29 Expressivity 29 Substitutability 32 Enhancements to C++ for writing better code 33 Type deduction and inference 33 Uniform initialization of variables 35 Variadic templates Rvalue references 38 Move semantics 39 Smart pointers 41 Lambda functions 43 Functors and lambdas 44 Composition, currying, and partial function application 47 Function wrappers 49 Composing functions together with the pipe operator 50 Miscellaneous features 52 Fold expressions 52 Variant type 53 Table of Contents Other important topics 54 Range-based for loops and observables 54 Summary 58 Chapter 3: Language-Level Concurrency and Parallelism in C++ 59 What is concurrency? 60 Hello World of concurrency(using std: thread) 61 Managing threads 62 Thread launch 63 Thread join 64 Passing arguments into a thread 65 Using Lambdas 68 Ownership management 69 Sharing data between threads 71 Mutexes 73 Avoiding deadlock 75 ocking with std: unique lock 78 Condition variables 80 A thread-safe stack data structure 82 Summary 85 Chapter 4: Asynchronous and Lock-Free Programming in C++ 86 Task-based parallelism in C++ 87 Future and promise 87 std: packaged task 90 std: async 91 C++ memory model 93 Memory access and concurrency 94 The modification contract 95 Atomic operations and types in C++ 95 Atomic types std: atomic flag 98 std atomic<bool> 100 Standard atomic integral types 102 std atomic<T*>- pointer arithmetic 103 std: :atomic<> primary class template 104 Memory ordering 105 Sequential consistency 105 Acquire-release ordering 107 Relaxed ordering 109 A lock-free data structure queue 110 Summary 112 Chapter 5: Introduction to observables 114 The GoF Observer pattern 115 [i] Table of Contents The limitations of the gof observer pattern 118 a holistic look at GoF patterns 119 The ooP programming model and hierarchies 120 A Composite/Visitor pattern for expression processing 122 Flattening the composite for iterative processing 126 Map and filter operations on the list 129 Reversing the gaze for Observables! 130 Summary 134 Chapter 6: Introduction to Event Stream Programming Using C++ 135 What is Stream programming model? 136 Advantages of the Stream programming model 136 Applied Stream programming using the Streams library 137 Lazy evaluation 138 a simple stream program 138 Aggregating values using the Stream paradigm 139 The STL and the stream paradigm 140 A word about the Streams library 140 Event Stream programming 141 Advantages of Event Stream programming 141 The Streamulus library and its programming model 142 The Streamulus library -a peek into its internals 145 The Streamulus Library -a look into expression processing 146 The spreadsheet Library-a change-propagation engine 147 RaftLib-another Stream-processing library 149 What do these things have to do with Rx programming? 150 Summary 151 Chapter 7: Introduction to Data Flow Computation and the RxCpp Library 152 The data flow computation paradigm 153 An introduction to the Rxcpp library 154 The RXCpp library and its programming model 155 A simple Observable/Observer interaction 155 Filters and transformations with observables 156 Streaming values from C++ containers 157 Creating Observables from scratch 157 Concatenating observable Streams 158 Unsubscribing from Observable Streams 158 An introduction to marble diagrams for visual representation 159 RXCpp( Stream)operators 160 The average operator 160 The scan operator 160 Composing operators through the pipe operator 161 Working with Schedulers 162 Table of Contents a tale of two operators- flat versus concat map 164 More operators that are of importance 169 a peek into the things we haven't covered yet 171 Summary 172 Chapter 8: RXCpp- the Key Elements 173 Observables 174 What's a producer? 174 Hot versus cold observables 174 Hot observables 175 Hot observables and the replay mechanism 178 Observers and their variants(subscribers) 179 Subjects 180 Schedulers 183 Observeon versus subscribeon 185 The RunLoop scheduler 187 Operators 189 Creational operators 189 Transformation operators 190 Filtering operators 190 Combining operators 191 Error-handling operators 192 Observable utility operators 192 Conditional and boolean operators 192 Mathematical and aggregate operators 193 Connectable Observable operators 194 Summary 194 Chapter 9: Reactive GUI Programming Using Qt/C++ 195 A quick introduction to Qt GUI programming 196 Qt object model 197 Signals and slots 198 Event system 199 Event handlers 200 Sending events 201 Meta-object system 201 Hello world -Qt program 202 Qt event model with signals/slots/Moc -an example 204 Creating a custom widget 204 Creating the application dialog 206 Executing the application 210 Integrating the RXCpp library with the Qt event model 212 Qt event filter-a reactive approach 212 Creating the window-setting layouts and alignments 214 Event type specific observables 215 【实例截图】
【核心代码】
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论