010 Types

Transcript

1 Types and Byte Order Types for fi xed-size integers, byte order conversions and the Any/DynamicAny types.

2 Overview Fixed-Size Integer Types > Byte Order (Conversions) > The Any Type > The DynamicAny Type >

3 Fixed-Size Integer Types POCO defines types for fixed-size integers > #include "Poco/Types.h" > (automatically included by Poco/Foundation.h) Poco::Int8 , Poco::Int64 , Poco::Int32 , Poco::Int16 > Poco::UInt8 , Poco::UInt16 , Poco::UInt32 , Poco::UInt64 Poco::IntPtr , Poco::UIntPtr : integer with same size as a pointer > type (32 or 64 bits) For portable code, always use these types if you need a fixed-size > integer.

4 Size of Built-in Types POCO has two macros to determine the size of the long type and > of pointer types. POCO_PTR_IS_64_BIT > macro is defined if pointers are 64 bits POCO_LONG_IS_64_BIT > macro is defined if long's are 64 bits

5 Byte Order POCO has facilities to deal with byte order issues. > Macros to determine the current host's byte order: > POCO_ARCH_LITTLE_ENDIAN > macro is defined if architecture is little endian POCO_ARCH_BIG_ENDIAN > macro is defined if architecture is big endian

6 Byte Order Conversions Class Poco::ByteOrder provides static methods for byte order > conversions. #include "Poco/ByteOrder.h" > All functions are available for > Int16 , UInt16 , Int32 , UInt32 , Int64 and UInt64 IntXX flipBytes(IntXX value) > changes byte order from big to little endian and vice versa

7 Byte Order Conversions (cont'd) IntXX toBigEndian(IntXX value) > converts from host byte order to big endian IntXX toLittleEndian(IntXX value) > converts from host byte order to little endian IntXX fromBigEndian(IntXX value) > converts from big endian to host byte order IntXX fromLittleEndian(IntXX value) > converts from little endian to host byte order

8 Byte Order Conversions (cont'd) IntXX toNetwork(IntXX value) > converts from host byte order to network byte order IntXX fromNetwork(IntXX value) > converts from network byte order to host byte order Network byte order is big endian > All methods are defined as inline functions and are very e ffi cient. > Unnecessary conversions will be optimized away by the compiler.

9 #include "Poco/ByteOrder.h" #include using Poco::ByteOrder; using Poco::UInt16; int main(int argc, char** argv) { #ifdef POCO_ARCH_LITTLE_ENDIAN std::cout << "little endian" << std::endl; #else std::cout << "big endian" << std::endl; #endif UInt16 port = 80; UInt16 networkPort = ByteOrder::toNetwork(port); return 0; }

10 The Any Type #include "Poco/Any.h" > An instance of can hold a value of any built-in or user- Poco::Any > defined type. Poco::Any supports value semantics. > The value can be extracted in a type-safe manner. > The type of the value must be known in order to extract it. > The Poco::AnyCast() and Poco::RefAnyCast() function templates > are used to extract values.

11 #include "Poco/Any.h" #include "Poco/Exception.h" using Poco::Any; using Poco::AnyCast; using Poco::RefAnyCast; int main(int argc, char** argv) { Any any(42); int i = AnyCast(any); // okay int& ri = RefAnyCast(any); // okay try { short s = AnyCast(any); // throws BadCastException } catch (Poco::BadCastException&) { } return 0; }

12 The DynamicAny Type #include "Poco/DynamicAny.h" > An instance of can hold a value of any type for Poco::DynamicAny > which a DynamicAnyHolder specialization is available. Poco::DynamicAny supports value semantics. > The value can be extracted in a type-safe manner. > Safe implicit and explicit conversions to various types (standard > types, std::string ) are supported (ranges are checked).

13 DynamicAny: convert() vs. extract() const T& extract(); T convert(); > > void convert(T& val); returns a const ref > > operator T () no autoconversion > > as fast as all return a copy Any > > autoconversion > Any slower than >

14 DynamicAny – Conversion Rules Data loss is forbidden for numeric values: > value < 0 will never be converted to an unsigned > value needing x bits, will never be converted to a smaller bit > range (e.g.: value = 2000, needs 16bits, conversion to 8 bit is forbidden) Precision loss from int to float and back is allowed > String truncation is allowed (string to single char) >

15 #include "Poco/DynamicAny.h" #include "Poco/Exception.h" using Poco::DynamicAny; int main(int argc, char** argv) { DynamicAny any(42); int i = any; std::string s(any.convert()); any.convert(s); // or without the need to cast const int& ri(any.extract()); short s = any; try { short s = any.extract(); // throws BadCastException } catch (Poco::BadCastException&) { } return 0; }

16 Any vs. DynamicAny can hold any type, but you have to know the type to get it Any > out again. can hold any type for which a DynamicAnyHolder DynamicAny > specialization exists. Implicit and explicit conversions are restricted to a fixed set of > types (standard types plus std::string ).

17 Copyright © 2006-2010 by Applied Informatics Software Engineering GmbH. Some rights reserved. www.appinf.com | [email protected] T +43 4253 32596 | F +43 4253 32096

Related documents

Annual Energy Review 2011   Released September 2012

Annual Energy Review 2011 Released September 2012

D / E I A - 0 3 8 4 ( 2 0 1 1 ) E | S e p t e m b e r 2 0 1 2 O 1 1 0 2 w e i v e R y g r A n n u a l E n e . r a / v o g e a i e . w w w

More info »
Monthly Energy Review – April 2019

Monthly Energy Review – April 2019

DOE/EIA ‐ 0035( 2019/4 ) April 2019 Monthly Energy Review www.eia.gov/mer

More info »
FY19 Standard Items Package

FY19 Standard Items Package

NAVSEA STANDARD ITEM NUMERICAL INDEX 19 FY - UTILIZATION CATEGORY TITLE DATE ITEM NO. 01 General Criteria; accomplish 009 01 OCT 2017 - I - 02 NOV 2016 009 18 I Report Environmental Compliance for Mat...

More info »
Summary of Changes to Title 29

Summary of Changes to Title 29

Alaska Statutes: Title 29 Municipal Government 2018 Updates from the th Legislature 30 nd Session: January – 2 April 2018 Bill Walker, Governor State of Alaska Mike Navarre, Commissioner Department of...

More info »
Out of Reach 2016

Out of Reach 2016

No Refuge for Low Income Renters MADE POSSIBLE BY THE GENEROSITY OF:

More info »
Portable Power Tools, Chapter 296 807, WAC

Portable Power Tools, Chapter 296 807, WAC

296- 807 WAC Portable Power Tools Safety and Health Core Rules WAC Chapter 296 -807 Portable Power Tools -089 (Form Number 414 -000) 2/17/2015 LAST UPDATED 1 , as adopted under the This book contains ...

More info »
A/HRC/39/CRP.2 in Word

A/HRC/39/CRP.2 in Word

/HRC/39/CRP.2 A September 2018 17 only English Human Rights Council Thirty ninth session - 10 28 September 2018 – Agenda item 4 Human rights situations that require the Council’s attention Report of t...

More info »
Second National Report on Biochemical Indicators of Diet and Nutrition in the U.S. Population

Second National Report on Biochemical Indicators of Diet and Nutrition in the U.S. Population

Second National Report on Biochemical Indicators of Diet and Nutrition in the U.S. Population Second National Report on Biochemical Indicators of Diet and Nutrition in the U.S. Population 2012 Nationa...

More info »
C:\Users\aholmes4\AppData\Roaming\SoftQuad\XMetaL\7.0\gen\c\H5515 ~1.XML

C:\Users\aholmes4\AppData\Roaming\SoftQuad\XMetaL\7.0\gen\c\H5515 ~1.XML

H. R. 5515 One Hundred Fifteenth Congress of the United States of America AT THE SECOND SESSION Begun and held at the City of Washington on Wednesday, the third day of January, two thousand and eighte...

More info »
Microsoft Word   A) Division 245.docx

Microsoft Word A) Division 245.docx

tables Attachment Division 245, including A: Nov. 15-16, 2018, EQC meeting 1 of 121 Page Division 245 CLEANER AIR OREGON 340-245-0005 Purpose and Overview (1) This statement of purpose and overview is...

More info »
Out of Reach 2018

Out of Reach 2018

2018 of OUT REACH THE HIGH COST OF HOUSING MADE POSSIBLE BY THE GENEROSITY OF:

More info »
RIE Tenant List By Docket Number

RIE Tenant List By Docket Number

SCRIE TENANTS LIST ~ By Docket Number ~ Borough of Bronx SCRIE in the last year; it includes tenants that have a lease expiration date equal or who have received • This report displays information on ...

More info »
ab2222

ab2222

COMMUNITIES THAT RELY ON A CONTAMINATED GROUNDWATER SOURCE FOR DRINKING WATER STATE WATER RESOURCES CONTROL BOARD REPORT TO THE LEGISLATURE January 201 3

More info »
vol9 organic ligands

vol9 organic ligands

C HERMODYNAMICS HEMICAL T OMPOUNDS AND C OMPLEXES OF OF C U, Np, Pu, Am, Tc, Se, Ni and Zr O ELECTED WITH RGANIC L IGANDS S Wolfgang Hummel (Chairman) Laboratory for Waste Management Paul Scherrer Ins...

More info »
a i4787e

a i4787e

2015 ISSN 2412-5474 nimal genetic resource diversity underpins the supply livestock products and A services across a wide range of production environments. It promotes resilience and serves as a basis...

More info »
THREAD GUIDE REV 01   APRIL 5 2013

THREAD GUIDE REV 01 APRIL 5 2013

5 6 2 4 8 1 3 7 D D THIS THREADING GUIDE CONTAINS DATA FOR THREADING FIREARM BARRELS THAT WILL BE COMPATIBLE WITH 1. ALL CURRENT PRODUCTION ADVANCED ARMAMENT SILENCERS AND MUZZLE DEVICES. MANY OF THE ...

More info »
Skills volume 1 (eng)  full v12  eBook (04 11 2013)

Skills volume 1 (eng) full v12 eBook (04 11 2013)

OECD Skills Outlook 2013 FirSt rESultS FrOm thE SurvEy OF ADult SkillS 2013

More info »
Recovery2020.FR .Web

Recovery2020.FR .Web

3300 Whitehaven Street, NW, Suite 5000 Washington, DC 20007 Mail: Campus Box 571444, Washington, DC 20057 cew.georgetown.edu union bug

More info »
TPT and Other Tax Rate Tables

TPT and Other Tax Rate Tables

Arizona State, County and City E AND OTHER TAX RATE TABLES Effective June 1, 2018 TRANSACTION PRIVILEG s, and most Arizona cities: The following tables contain the rates for Transaction Privilege and ...

More info »