blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
2
247
content_id
stringlengths
40
40
detected_licenses
listlengths
0
57
license_type
stringclasses
2 values
repo_name
stringlengths
4
111
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringlengths
4
58
visit_date
timestamp[ns]date
2015-07-25 18:16:41
2023-09-06 10:45:08
revision_date
timestamp[ns]date
1970-01-14 14:03:36
2023-09-06 06:22:19
committer_date
timestamp[ns]date
1970-01-14 14:03:36
2023-09-06 06:22:19
github_id
int64
3.89k
689M
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
25 values
gha_event_created_at
timestamp[ns]date
2012-06-07 00:51:45
2023-09-14 21:58:52
gha_created_at
timestamp[ns]date
2008-03-27 23:40:48
2023-08-24 19:49:39
gha_language
stringclasses
159 values
src_encoding
stringclasses
34 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
7
10.5M
extension
stringclasses
111 values
filename
stringlengths
1
195
text
stringlengths
7
10.5M
471d4148268740d70a9e76e42c34690327b9662e
adc933a7f0ee1a4b5cadfcf622fea330cef4970d
/ProjetCPOA/voiture.cpp
52800342dc411ca4630b4eccd8a1322598b25149
[]
no_license
simonh88/projetL3
fcd411aace0eb58938702dfe480da1e8c16ed44d
c6902832f3c31716388b4cc98d9e9a379f4de1a2
refs/heads/master
2020-07-12T17:01:41.649446
2016-12-11T20:31:42
2016-12-11T20:31:42
73,902,809
0
0
null
null
null
null
UTF-8
C++
false
false
453
cpp
voiture.cpp
#include "voiture.h" #include "string.h" Voiture::Voiture(std::string immatriculation, std::string modele, int nbPlaces, bool estDispo, double prixJournee): Vehicule::Vehicule(immatriculation, modele, estDispo, prixJournee), nbPlaces(nbPlaces) { this->type = "Voiture"; } /*Voiture::~Voiture(){ }*/ void Voiture::setNbPlaces(const int value) { this->nbPlaces = value; } int Voiture::getNbPlaces() const { return this->nbPlaces; }
e12b0edd3c971f2547a9b0c8d1611ec31258a3cb
09ddd2df75bce4df9e413d3c8fdfddb7c69032b4
/src/LFC/.svn/text-base/NullStreamObject.cpp.svn-base
2e683c3510ee7e8c29df46117104870bb95921f9
[]
no_license
sigurdle/FirstProject2
be22e4824da8cd2cb5047762478050a04a4ac63b
dee78c62a1b95e55fcdf3bf2a9bc79c69705bf94
refs/heads/master
2021-01-16T18:45:41.042140
2020-08-18T16:57:13
2020-08-18T16:57:13
3,554,336
6
5
null
null
null
null
UTF-8
C++
false
false
136
NullStreamObject.cpp.svn-base
#include "stdafx.h" #include "LFC.h" namespace System { namespace IO { /* NullStreamObject::NullStreamObject() { } */ } } // System
0b6535cfd9c29da2d6513b5d47702b555615fea1
8b452b3e014e0448081cc0a9451bb2667668b4f9
/src/Shape.cpp
54de1af2905f4ef4a5b84d499e608318d4c7e3a4
[]
no_license
TristanDewalle/Pong
3c7b6326272ff3d9c74122264f5d3cf480ca11c8
278a2094beb2b7c026af20e3a9aeca157a240191
refs/heads/master
2016-08-12T10:57:37.351490
2015-10-02T21:04:19
2015-10-02T21:04:19
43,560,757
0
0
null
null
null
null
UTF-8
C++
false
false
457
cpp
Shape.cpp
#include "Shape.h" Shape::Shape(int x, int y, int r, int g, int b, int height, int length, double direction): _x(x), _y(y),_height(height), _length(length), _direction(direction){ _color = new Color(r,g,b); } Shape::Shape(int x, int y, Color* color, int height, int length, double direction): _x(x), _y(y), _height(height), _length(length), _direction(direction){ int r,g,b; color->getRGB(r,g,b); _color = new Color(r,g,b); }
b82679979556d11e55260096a9a0463beafa45da
2f78e134c5b55c816fa8ee939f54bde4918696a5
/code/camera/lookatcontroller.cpp
a7b22e77ee3b3cac604f2ee3a9f5b373dd76ddb4
[]
no_license
narayanr7/HeavenlySword
b53afa6a7a6c344e9a139279fbbd74bfbe70350c
a255b26020933e2336f024558fefcdddb48038b2
refs/heads/master
2022-08-23T01:32:46.029376
2020-05-26T04:45:56
2020-05-26T04:45:56
null
0
0
null
null
null
null
UTF-8
C++
false
false
34,009
cpp
lookatcontroller.cpp
//------------------------------------------------------------------------------------------ //! //! \file lookatcontroller.cpp //! //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ // Required Includes //------------------------------------------------------------------------------------------ #include "camera/lookatcontroller.h" #include "camera/basiccamera.h" #include "camera/elementmanager.h" #include "camera/sceneelementcomponent.h" #include "camera/smoother.h" #include "camera/converger.h" #include "camera/pointtransform.h" #include "camera/curverail.h" #include "camera/curves.h" #include "camera/camman.h" #include "camera/combatcam.h" #include "objectdatabase/dataobject.h" //------------------------------------------------------------------------------------------ // LACFixedPosDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACFixedPosDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) // New PUBLISH_VAR_WITH_DEFAULT_AS(m_obPosition, CPoint(0.0f, 0.0f, 0.0f), Position) END_STD_INTERFACE //------------------------------------------------------------------------------------------ // LACFixedDirDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACFixedDirDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) // New PUBLISH_VAR_AS(m_obDirection, Direction) END_STD_INTERFACE //------------------------------------------------------------------------------------------ // LACFixedYPRDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACFixedYPRDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) // New PUBLISH_VAR_AS(m_obYawPitchRoll, YawPitchRoll) END_STD_INTERFACE //------------------------------------------------------------------------------------------ // LACPOIRelDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACPOIRelDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) END_STD_INTERFACE //------------------------------------------------------------------------------------------ // LACRotRailDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACRotRailDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) //New PUBLISH_PTR_AS(m_pobRail, Rail) PUBLISH_PTR_AS(m_pobRotCurve, RotCurve) END_STD_INTERFACE //------------------------------------------------------------------------------------------ // LACRotGuideDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACRotGuideDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) //New PUBLISH_PTR_AS(m_pobRail, Rail) PUBLISH_PTR_AS(m_pobRotCurve, RotCurve) END_STD_INTERFACE //------------------------------------------------------------------------------------------ // LACGuideRailDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACGuideRailDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) //New PUBLISH_PTR_AS(m_pobRail, Rail) END_STD_INTERFACE //------------------------------------------------------------------------------------------ // LACRailDef XML Interface //------------------------------------------------------------------------------------------ START_CHUNKED_INTERFACE(LACRailDef, Mem::MC_CAMERA) //Parent PUBLISH_PTR_AS(m_pobPOISmootherDef, POISmootherDef) PUBLISH_PTR_AS(m_pobPOITrans, POITrans) PUBLISH_PTR_AS(m_pobOffsetConvergerDef, OffsetConvergerDef) PUBLISH_VAR_WITH_DEFAULT_AS(m_bPOIFixedOffset, false, POIFixedOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_obTargetOffset, CDirection(0.0f, 0.0f, 0.0f), TargetOffset) PUBLISH_VAR_WITH_DEFAULT_AS(m_bBound, false, Bound) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMax, CPoint(0.0f, 0.0f, 0.0f), BoundMax) PUBLISH_VAR_WITH_DEFAULT_AS(m_obBoundMin, CPoint(0.0f, 0.0f, 0.0f), BoundMin) //New PUBLISH_PTR_AS(m_pobRail, Rail) END_STD_INTERFACE //------------------------------------------------------------------------------------------ //! //! LookAtControllerDef::LookAtControllerDef //! LookAtControllerDef Constructor //! //------------------------------------------------------------------------------------------ LookAtControllerDef::LookAtControllerDef() : m_pobPOITrans(0), m_pobOffsetConvergerDef(0), m_pobPOISmootherDef(0), m_bPOIFixedOffset(false), m_obTargetOffset(CONSTRUCT_CLEAR), m_obBoundMax(CONSTRUCT_CLEAR), m_obBoundMin(CONSTRUCT_CLEAR), m_bBound(false) { } /*************************************************************************************************** * * FUNCTION LookAtController::Reset * * DESCRIPTION reset the LAC * ***************************************************************************************************/ void LookAtController::Reset(bool bRebuildSmoothers) { m_bLastTrackedValid = false; m_bLastTransformValid = false; if(bRebuildSmoothers) { NT_DELETE_CHUNK(Mem::MC_CAMERA, m_pobPOISmooth); m_pobPOISmooth = 0; } if(m_pobPOISmooth) m_pobPOISmooth->Reset(); if(m_pobPOITrans) m_pobPOITrans->Reset(); if (m_pobOffsetConverger) m_pobOffsetConverger->Reset(); // if(m_pobRotSmooth) // m_pobRotSmooth->Reset(); // if(m_pobRotConv) // m_pobRotConv->Reset(); } /*************************************************************************************************** * * FUNCTION LookAtController::LookAtController * * DESCRIPTION Debug constructor for handmade LAC's * ***************************************************************************************************/ LookAtController::LookAtController(const BasicCamera* pParent, const LookAtControllerDef& def) : m_pParent(pParent), m_bLastTrackedValid(false), m_obLastTracked(CONSTRUCT_CLEAR), m_bTargetValid(false), m_obTarget(CONSTRUCT_CLEAR), m_bLastTransformValid(false), m_obLastTransform(CONSTRUCT_CLEAR), m_pobPOISmooth(0), m_pobPOITrans(0), m_bPOIFixedOffset(false), m_obTargetOffset(CONSTRUCT_CLEAR), m_bBound(false), m_obBoundMax(CONSTRUCT_CLEAR), m_obBoundMin(CONSTRUCT_CLEAR) { // Welder Attribute Defaults (Interface moved into defintion...) if(def.m_pobPOISmootherDef) m_pobPOISmooth = NT_NEW_CHUNK(Mem::MC_CAMERA) CPointSmoother(*def.m_pobPOISmootherDef); else m_pobPOISmooth = 0; m_bPOIFixedOffset = def.m_bPOIFixedOffset; m_obTargetOffset = def.m_obTargetOffset; if (def.m_pobOffsetConvergerDef && def.m_pobOffsetConvergerDef->GetSpeed()>0.0f) { m_pobOffsetConverger = NT_NEW_CHUNK(Mem::MC_CAMERA) CPointConverger(*def.m_pobOffsetConvergerDef); } else { m_pobOffsetConverger = 0; } } /*************************************************************************************************** * * FUNCTION LookAtController::~LookAtController * * DESCRIPTION cleanup the look at controller * ***************************************************************************************************/ LookAtController::~LookAtController() { NT_DELETE_CHUNK(Mem::MC_CAMERA, m_pobPOISmooth); NT_DELETE_CHUNK(Mem::MC_CAMERA, m_pobPOITrans); NT_DELETE_CHUNK(Mem::MC_CAMERA, m_pobOffsetConverger); } /*************************************************************************************************** * * FUNCTION LookAtController::CalcLastTracked * * DESCRIPTION Calc what we're looking at * ***************************************************************************************************/ void LookAtController::CalcLastTracked(float fTimeChange) { CPoint ptPOI(m_pParent->GetElementManager().GetPointOfInterest()); // Check Bounding Restraints if(CamMan::Get().IsCombatAware()) { CombatCam* pCC(m_pParent->GetCombatCam()); const SceneElementComponent* pPrimary(m_pParent->GetElementManager().GetPrimaryElement()); if(pCC && pPrimary) { float fPOILimit = pCC->GetPOILimit(); if(fPOILimit >= 0.f) { CPoint ptPrimary(pPrimary->GetPosition()); CDirection dPrimary(ptPrimary - ptPOI); if(dPrimary.LengthSquared() > fPOILimit*fPOILimit) { dPrimary.Normalise(); ptPOI = ptPrimary + dPrimary*fPOILimit; } } } } SetLastTracked(ptPOI); // feed this into our point transform if we have one if(m_pobPOITrans) SetLastTracked(m_pobPOITrans->Update(GetLastTracked(),m_pParent->GetElementManager(),fTimeChange)); // add a fixed offset if we have one //if(m_bPOIFixedOffset && !CamMan::Get().IsCombatAware()) // SetLastTracked(GetLastTracked() + m_obTargetOffset*(m_pParent->GetTransform())); // scee.sbashow: // Use a point converger to smoothly go from one LAC offset to another (in world space) const CDirection obAppliedLocalOffset = (CamMan::Get().IsCombatAware() && m_pParent->GetCombatCam()) ? (m_pParent->GetCombatCam()->GetCombatOffset()) : (m_bPOIFixedOffset) ? (m_obTargetOffset) : CDirection(CONSTRUCT_CLEAR); if (m_pobOffsetConverger) { m_pobOffsetConverger->Update(CPoint(obAppliedLocalOffset),fTimeChange); SetLastTracked(GetLastTracked()+(CDirection(m_pobOffsetConverger->GetDamped())*(m_pParent->GetTransform()))); } else { SetLastTracked(GetLastTracked()+(obAppliedLocalOffset*(m_pParent->GetTransform()))); } // This is our LAC target point. Might not be there yet due to smoothing SetTarget(GetLastTracked()); // feed this into our point smoother if we have one if(m_pobPOISmooth) { m_pobPOISmooth->Update(GetLastTracked(), fTimeChange); SetLastTracked(m_pobPOISmooth->GetTargetMean()); } // Clamp to box if required if(m_bBound) { CPoint obPt = GetLastTracked(); obPt.X() = ntstd::Clamp(obPt.X(), m_obBoundMin.X(), m_obBoundMax.X()); obPt.Y() = ntstd::Clamp(obPt.Y(), m_obBoundMin.Y(), m_obBoundMax.Y()); obPt.Z() = ntstd::Clamp(obPt.Z(), m_obBoundMin.Z(), m_obBoundMax.Z()); SetLastTracked(obPt); } } /*************************************************************************************************** * * FUNCTION LookAtController::ModifyLookat * * DESCRIPTION Adjust the transform if nessecary * ***************************************************************************************************/ CMatrix LookAtController::ModifyLookat(const CMatrix& obMat) { // convert matrix to quat // check for smoothing of our rotations.. // if(m_bUseSteadyFocus) // m_pobRotSmooth->Update(obNewDir); // obNewDir = m_pobRotSmooth->GetTargetMean(); // check for a final converge to our target rotation // if(m_pobRotConv) // obNewDir = m_pobRotConv->Update(obNewDir); // convert quat back to matrix return obMat; } /*************************************************************************************************** * * FUNCTION LookAtController::Render * * DESCRIPTION render stuff * ***************************************************************************************************/ void LookAtController::Render() { if(m_pobPOITrans) m_pobPOITrans->Render(); if(m_pobPOISmooth) m_pobPOISmooth->Render(); } /*************************************************************************************************** * * FUNCTION LookAtController::Render * * DESCRIPTION render stuff * ***************************************************************************************************/ void LookAtController::RenderInfo(int iX, int iY) { UNUSED(iX); UNUSED(iY); //CCamUtil::DebugPrintf(iX, iY, "LookAtController: %s", GetNameC()); } //------------------------------------------------------------------------------------------ //! //! LACFixedPosDef::Create //! Create an LACFixedPos from this definition //! //------------------------------------------------------------------------------------------ class LookAtController* LACFixedPosDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACFixedPos(*this, pParent); } /*************************************************************************************************** * * FUNCTION LACFixedPos::LACFixedPos * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACFixedPos::LACFixedPos(const LACFixedPosDef& def, const BasicCamera* pParent) : LookAtController(pParent, def), m_def(def) { } /*************************************************************************************************** * * FUNCTION LACFixedPos::Update * * DESCRIPTION calc our current look at matrix * ***************************************************************************************************/ CMatrix LACFixedPos::Update(const CPoint& obCurrPos, float fTimeChange) { UNUSED(fTimeChange); SetLastTracked(m_def.m_obPosition); SetTarget(m_def.m_obPosition); CMatrix obTemp; CCamUtil::CreateFromPoints(obTemp, obCurrPos, GetLastTracked()); SetLastTransform(ModifyLookat(obTemp)); return GetLastTransform(); } /*************************************************************************************************** * * FUNCTION LACFixedPos::Render * * DESCRIPTION render stuff * ***************************************************************************************************/ void LACFixedPos::Render() { LookAtController::Render(); CCamUtil::Render_Sphere(m_def.m_obPosition, 0.2f, 1.0f, 0.0f, 0.0f, 1.0f); } //------------------------------------------------------------------------------------------ //! //! LACFixedDirDef::Create //! Create an LACFixedPos from this definition //! //------------------------------------------------------------------------------------------ LookAtController* LACFixedDirDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACFixedDir(*this, pParent); } /*************************************************************************************************** * * FUNCTION LACFixedDir::LACFixedDir * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACFixedDir::LACFixedDir(const LACFixedDirDef& def, const BasicCamera* pParent) : LookAtController(pParent, def), m_def(def) { } /*************************************************************************************************** * * FUNCTION LACFixedDir::Update * * DESCRIPTION calc our current lookat matrix * ***************************************************************************************************/ CMatrix LACFixedDir::Update(const CPoint& obCurrPos, float fTimeChange) { UNUSED(fTimeChange); SetLastTracked(obCurrPos + m_def.m_obDirection); SetTarget(obCurrPos + m_def.m_obDirection); CMatrix obTempMat; CCamUtil::CreateFromPoints(obTempMat, obCurrPos, GetLastTracked()); SetLastTransform(ModifyLookat(obTempMat)); return GetLastTransform(); } //------------------------------------------------------------------------------------------ //! //! LACFixedYPRDef::Create //! Create an LACFixedPos from this definition //! //------------------------------------------------------------------------------------------ LookAtController* LACFixedYPRDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACFixedYPR(*this, pParent); } /*************************************************************************************************** * * FUNCTION LACFixedYPR::LACFixedYPR * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACFixedYPR::LACFixedYPR(const LACFixedYPRDef& def, const BasicCamera* pParent) : LookAtController(pParent, def), m_def(def) { } /*************************************************************************************************** * * FUNCTION LACFixedYPR::Update * * DESCRIPTION calc our current lookat matrix * ***************************************************************************************************/ CMatrix LACFixedYPR::Update(const CPoint& obCurrPos, float fTimeChange) { UNUSED(fTimeChange); // construct our matrix from YPR CMatrix obTempMat(CCamUtil::QuatFromYawPitchRoll(m_def.m_obYawPitchRoll.X(), m_def.m_obYawPitchRoll.Y(), m_def.m_obYawPitchRoll.Z()), obCurrPos); // construct a fake last tracked for transitions to use. // NB this is 10 meters infront untill its a mappable parameter SetLastTracked(obCurrPos + (obTempMat.GetZAxis() * FOCAL_DISTANCE_HACK)); SetTarget(GetLastTracked()); SetLastTransform(ModifyLookat(obTempMat)); return GetLastTransform(); } //------------------------------------------------------------------------------------------ //! //! LACPOIRelDef::Create //! Create an LACFixedPos from this definition //! //------------------------------------------------------------------------------------------ LookAtController* LACPOIRelDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACPOIRel(pParent, *this); } /*************************************************************************************************** * * FUNCTION LACPOIRel::LACPOIRel * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACPOIRel::LACPOIRel(const BasicCamera* pParent, const LACPOIRelDef& def) : LookAtController(pParent, def) { } /*************************************************************************************************** * * FUNCTION LACPOIRel::Update * * DESCRIPTION calc our current lookat matrix * ***************************************************************************************************/ CMatrix LACPOIRel::Update(const CPoint& obCurrPos, float fTimeChange) { CalcLastTracked(fTimeChange); CMatrix obTempMat; CCamUtil::CreateFromPoints(obTempMat, obCurrPos, GetLastTracked()); SetLastTransform(ModifyLookat(obTempMat)); return GetLastTransform(); } //------------------------------------------------------------------------------------------ //! //! LACRotRailDef::Create //! Create an LACRotRail from this definition //! //------------------------------------------------------------------------------------------ LookAtController* LACRotRailDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACRotRail(*this, pParent); } /*************************************************************************************************** * * FUNCTION LACRotRail::LACRotRail * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACRotRail::LACRotRail(const LACRotRailDef& def, const BasicCamera* pParent) : LookAtController(pParent, def), m_def(def), m_fCurrPos(0.f) { Reset(); } LACRotRail::~LACRotRail() { // NB, the rail will free our m_pobRotCurve for us //FIX: //NT_DELETE(m_pobRail); } /*************************************************************************************************** * * FUNCTION LACRotRail::Reset * * DESCRIPTION reset the LAC * ***************************************************************************************************/ void LACRotRail::Reset() { LookAtController::Reset(); m_fCurrPos = 0.0f; m_def.m_pobRail->Reset(); } /*************************************************************************************************** * * FUNCTION LACRotRail::Update * * DESCRIPTION calc our current lookat matrix * ***************************************************************************************************/ CMatrix LACRotRail::Update(const CPoint& obCurrPos, float fTimeChange) { CalcLastTracked(fTimeChange); m_def.m_pobRail->TrackPoint(GetLastTracked(), fTimeChange); m_fCurrPos = m_def.m_pobRail->GetDampedVal(); CMatrix obTempMat = m_def.m_pobRotCurve->GetRotation(m_fCurrPos); obTempMat.SetTranslation(obCurrPos); SetLastTransform(ModifyLookat(obTempMat)); return GetLastTransform(); } /*************************************************************************************************** * * FUNCTION LACRotRail::Render * * DESCRIPTION render stuff * ***************************************************************************************************/ void LACRotRail::Render() { LookAtController::Render(); m_def.m_pobRail->Render(); } //------------------------------------------------------------------------------------------ //! //! LACRotGuideDef::Create //! Create an LACRotGuide from this definition //! //------------------------------------------------------------------------------------------ LookAtController* LACRotGuideDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACRotGuide(*this, pParent); } /*************************************************************************************************** * * FUNCTION LACRotGuide::LACRotGuide * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACRotGuide::LACRotGuide(const LACRotGuideDef& def, const BasicCamera* pParent) : LookAtController(pParent, def), m_def(def), m_fCurrPos(0.f) { ntAssert_p(GetPOITrans(), ("LACRotGuide must have a CPointTransform of type GUIDE_CURVE")); ntAssert_p(GetPOITrans()->GetTransformType() == PointTransform::GUIDE_CURVE, ("LACRotGuide must have a CPointTransform of type GUIDE_CURVE")); Reset(); } LACRotGuide::~LACRotGuide() { // NB, the rail will free our m_pobRotCurve for us //FIX: //NT_DELETE(m_pobRail); } /*************************************************************************************************** * * FUNCTION LACRotGuide::Reset * * DESCRIPTION reset the LAC * ***************************************************************************************************/ void LACRotGuide::Reset() { LookAtController::Reset(); m_fCurrPos = 0.0f; m_def.m_pobRail->Reset(); } /*************************************************************************************************** * * FUNCTION LACRotGuide::Update * * DESCRIPTION calc our current lookat matrix * ***************************************************************************************************/ CMatrix LACRotGuide::Update(const CPoint& obCurrPos, float fTimeChange) { CalcLastTracked(fTimeChange); // feed guide value into the rail as our target paramater PTGuide* pPOI = static_cast<PTGuide*>(GetPOITrans()); m_fCurrPos = pPOI->GetGuideVal(); m_def.m_pobRail->TrackTarget(m_fCurrPos, GetLastTracked(), fTimeChange); // now retrive the damped converged value and use that as our rotation m_fCurrPos = m_def.m_pobRail->GetDampedVal(); CMatrix obTempMat = m_def.m_pobRotCurve->GetRotation(m_fCurrPos); obTempMat.SetTranslation(obCurrPos); SetLastTransform(ModifyLookat(obTempMat)); return GetLastTransform(); } /*************************************************************************************************** * * FUNCTION LACRotGuide::Render * * DESCRIPTION render stuff * ***************************************************************************************************/ void LACRotGuide::Render() { LookAtController::Render(); m_def.m_pobRail->Render(); } //------------------------------------------------------------------------------------------ //! //! LACGuideRailDef::Create //! Create an LACGuideRail from this definition //! //------------------------------------------------------------------------------------------ LookAtController* LACGuideRailDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACGuideRail(*this, pParent); } /*************************************************************************************************** * * FUNCTION LACGuideRail::LACGuideRail * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACGuideRail::LACGuideRail(const LACGuideRailDef& def, const BasicCamera* pParent) : LookAtController(pParent, def), m_def(def), m_fCurrPos(0.f) { ntAssert_p(GetPOITrans(), ("LACGuideRail must have a CPointTransform of type GUIDE_CURVE")); ntAssert_p(GetPOITrans()->GetTransformType() == PointTransform::GUIDE_CURVE, ("LACRotGuide must have a CPointTransform of type GUIDE_CURVE")); Reset(); } LACGuideRail::~LACGuideRail() { //FIX: //NT_DELETE(m_pobRail); } /*************************************************************************************************** * * FUNCTION LACGuideRail::Reset * * DESCRIPTION reset the LAC * ***************************************************************************************************/ void LACGuideRail::Reset() { LookAtController::Reset(); m_fCurrPos = 0.0f; m_def.m_pobRail->Reset(); } /*************************************************************************************************** * * FUNCTION LACGuideRail::Update * * DESCRIPTION calc our current lookat matrix * ***************************************************************************************************/ CMatrix LACGuideRail::Update(const CPoint& obCurrPos, float fTimeChange) { CalcLastTracked(fTimeChange); // feed guide value into the rail as our target paramater PTGuide* pPOI = static_cast<PTGuide*>(GetPOITrans()); m_fCurrPos = pPOI->GetGuideVal(); m_def.m_pobRail->TrackTarget(m_fCurrPos, GetLastTracked(), fTimeChange); // now retrive the damped converged positon and use that as our rotation target SetLastTracked(m_def.m_pobRail->GetDampedPoint()); SetTarget(GetLastTracked()); CMatrix obTempMat; CCamUtil::CreateFromPoints(obTempMat, obCurrPos, GetLastTracked()); SetLastTransform(ModifyLookat(obTempMat)); return GetLastTransform(); } /*************************************************************************************************** * * FUNCTION LACGuideRail::Render * * DESCRIPTION render stuff * ***************************************************************************************************/ void LACGuideRail::Render() { LookAtController::Render(); m_def.m_pobRail->Render(); } //------------------------------------------------------------------------------------------ //! //! LACRailDef::Create //! Create an LACRail from this definition //! //------------------------------------------------------------------------------------------ LookAtController* LACRailDef::Create(const BasicCamera* pParent) { return NT_NEW_CHUNK(Mem::MC_CAMERA) LACRail(*this, pParent); } /*************************************************************************************************** * * FUNCTION LACRail::LACRail * * DESCRIPTION Construct the LAC * ***************************************************************************************************/ LACRail::LACRail(const LACRailDef& def, const BasicCamera* pParent) : LookAtController(pParent, def), m_def(def) { Reset(); } LACRail::~LACRail() { //FIX: //NT_DELETE(m_pobRail); } /*************************************************************************************************** * * FUNCTION LACRail::Reset * * DESCRIPTION reset the LAC * ***************************************************************************************************/ void LACRail::Reset() { LookAtController::Reset(); m_def.m_pobRail->Reset(); } /*************************************************************************************************** * * FUNCTION LACRail::Update * * DESCRIPTION calc our current lookat matrix * ***************************************************************************************************/ CMatrix LACRail::Update(const CPoint& obCurrPos, float fTimeChange) { CalcLastTracked(fTimeChange); // feed our POI position into our rail m_def.m_pobRail->TrackPoint(GetLastTracked(), fTimeChange); // now retrive the damped converged positon and use that as our rotation target SetLastTracked(m_def.m_pobRail->GetDampedPoint()); SetTarget(GetLastTracked()); CMatrix obTempMat; CCamUtil::CreateFromPoints(obTempMat, obCurrPos, GetLastTracked()); SetLastTransform(ModifyLookat(obTempMat)); return GetLastTransform(); } /*************************************************************************************************** * * FUNCTION LACRail::Render * * DESCRIPTION render stuff * ***************************************************************************************************/ void LACRail::Render() { LookAtController::Render(); m_def.m_pobRail->Render(); }
ec06ad7832f188880282b1d588f7f20ef268be17
f83ef53177180ebfeb5a3e230aa29794f52ce1fc
/ACE/ACE_wrappers/TAO/DevGuideExamples/Multithreading/Reactive/Messenger_i.cpp
fd6851b32b21d7a8fd124761491546ce6f28d26e
[ "LicenseRef-scancode-warranty-disclaimer", "Apache-2.0", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-proprietary-license", "LicenseRef-scancode-sun-iiop" ]
permissive
msrLi/portingSources
fe7528b3fd08eed4a1b41383c88ee5c09c2294ef
57d561730ab27804a3172b33807f2bffbc9e52ae
refs/heads/master
2021-07-08T01:22:29.604203
2019-07-10T13:07:06
2019-07-10T13:07:06
196,183,165
2
1
Apache-2.0
2020-10-13T14:30:53
2019-07-10T10:16:46
null
UTF-8
C++
false
false
943
cpp
Messenger_i.cpp
/* -*- C++ -*- */ // ****** Code generated by the The ACE ORB (TAO) IDL Compiler ******* // TAO and the TAO IDL Compiler have been developed by the Center for // Distributed Object Computing at Washington University, St. Louis. // // Information about TAO is available at: // http://www.dre.vanderbilt.edu/~schmidt/TAO.html #include "Messenger_i.h" #include <iostream> // Implementation skeleton constructor Messenger_i::Messenger_i (void) { } // Implementation skeleton destructor Messenger_i::~Messenger_i (void) { } CORBA::Boolean Messenger_i::send_message ( const char * user_name, const char * subject, char *& message ) { std::cout << "Message from: " << user_name << std::endl; std::cout << "Subject: " << subject << std::endl; std::cout << "Message: " << message << std::endl; CORBA::string_free(message); message = CORBA::string_dup("Thanks for the message."); return true; }
6e9b619d45c64af2cf53f2b5346bc5bfa2e7832c
3d95a585e38213604060f2ee26c624efa1a2c706
/library/test/unit/mipi_syst_string_test.cpp
c2fdbcfe5b73dc9e72c37f0c0578038707f5e3a9
[ "LicenseRef-scancode-unknown-license-reference", "BSD-3-Clause" ]
permissive
zephyrproject-rtos/mipi-sys-t
d76fedd97cd23f2130396032bfa843f27d25a32b
a819419603a2dfcb47f7f39092e1bc112e45d1ef
refs/heads/zephyr
2023-06-25T03:41:33.306662
2023-06-15T19:38:07
2023-06-15T21:26:47
217,042,311
5
7
BSD-3-Clause
2023-06-15T21:26:48
2019-10-23T11:37:29
C
UTF-8
C++
false
false
11,253
cpp
mipi_syst_string_test.cpp
/* Copyright (c) 2018, MIPI Alliance, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * Contributors: * Norbert Schulz (Intel Corporation) - Initial API and implementation */ #include "mipi_syst_gtest.h" #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA) &&\ defined(MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE) &&\ defined(MIPI_SYST_PCFG_ENABLE_STRING_API) class MipiSysTFixtureDebugString : public MipiSysTFixtureOutput { public: void SetUp() { MipiSysTFixtureOutput::SetUp(); } void TearDown(){ MipiSysTFixtureOutput::TearDown(); } const char * mipi_syst_write_debug_string(struct mipi_syst_handle* svh, struct mipi_syst_msglocation* loc, enum mipi_syst_subtype_string type, enum mipi_syst_severity severity, mipi_syst_u16 len, const char * str) { sstr.str(""); ::mipi_syst_write_debug_string(svh, loc, type, severity, len, str); result = sstr.str(); return result.c_str(); } static std::string result; }; std::string MipiSysTFixtureDebugString::result; TEST_F(MipiSysTFixtureDebugString, syst_string_null) { EXPECT_STREQ( xform(""), MIPI_SYST_DEBUG(NULL, MIPI_SYST_SEVERITY_WARNING, "", 1) ); EXPECT_STREQ( xform("<D32TS>05012232[typ=2:5 mu=1:2 sev=3 len]<D16>0007<D32>6c756e28<D16>296c<D8>00<FLAG>"), MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, NULL, 1) ); } TEST_F(MipiSysTFixtureDebugString, syst_func_enter_output) { EXPECT_STREQ( xform("<D32TS>02012232[typ=2:2 mu=1:2 sev=3 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_ENTER(ph, MIPI_SYST_SEVERITY_WARNING) ); } TEST_F(MipiSysTFixtureDebugString, syst_func_exit_output) { EXPECT_STREQ( xform("<D32TS>03012232[typ=2:3 mu=1:2 sev=3 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_EXIT(ph, MIPI_SYST_SEVERITY_WARNING) ); } TEST_F(MipiSysTFixtureDebugString, syst_debugstring_output) { EXPECT_STREQ( xform("<D32TS>01012232[typ=2:1 mu=1:2 sev=3 len]<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12) ); #if defined(MIPI_SYST_PCFG_ENABLE_CHECKSUM) MIPI_SYST_ENABLE_HANDLE_CHECKSUM(ph,1); #if defined(MIPI_SYST_PCFG_LENGTH_FIELD) EXPECT_STREQ( xform("<D32TS>01012632[typ=2:1 mu=1:2 sev=3 len chk]<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<D32>eab806d3<FLAG>"), MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12) ); #else EXPECT_STREQ( xform("<D32TS>01012432[typ=2:1 mu=1:2 sev=3 chk]<D64>6f77206f6c6c6548<D32>21646c72<D32>ff19ff90<FLAG>"), MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!", 12) ); #endif MIPI_SYST_ENABLE_HANDLE_CHECKSUM(ph,0); #endif #if defined(MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID) // {8887160A-C965-463b-9F43-1EFE9FDFE3F9} const struct mipi_syst_guid aguid = MIPI_SYST_GEN_GUID(0x8887160A, 0xC965, 0x463b, 0x9F43, 0x1EFE9FDFE3F9); MIPI_SYST_SET_HANDLE_GUID_UNIT(ph, aguid, 7); EXPECT_STREQ( xform("<D32TS>01807252[typ=2:1 mu=0:7 sev=5 len]<D64>3b4665c90a168788<D64>f9e3df9ffe1e439f<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_USER1, "Hello world!" , 12) ); #endif } #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD) TEST_F(MipiSysTFixtureDebugString, syst_debugstring_loc) { EXPECT_STREQ( xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>00<D32>5678abcd<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG_LOC16(ph, MIPI_SYST_SEVERITY_WARNING, 0xabcd, "Hello world!" , 12) ); EXPECT_STREQ( xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>01<D64>123456780000abcd<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG_LOC32(ph, MIPI_SYST_SEVERITY_WARNING,0xabcd, "Hello world!" , 12) ); #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS) #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR) EXPECT_STREQ( xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>03<D64>12345678aabbccdd<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG_LOCADDR(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12) ); #else EXPECT_STREQ( xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>02<D32>12345678<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG_LOCADDR(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12) ); #endif #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS } #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD TEST_F(MipiSysTFixtureDebugString, syst_debugstring_nolength) { MIPI_SYST_ENABLE_HANDLE_LENGTH(ph,0); EXPECT_STREQ( xform("<D32TS>01012032[typ=2:1 mu=1:2 sev=3]<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12) ); MIPI_SYST_ENABLE_HANDLE_LENGTH(ph,1); EXPECT_STREQ( xform("<D32TS>01012232[typ=2:1 mu=1:2 sev=3 len]<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"), MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12) ); } TEST_F(MipiSysTFixtureDebugString, syst_func_enter) { EXPECT_STREQ( xform("<D32TS>02012242[typ=2:2 mu=1:2 sev=4 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_ENTER(ph, MIPI_SYST_SEVERITY_INFO) ); #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD) EXPECT_STREQ( xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>00<D32>5678abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_ENTER_LOC16(ph, MIPI_SYST_SEVERITY_INFO,0xabcd) ); EXPECT_STREQ( xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>01<D64>123456780000abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_ENTER_LOC32(ph, MIPI_SYST_SEVERITY_INFO,0xabcd) ); #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS) #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR) EXPECT_STREQ( xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>03<D64>12345678aabbccdd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_ENTER_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO) ); #else EXPECT_STREQ( xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>02<D32>12345678<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_ENTER_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO) ); #endif //MIPI_SYST_PCFG_ENABLE_64BIT_ADDR #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD } TEST_F(MipiSysTFixtureDebugString, syst_func_exit) { EXPECT_STREQ( xform("<D32TS>03012242[typ=2:3 mu=1:2 sev=4 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_EXIT(ph, MIPI_SYST_SEVERITY_INFO) ); #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD) EXPECT_STREQ( xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>00<D32>5678abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_EXIT_LOC16(ph, MIPI_SYST_SEVERITY_INFO,0xabcd) ); EXPECT_STREQ( xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>01<D64>123456780000abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_EXIT_LOC32(ph, MIPI_SYST_SEVERITY_INFO,0xabcd) ); #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS) #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR) EXPECT_STREQ( xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>03<D64>12345678aabbccdd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_EXIT_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO) ); #else EXPECT_STREQ( xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>02<D32>12345678<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"), MIPI_SYST_FUNC_EXIT_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO) ); #endif //MIPI_SYST_PCFG_ENABLE_64BIT_ADDR #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD } #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD) TEST_F(MipiSysTFixtureDebugString, syst_debug_assert) { MIPI_SYST_ASSERT(ph, MIPI_SYST_SEVERITY_ERROR, 0); EXPECT_STREQ( xform("<D32TS>07012222[typ=2:7 mu=1:2 sev=2 len]<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"), result.c_str() ); result = ""; MIPI_SYST_ASSERT(ph, MIPI_SYST_SEVERITY_ERROR, 1); EXPECT_STREQ( "", result.c_str() ); #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS) MIPI_SYST_ASSERT_LOCADDR(ph, MIPI_SYST_SEVERITY_ERROR, 0); #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR) EXPECT_STREQ( xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>03<D64>12345678aabbccdd<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"), result.c_str() ); #else EXPECT_STREQ( xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>02<D32>12345678<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"), result.c_str() ); #endif result = ""; MIPI_SYST_ASSERT_LOCADDR(ph, MIPI_SYST_SEVERITY_ERROR, 1); EXPECT_STREQ( "", result.c_str() ); #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS MIPI_SYST_ASSERT_LOC16(ph, MIPI_SYST_SEVERITY_ERROR, 0xabcd, 0); EXPECT_STREQ( xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>00<D32>5678abcd<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"), result.c_str() ); result = ""; MIPI_SYST_ASSERT_LOC16(ph, MIPI_SYST_SEVERITY_ERROR,0xabcd, 1); EXPECT_STREQ( "", result.c_str() ); MIPI_SYST_ASSERT_LOC32(ph, MIPI_SYST_SEVERITY_ERROR, 0xabcd, 0); EXPECT_STREQ( xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>01<D64>123456780000abcd<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"), result.c_str() ); result = ""; MIPI_SYST_ASSERT_LOC32(ph, MIPI_SYST_SEVERITY_ERROR, 0xabcd, 1); EXPECT_STREQ( "", result.c_str() ); } #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD #endif //MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA && MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE && MIPI_SYST_PCFG_ENABLE_STRING_API
23ceb1a890ed0f648f30d9bdb33f41d21911d4b8
67d8e6d695d359e7ab4fe4422c20356da60a58f4
/30 Days of Code/Day 3: Intro to Conditional Statements.cpp
dc41030e17db88b4404493bec0b8b14ebdd4be85
[ "MIT" ]
permissive
thelvir/HackerRank
b03647ee3c4dc7c53345a8449cd3542a1565ec8d
4d02fb1f884d46210b373cd48dc9da9bb6f9a876
refs/heads/main
2023-04-04T20:47:14.930771
2021-04-02T11:09:04
2021-04-02T11:09:04
331,679,358
2
0
null
null
null
null
UTF-8
C++
false
false
321
cpp
Day 3: Intro to Conditional Statements.cpp
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>>n; if(n%2!=0) cout<<"Weird"<<endl; else if(n%2==0 && n>2 && n<5) cout << "Not Weird"<<endl; else if(n%2==0 && n>6 &&n<=20) cout<<"Weird"<<endl; else if (n%2==0 && n>20) cout << "Not Weird"; return 0; }
2aa1942a8b3a81ca11ff72644f1db2faedf4424a
6267db02012d1e206f23132879ae3579927c74e0
/图论/连通图/无向图求桥.cpp
bfd61db54e84bd2236921bad888c03a972c71c47
[]
no_license
37keke/ACM-ICPC
febafc1842f88699ef483e303b881716bc6d68e6
c3896e0451d96cf8b8a7c8d2214b3055dcd70cbe
refs/heads/master
2020-03-08T13:21:06.565286
2019-03-26T12:52:07
2019-03-26T12:52:07
128,155,703
0
0
null
null
null
null
UTF-8
C++
false
false
2,930
cpp
无向图求桥.cpp
/*给一张无向图,你需要将边定向,使得定向后的有向图强连通。 0代表x到y 1代表y到x */ #define ll long long #define inf 0x3f3f3f3f #define N 1500005 #define M 1500005 using namespace std; void read(int &x){scanf("%d",&x);} int fg; int n,m;//n个点 m条边 struct node { int from,to,nex; int cut;//记录这条边是否为割边(桥) }edge[2*M]; //双向边则 edge[i]与edge[i^1]是2条反向边 int head[N] ,num;//在一开始就要 memset(head,-1,sizeof(head)); num=0; int low[N],dfn[N],Index; void add(int u,int v) { node E={u,v,head[u],0}; edge[num]=E; head[u]=num++; } void tarjin(int u,int pre) { low[u]=dfn[u]= ++Index; int flag=1;//flag是阻止双向边的反向边 i和i^1 for(int i=head[u];i!=-1;i=edge[i].nex) { int v=edge[i].to; if(flag&&v==pre) { flag=0; continue; } if(!dfn[v]) { tarjin(v,u); if(low[u]>low[v])low[u]=low[v]; if(low[v]>dfn[u])//是桥low[v]表示v能走到的最早祖先 //有重边且u是v的最早祖先 则low[v]==dfn[u],所以不会当作桥 //这个位置是桥 {fg=1;edge[i].cut=edge[i^1].cut=1;} } else if(low[u]>dfn[v])low[u]=dfn[v]; } } bool liantong;//是否连通 void find_edgecut() { memset(dfn,0,sizeof(dfn)); Index=0; tarjin(1,1); liantong=true; for(int i=1;i<=n;i++)if(!dfn[i]){liantong=false;return;} } bool vis[N]; void init(){ for(int i = 0;i<=n;i++)head[i] = -1; num = 0; memset(vis, 0, sizeof(vis)); fg = 0; } void dfs(int u){ vis[u] = true; for(int i = head[u]; i!=-1; i = edge[i].nex){ int v = edge[i].to; if(edge[i].cut==1) continue; if(edge[i].cut==0) { edge[i].cut=1; edge[i^1].cut=-1; } if(!vis[v]) dfs(v); } } int main(){ int u, v; read(n);read(m);{ init(); // while(m--){ read(u);read(v); add(u, v); add(v, u); } find_edgecut(); if(fg){puts("impossible");return 0;} dfs(1); for(int i = 0; i < num; i+=2) if(edge[i].cut==1)printf("1"); else printf("0"); puts(""); } return 0; } /*求所有桥中最小的桥的权值 int main() { int i,j,k; while(~scanf("%d%d",&n,&m),n) { memset(head,-1,sizeof(head)); edgenum=0; while(m--) { scanf("%d%d%d",&i,&j,&k); add(i,j,k); add(j,i,k); } find_edgecut(); int ans=inf; if(liantong==false){puts("0");continue;} for(int i=0;i<num;i++)if(edge[i].cut) { if(edge[i].val<ans)ans=edge[i].val; } if(ans==inf)ans=-1; if(ans==0)ans=1; printf("%d\n",ans); } return 0; }
389e82205705b50a0bcd6406da2c78389a1db8e9
41122920d20ff83d77c0735d85449252b628c4d2
/CGameSetting.cpp
8b3032bbae6e0930bedfb0c4a7dbbc181185d968
[]
no_license
Night-Govery/Bejeweled
54031aafa79b39d003621e70cba6e8938a5d0913
8207af6b81cc74931ff405b76fcf032b15f24ca4
refs/heads/master
2022-11-06T01:25:13.479509
2020-06-19T04:50:13
2020-06-19T04:50:13
273,406,296
0
0
null
null
null
null
UTF-8
C++
false
false
368
cpp
CGameSetting.cpp
#include "CGameSetting.h" #include "ui_CGameSetting.h" CGameSetting::CGameSetting(QWidget *parent) : QDialog(parent), ui(new Ui::CGameSetting) { ui->setupUi(this); } CGameSetting::~CGameSetting() { delete ui; } void CGameSetting::on_pushButton_clicked() { emit voiceOn(); } void CGameSetting::on_pushButton_2_clicked() { emit voiceOff(); }
fbcdfb2dd5bad6369460950970dd2a91d99cbd56
971713859cee54860e32dce538a7d5e796487c68
/unisim/unisim_lib/unisim/service/loader/pmac_bootx/pmac_bootx.hh
2aaa2215c45f358133cc078a8480d4ab009c28b9
[]
no_license
binsec/cav2021-artifacts
3d790f1e067d1ca9c4123010e3af522b85703e54
ab9e387122968f827f7d4df696c2ca3d56229594
refs/heads/main
2023-04-15T17:10:10.228821
2021-04-26T15:10:20
2021-04-26T15:10:20
361,684,640
2
0
null
null
null
null
UTF-8
C++
false
false
10,671
hh
pmac_bootx.hh
/* * Copyright (c) 2007, * Commissariat a l'Energie Atomique (CEA) * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * - Neither the name of CEA nor the names of its contributors may be used to * endorse or promote products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * Authors: Gilles Mouchard (gilles.mouchard@cea.fr) */ #ifndef __UNISIM_SERVICE_LOADER_PMAC_BOOTX_PMAC_BOOTX_HH__ #define __UNISIM_SERVICE_LOADER_PMAC_BOOTX_PMAC_BOOTX_HH__ #include <unisim/service/interfaces/loader.hh> #include <unisim/service/interfaces/memory.hh> #include <unisim/service/interfaces/registers.hh> #include <unisim/service/interfaces/blob.hh> #include <unisim/util/xml/xml.hh> #include <unisim/kernel/kernel.hh> #include <unisim/kernel/variable/variable.hh> #include <unisim/kernel/logger/logger.hh> #include <list> #include <string> #include <inttypes.h> namespace unisim { namespace service { namespace loader { namespace pmac_bootx { using std::list; using std::string; using unisim::service::interfaces::Memory; using unisim::service::interfaces::Registers; using unisim::service::interfaces::Loader; using unisim::service::interfaces::Blob; using unisim::kernel::Service; using unisim::kernel::Client; using unisim::kernel::ServiceImport; using unisim::kernel::ServiceExport; using unisim::kernel::ServiceExportBase; using unisim::kernel::Object; using unisim::kernel::variable::Parameter; struct DeviceProperty { uint32_t name; // char *name; int32_t length; uint32_t value; //unsigned char *value; uint32_t next; // struct property *next; }; struct DeviceNode { uint32_t name; // char *name uint32_t type; // char *type uint32_t node; // phandle node int32_t n_addrs; uint32_t addrs; // struct address_range *addrs int32_t n_intrs; uint32_t intrs; // struct interrupt_info *intrs uint32_t full_name; // char *full_name uint32_t properties; // struct property *properties uint32_t parent; // struct device_node *parent uint32_t child; // struct device_node *child; uint32_t sibling; // struct device_node *sibling; uint32_t next; // struct device_node *next /* next device of same type */ uint32_t allnext; // struct device_node *allnext; /* next in list of all nodes */ }; class BootInfos; class DeviceTree { public: DeviceTree(BootInfos *boot_infos, unisim::kernel::logger::Logger& logger, bool verbose); virtual ~DeviceTree(); bool Load(const string& filename); uint32_t GetBase(); uint32_t GetSize(); DeviceNode *FindDevice(const char *prop_name, const char *prop_string_value); uint8_t *GetProperty(DeviceNode *reloc_node, const char *name, int32_t& len); private: unisim::kernel::logger::Logger& logger; BootInfos *boot_infos; DeviceNode *root_node; DeviceNode *last_reloc_node; uint32_t base; uint32_t size; bool verbose; uint32_t Malloc(uint32_t size); void *Relocate(uint32_t offset); uint32_t UnRelocate(void *p); DeviceProperty *CreateDeviceProperty(const char *name, const uint8_t *value, int32_t len); DeviceProperty *CreateDeviceProperty(const unisim::util::xml::Node *xml_node); DeviceNode *CreateDeviceNode(DeviceNode *reloc_parent, const unisim::util::xml::Node *xml_node); void DumpDeviceProperty(DeviceProperty *reloc_prop); void DumpDeviceNode(DeviceNode *reloc_node); unsigned int ExpandEscapeSequences(const string& s, char *buffer); }; class BootInfos { public: static const uint32_t MAX_BOOT_INFOS_IMAGE_SIZE = 104 * 1024 * 1024; // 104 MB BootInfos(unisim::kernel::logger::Logger& logger, bool verbose); virtual ~BootInfos(); uint32_t Malloc(uint32_t size); void *Relocate(uint32_t offset); uint32_t UnRelocate(void *p); bool Load(uint32_t boot_infos_addr, const string& device_tree_filename, const string& kernel_parms, const string& ramdisk_filename, unsigned int screen_width, unsigned int screen_height); const unisim::util::blob::Blob<uint32_t> *GetBlob() const; private: unisim::kernel::logger::Logger& logger; bool verbose; uint32_t size; uint32_t max_size; uint8_t *image; unisim::util::blob::Blob<uint32_t> *blob; /* On kernel entry: * * r3 = 0x426f6f58 ('BooX') * r4 = pointer to boot_infos * r5 = NULL * * Data and instruction translation disabled, interrupts * disabled, kernel loaded at physical 0x00000000 on PCI * machines (will be different on NuBus). */ static const uint32_t BOOT_INFO_VERSION = 5; static const uint32_t BOOT_INFO_COMPATIBLE_VERSION = 1; /* Bit in the architecture flag mask. More to be defined in future versions. Note that either BOOT_ARCH_PCI or BOOT_ARCH_NUBUS is set. The other BOOT_ARCH_NUBUS_xxx are set additionally when BOOT_ARCH_NUBUS is set. */ static const uint32_t BOOT_ARCH_PCI = 0x00000001UL; static const uint32_t BOOT_ARCH_NUBUS = 0x00000002UL; static const uint32_t BOOT_ARCH_NUBUS_PDM = 0x00000010UL; static const uint32_t BOOT_ARCH_NUBUS_PERFORMA = 0x00000020UL; static const uint32_t BOOT_ARCH_NUBUS_POWERBOOK = 0x00000040UL; /* Maximum number of ranges in phys memory map */ static const unsigned int MAX_MEM_MAP_SIZE = 26; /* This is the format of an element in the physical memory map. Note that the map is optional and current BootX will only build it for pre-PCI machines */ typedef struct { uint32_t physAddr; /* Physical starting address */ uint32_t size; /* Size in bytes */ } BootInfoMapEntry; /* Here are the boot informations that are passed to the bootstrap * Note that the kernel arguments and the device tree are appended * at the end of this structure. */ typedef struct { /* Version of this structure */ uint32_t version; /* backward compatible down to version: */ uint32_t compatible_version; /* NEW (vers. 2) this holds the current _logical_ base addr of the frame buffer (for use by early boot message) */ uint32_t logicalDisplayBase; /* NEW (vers. 4) Apple's machine identification */ uint32_t machineID; /* NEW (vers. 4) Detected hw architecture */ uint32_t architecture; /* The device tree (internal addresses relative to the beginning of the tree, * device tree offset relative to the beginning of this structure). * On pre-PCI macintosh (BOOT_ARCH_PCI bit set to 0 in architecture), this * field is 0. */ uint32_t deviceTreeOffset; /* Device tree offset */ uint32_t deviceTreeSize; /* Size of the device tree */ /* Some infos about the current MacOS display */ uint32_t dispDeviceRect[4]; /* left,top,right,bottom */ uint32_t dispDeviceDepth; /* (8, 16 or 32) */ uint32_t dispDeviceBase; /* base address (physical) */ uint32_t dispDeviceRowBytes; /* rowbytes (in bytes) */ uint32_t dispDeviceColorsOffset; /* Colormap (8 bits only) or 0 (*) */ /* Optional offset in the registry to the current * MacOS display. (Can be 0 when not detected) */ uint32_t dispDeviceRegEntryOffset; /* Optional pointer to boot ramdisk (offset from this structure) */ uint32_t ramDisk; uint32_t ramDiskSize; /* size of ramdisk image */ /* Kernel command line arguments (offset from this structure) */ uint32_t kernelParamsOffset; /* ALL BELOW NEW (vers. 4) */ /* This defines the physical memory. Valid with BOOT_ARCH_NUBUS flag (non-PCI) only. On PCI, memory is contiguous and it's size is in the device-tree. */ BootInfoMapEntry physMemoryMap[MAX_MEM_MAP_SIZE]; /* Where the phys memory is */ uint32_t physMemoryMapSize; /* How many entries in map */ /* The framebuffer size (optional, currently 0) */ uint32_t frameBufferSize; /* Represents a max size, can be 0. */ /* NEW (vers. 5) */ /* Total params size (args + colormap + device tree + ramdisk) */ uint32_t totalParamsSize; } BootInfosImage; }; class PMACBootX : public Service<Loader>, public Service<Blob<uint32_t> >, public Client<Loader>, public Client<Blob<uint32_t> >, public Client<Memory<uint32_t> >, public Client<Registers> { public: ServiceExport<Loader> loader_export; ServiceExport<Blob<uint32_t> > blob_export; ServiceImport<Loader> loader_import; ServiceImport<Blob<uint32_t> > blob_import; ServiceImport<Memory<uint32_t> > memory_import; ServiceImport<Registers> registers_import; PMACBootX(const char *name, Object *parent = 0); virtual void OnDisconnect(); virtual bool BeginSetup(); virtual bool Setup(ServiceExportBase *srv_export); virtual bool EndSetup(); virtual const unisim::util::blob::Blob<uint32_t> *GetBlob() const; virtual bool Load(); private: unisim::kernel::logger::Logger logger; string device_tree_filename; string kernel_parms; string ramdisk_filename; unsigned int screen_width; unsigned int screen_height; bool verbose; unisim::util::blob::Blob<uint32_t> *blob; Parameter<string> param_device_tree_filename; Parameter<string> param_kernel_parms; Parameter<string> param_ramdisk_filename; Parameter<unsigned int> param_screen_width; Parameter<unsigned int> param_screen_height; Parameter<bool> param_verbose; bool SetupBlob(); bool SetupLoad(); bool LoadBootInfosAndRegisters(); }; } // end of namesapce pmac_bootx } // end of namespace loader } // end of namespace service } // end of namespace unisim #endif
38ecf0fef7badb3397026a2dce826e221bc8a389
c3d5217edb3dea99c97ac4c665ad7c4b0aec0c2f
/LightOj 1178.cpp
a001335930494f4612756e48bf9ce511fec7d6af
[]
no_license
artugal28373/LightOj-Solutions-2
1d50d5bd9743a933eb6320d2b634bee5882e891f
2ca59eb836d1c0cc0c99d3669d8f7c28212c46df
refs/heads/master
2023-03-18T18:15:03.064338
2018-07-12T22:27:01
2018-07-12T22:27:01
null
0
0
null
null
null
null
UTF-8
C++
false
false
395
cpp
LightOj 1178.cpp
#include<stdio.h> #include<math.h> #include<stdlib.h> int main() { double a,b,c,d,h,area,root,m; int i,t; scanf("%d",&t); for(i=1;i<=t;i++){ scanf("%lf%lf%lf%lf",&a,&c,&b,&d); root=sqrt((-a+b+c+d)*(a-b+c+d)*(a-b-c+d)*(a-b+c-d)); m=2*fabs(a-b); h=root/m; area=h*(a+b)*0.5; printf("Case %d: %.10lf\n",i,area); } return 0; }
41b526fe64c1107f62af1ec8223883206604d787
f955f73a923f9a9130a1cf161f9b2bc07a7fa8ed
/Module5/LA5-1/my_structures.cpp
7da370217a1e7e3023adf20233e25f38de88fd07
[]
no_license
gehrBehr/hafb-cpp-fundamentals
76ee2261c286f9bed4dc15bb242dc066e82991e1
088e6a03d92282d1fb9198efa98b5c9297b8fcb1
refs/heads/master
2020-11-25T01:14:12.315291
2019-12-19T23:26:50
2019-12-19T23:26:50
228,425,159
0
0
null
2019-12-16T16:10:42
2019-12-16T16:10:41
null
UTF-8
C++
false
false
752
cpp
my_structures.cpp
#include <iostream> #include <array> #include <algorithm> struct Part { int model_number; int part_number; float cost; }; struct Car { Part tires; Part doors; Part windows; }; // Local Prototypes void fun(int const& value); int main() { Part part1; part1.model_number = 6244; part1.part_number = 6244; part1.cost = 45.90; std::cout << "Model: " << part1.model_number <<"Part: " << part1.part_number << "Cost $" << part1.cost; Part part2 = {6277, 781, 32.10}; Car sedan; sedan.doors.part_number = 101; sedan.windows.model_number = 7001; sedan.tires.cost = 89.99; return 0; } // Local function definitions void fun(int const& value) { std::cout << value << "\n"; }
a15286b525bc2ffacb0ce3c7650f239f74ad1d85
bf4e1bd077e976c1b63e6854f6607584974341b8
/point.cpp
9e35d663ba8df30bbe0a1f33af189e8e251a1bbc
[]
no_license
joshbenjamin/KMeans-Clustering
97c50f2e2456c782ac322a425f97266757015bd4
ca0a980cfcce1e4600f4c517689fa630d1915462
refs/heads/master
2020-03-25T04:27:06.165306
2018-08-03T07:51:31
2018-08-03T07:51:31
143,395,758
0
0
null
null
null
null
UTF-8
C++
false
false
781
cpp
point.cpp
#include "point.h" #include <iostream> namespace BNJJOS003 { int index; int x; int y; int clusterNumber; point::point() { } point::~point() { index = 0; x = 0; y = 0; clusterNumber = 0; } // Initialising methods void point::setX(int xVal) { x = xVal; } void point::setY(int yVal) { y = yVal; } void point::setIndex(int indVal) { index = indVal; } // Sets this current point's 'ownership' to one of the clusters void point::setClusterNumber(int clus) { clusterNumber = clus; } // This was just used for tracing void point::print() { std::cout << this->index << " " << this->x << " " << this->y << std::endl; } };
a68234bb60aad8a7b70d530d2ef220ee7092186b
013caff69e41c36c4efe9359c8ce2ecfb5f659ab
/Handshaking.cpp
8086ff71432fe3e8b6e2b2e5bd9ef50ca3cef40f
[]
no_license
iamsile/ACM
cbe5754bed56b1abb3cfaed6b25b9bffa1ec04a5
d51e43780e33b51c70007ba0702448909f9d0553
refs/heads/master
2016-08-04T02:31:51.523885
2013-09-09T05:36:35
2013-09-09T05:36:35
12,693,702
9
5
null
null
null
null
UTF-8
C++
false
false
2,012
cpp
Handshaking.cpp
#include <iostream> using namespace std; int main() { int n; while (scanf("%d",&n)!=EOF) { cout << n << '\n'; } return 0; } /* Problem description In our daily human communication, greetings between each other are primarily necessary. The differences between cultures and customs cause the differences between the courtesies in greeting, which colors the customs in greeting, such as nodding, bowing, hands-folding, hugging and handshaking, and among these, handshaking is regarded as a universal language in greetings. What shall we notice while shaking hands with others, since it is a regular courtesy in our social life? The most important point is that we should pay attention to the orders. Who should hand first while shaking hands? The seniors, the ladies and the teachers should give hands to the juniors, the men and the students. If two couples meet with each other, ladies greet each other first, then the husbands greet other's wives, and the greetings between men comes last. While the guests pay a visit, generally, the hosts hand first; and while saying goodbye, the guests hand first, meaning 'don't bother to see me out'. Based on what has been described above, there is a tough task left to you to complete: One day, the Lee’s invite N couples to dinner. Before the dinner they will shake hands with each other. The handshaking rules are: the couple does not shake hands with each other and at most one handshaking happens between two people. During the dinner, Mr. Lee asks the other people how many handshaking they took. And all the answers are different. Do you know how many times Mrs. Lee shakes hand with the others? Input There will be several test cases. The input of each test case is only one line with one integer N(0 < n < 100), which is the number of couples the Lee’s has invited. Output For each test case, you only need to output how many times Mrs. Lee will shake hands with the others. Sample Input 2 Sample Output 2 */
91470a975ad404d32ac4b4b3c24b644819d78c52
40b85924238752137a60c3c434e803f461479598
/Laboratories/Exams | Exercises/Starsze egzaminy/Egzaminya/Egzamin 2010_2/zad4.cpp
af11ea4544c0186a2472e10cf1acfe63ce770a27
[]
no_license
L0GI0/CPP
4ec3cb557c0d1d24a2be8dfcee526378bc0faace
063d8c177485745c28231665e895e1b2ca6360b8
refs/heads/master
2020-05-03T09:32:26.443048
2019-04-27T19:04:54
2019-04-27T19:04:54
178,556,663
0
0
null
null
null
null
WINDOWS-1250
C++
false
false
1,253
cpp
zad4.cpp
#include <iostream> #include <vector> using namespace std; struct Object{ virtual string print() const=0; }; struct ConsoleObject : public Object{ string print()const{ return "Console Object"; } }; struct ConsoleLine : public ConsoleObject{ string print()const{ return "Console Line"; } }; struct ConsoleText : public ConsoleObject{ string print()const{ return "Console Text"; } }; struct GuiObject : public Object{ string print()const{ return "Gui Object"; } }; struct GuiLine : public GuiObject{ string print()const{ return "Gui Line"; } }; struct GuiText : public GuiObject{ string print()const{ return "Gui Text"; } }; /*UZUPEŁNIĆ*/ int main() { std::vector<Object*> objs; ConsoleObject* console0=new ConsoleLine(); ConsoleObject* console1=new ConsoleText(); GuiObject* gui0=new GuiLine(); GuiObject* gui1=new GuiText(); objs.push_back(console0); objs.push_back(console1); objs.push_back(gui0); objs.push_back(gui1); for(unsigned i=0; i !=objs.size();i++) cout<<objs[i]->print()<<","; } //wynik działania: //Console Line,Console Text,Gui Line,Gui Text,
d3571c3936588659433d544849269046f31711e0
af4be14586b3df9a95bc0e942f8cc196e8d49e75
/deferred/src/gl_holder.h
110ce0f7028e8b8836e5bdb950e7c81430719f65
[ "MIT" ]
permissive
kravtsun/au-cg
f567b1ecee404779a01d8e8dff2b4e2c6f483a62
8f06e35b0f2aef4f61d58251efbbc5d759038089
refs/heads/master
2022-02-16T15:00:54.592453
2018-03-05T15:17:05
2018-03-05T15:17:05
104,670,722
0
0
MIT
2018-02-25T16:31:53
2017-09-24T19:32:23
C++
UTF-8
C++
false
false
712
h
gl_holder.h
#ifndef DEFERRED_GL_LOADER_H #define DEFERRED_GL_LOADER_H #include <GL/glew.h> #include <glfw_window_manager.h> #include <memory> class GLHolder { public: explicit GLHolder(std::shared_ptr<GLFWWindowManager> window_manager); virtual void paint(); virtual ~GLHolder(); static constexpr int maxLightsCount = 10; int lightsCount = maxLightsCount; float screenGamma = 2.2; enum Mode { POSITION, NORMAL, DIFFUSE, AMBIENT, DEFERRED }; Mode mode = DEFERRED; private: std::shared_ptr<GLFWWindowManager> window_manager; void geometry_pass(); void light_pass(); }; #endif //DEFERRED_GL_LOADER_H
503f1875390c6bd740fa3820a6380ba07671ca55
e7b3e7fcc23ecfb17aaa382763c7cb97e7647c4e
/examples/vipreSliceViewerQt/QOSGWidget.cpp
fdb44394caa45fe92e276ca4551e48c573baf8bb
[]
no_license
sudodata/VIPRE
7938f3049bc15462f014883d556af377b808ca36
6cc8b1fc613ba845a890e60a6061a038febd23c8
refs/heads/master
2022-12-02T13:11:51.106935
2020-07-07T03:05:42
2020-07-07T03:05:42
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,851
cpp
QOSGWidget.cpp
// // QOSGWidget.cpp // vipreSliceViewerQt // // Created by Christian Noon on 12/6/11. // Copyright (c) 2011 Christian Noon. All rights reserved. // #include "QOSGWidget.hpp" #include <osgGA/TrackballManipulator> #include <osgQt/GraphicsWindowQt> #include <osgViewer/ViewerEventHandlers> #include <QtGui/QHBoxLayout> QOSGWidget::QOSGWidget() { // Set up the graphics context traits osg::DisplaySettings* ds = osg::DisplaySettings::instance().get(); osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits(); traits->windowName = ""; traits->windowDecoration = false; traits->x = 0; traits->y = 0; traits->width = 800; traits->height = 600; traits->doubleBuffer = true; traits->alpha = ds->getMinimumNumAlphaBits(); traits->stencil = ds->getMinimumNumStencilBits(); traits->sampleBuffers = ds->getMultiSamples(); traits->samples = ds->getNumMultiSamples(); // Set up the camera osgQt::GraphicsWindowQt* gw = new osgQt::GraphicsWindowQt(traits.get()); getCamera()->setGraphicsContext(gw); getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); // Add the GL widget to this osg widget QHBoxLayout* layout = new QHBoxLayout(); layout->addWidget(gw->getGLWidget()); layout->setSpacing(0); setLayout(layout); // Set up the osgViewer::Viewer setThreadingModel(osgViewer::Viewer::SingleThreaded); addEventHandler(new osgViewer::StatsHandler); setCameraManipulator(new osgGA::TrackballManipulator); // Connect the timer to the update call which will indirectly call the paintEvent() method connect(&_timer, SIGNAL(timeout()), this, SLOT(update())); _timer.start(10); } QOSGWidget::~QOSGWidget() { ; } void QOSGWidget::paintEvent(QPaintEvent* event) { frame(); }
979fd30eca43246db399fa2f337af4c52e2e999a
a57381ce6d2bf6cc057da8bad00bfb36944cbb85
/arrays&strings/1.9_stringrotation/main.cpp
0d4cc0422d27ed347c460b6da3d668967b15bdf1
[]
no_license
andreaziani/CCIP
eb355197baa2edf91ced59ee60020f32177c3cd3
74f8eae49b30f63eb8ebb9bd4168530ccec618a8
refs/heads/master
2020-07-02T18:16:48.109071
2019-08-29T15:17:07
2019-08-29T15:17:07
201,618,912
0
0
null
null
null
null
UTF-8
C++
false
false
1,201
cpp
main.cpp
#include <iostream> #include <stdlib.h> using namespace std; // assume that isSubstring is a method that tells you if s2 is substring of s1 bool isSubstring(string s1, string s2){ return true; } bool isRotation(string s1, string s2){ if(s1.size() != s2.size()) return false; int rot = -1; for(int i = s2.size(); i >= 0; i--){ // find where rotation starts if(s2.at(i) == s1.at(0)){ rot = i; break; } } if(rot == -1) return false; //if no rotation point found for(int i = rot + 1; i < s2.size(); i++){ // if all the chars after the rotation point are equals to the beginning if(s2.at(i) != s1.at(i - rot)) return false; } return isSubstring(s1, s2.substr(0, rot)); //if the part before rot point is a substring of s1, s2 is a rotation of s1 } /*This is an elegant way. Concat s1 with s1, if s2 is a rotation it has to be a substring of the new s1+s1*/ bool isRotation_best(string s1, string s2){ if(s1.size() == s2.size() && s1.size()>0){ string s1s1 = s1 + s1; return isSubstring(s1s1, s2); } return false; } int main(){ string s1, s2; cout << isRotation_best(s1, s2); }
82b6f84443415fc3d37c9169b5e3724bc2302479
5fdaaed14ef92b2602a0e7aa61efde9f17b5c669
/Classes/Pokemon2/Pokemon.cpp
6a06b3922ad91165203df827cb170fafa05c1193
[ "MIT" ]
permissive
ARuiz93/lectures
5d609faa60f3df535bfcac4e8cb7a9e9d5677262
ee1e24d5e1a6141970ca06d43ac5611de7fc2a7a
refs/heads/master
2020-02-26T15:31:17.468460
2015-11-13T01:55:04
2015-11-13T01:55:04
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,628
cpp
Pokemon.cpp
#include <iostream> #include <string> #include "Pokemon.h" using namespace std; // Implement the constructors. // Constructors do not have a return type; simply scope them. // We'll start with the full-parameter destructor. Pokemon::Pokemon(const string &name, int number, int hitPoints, int attack, int defense) : mName(name), mNumber(number), mHitPoints(hitPoints), mAttackPower(attack), mDefense(defense) { // This is called an initializer list. Its job is to initialize each member // variable with a value. // This is technically the same as doing // mName = name; // mNumber = number; etc // as you would in Java. It's more efficient, but you don't need to know // the intimate details. } // The default constructor should initialize the member variables to some // appropriate default values. Pokemon::Pokemon() // Instead of repeating an initializer list, we can "call" the other // constructor and give it "default" values. : Pokemon("", 0, 0, 0, 0) { } Pokemon::Pokemon(const string &name) : Pokemon(name, 0, 0, 0, 0) { } // Implementation of accessor functions. const string &Pokemon::GetName() { return mName; } int Pokemon::GetHitPoints() { return mHitPoints; } int Pokemon::GetNumber() { return mNumber; } // Implementation of mutator functions. void Pokemon::SetName(const string &name) { mName = name; } void Pokemon::SetHitPoints(int hitPoints) { if (hitPoints >= 0) mHitPoints = hitPoints; } void Pokemon::Speak() { string phrase = mName.substr(0, (mName.size() + 1) / 2); cout << phrase << ", " << phrase << "!" << endl; }
ff64ab74a066a226da9c7635d9057e9f6ed67015
7ceb36402b9a39ed1a34ce9942e75946bb66ee3b
/src/PengaturanPerangkat/HTMLForm/HTMLForm.cpp
dedebeecfbae6e193a527d43bf10b6cac0e28233
[ "MIT" ]
permissive
firmanadiwicaksono/SmartPlug-Dev
a5345752bea45f30050270779c7dc28bd6d890a9
981c122dd9298b805c5a9a6cf5eb8114744ef49e
refs/heads/master
2021-02-08T18:07:41.589385
2020-08-07T08:53:21
2020-08-07T08:53:21
244,181,915
1
1
null
null
null
null
UTF-8
C++
false
false
37,385
cpp
HTMLForm.cpp
#include "HTMLForm.h" #include <Arduino.h> //Public String HTMLForm::login(String target, String message){ /* Spesifikasi : - Fungsi ini digunakan untuk membuat kode HTML halaman login. - Keluaran dari fungsi ini berupa objek kelas String. */ String html = ""; html += "<html>"; html += "<head>"; html += "<meta charset=\"utf-8\">"; html += "<title>Login</title>"; html += "<style>a{ color: #0000FF; text-decoration: underline;}a:visited{ color: #800080;}a:active{ color: #FF0000;}a:hover{ color: #0000FF; text-decoration: underline;}input:focus, textarea:focus, select:focus{ outline: none;}.visibility-hidden{ visibility: hidden;}h1, .h1{ font-family: Arial; font-weight: bold; font-size: 32px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h2, .h2{ font-family: Arial; font-weight: bold; font-size: 27px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h3, .h3{ font-family: Arial; font-weight: bold; font-size: 24px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h4, .h4{ font-family: Arial; font-weight: bold; font-size: 21px; font-style: italic; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h5, .h5{ font-family: Arial; font-weight: bold; font-size: 19px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h6, .h6{ font-family: Arial; font-weight: bold; font-size: 16px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}.CustomStyle{ font-family: \"Courier New\"; font-weight: bold; font-size: 16px; text-decoration: none; color: #2E74B5; background-color: transparent;}div#container{ width: 363px; position: relative; margin: 0 auto 0 auto; text-align: left;}body{ background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 1.1875; margin: 0; text-align: center;}#wb_Form1{ background-color: #FBFBFB; background-image: none; border: 0px solid #CCCCCC;}#Label1{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox1{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox1:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label2{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox2{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox2:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Button1{ border: 1px solid #2E6DA4; border-radius: 4px; background-color: #3370B7; background-image: none; color: #FFFFFF; font-family: Arial; font-weight: normal; font-size: 13px; -webkit-appearance: none; margin: 0;}</style>"; html += "</head>"; html += "<body>"; html += "<div id=\"container\">"; html += "<div style=\"position:absolute;left:30px;top:0px;width:302px;height:122px;z-index:5;\">"; html += "<form method=\"post\" action=\""; html += target; html += "\">"; html += "<label for=\"Editbox1\" id=\"Label1\" style=\"position:absolute;left:10px;top:15px;width:70px;height:26px;line-height:26px;z-index:0;\">Username :</label>"; html += "<input type=\"text\" id=\"Editbox1\" style=\"position:absolute;left:88px;top:14px;width:190px;height:26px;z-index:1;\" name=\"username\" value=\"\" maxlength=\"32\" spellcheck=\"false\">"; html += "<label for=\"Editbox2\" id=\"Label2\" style=\"position:absolute;left:10px;top:46px;width:70px;height:26px;line-height:26px;z-index:2;\">Password :</label>"; html += "<input type=\"password\" id=\"Editbox2\" style=\"position:absolute;left:88px;top:45px;width:190px;height:26px;z-index:3;\" name=\"password\" value=\"\" maxlength=\"32\" spellcheck=\"false\">"; html += "<input type=\"submit\" id=\"Button1\" name=\"\" value=\"Login\" style=\"position:absolute;left:103px;top:82px;width:96px;height:25px;z-index:4;\">"; html += "</form>"; html += "</div>"; html += "</div>"; if(message != ""){ html += "<script type=\"text/javascript\">alert(\""; html += message; html += "\");</script>"; } html += "</body>"; html += "</html>"; return html; } String HTMLForm::pengaturanKoneksi(String target, String message, String link_pengaturan_koneksi, String link_pengaturan_pengguna, String link_informasi_firmware, String link_logout, String wifi_ssid, String wifi_password, String mqtt_broker, String mqtt_username, String mqtt_password){ /* Spesifikasi : - Fungsi ini digunakan untuk membuat kode HTML halaman pengaturan koneksi. - Keluaran dari fungsi ini berupa objek kelas String. */ String html = ""; html += "<html>"; html += "<head>"; html += "<meta charset=\"utf-8\">"; html += "<title>Home Automation</title>"; html += "<style>a{ color: #0000FF; text-decoration: underline;}a:visited{ color: #800080;}a:active{ color: #FF0000;}a:hover{ color: #0000FF; text-decoration: underline;}input:focus, textarea:focus, select:focus{ outline: none;}.visibility-hidden{ visibility: hidden;}h1, .h1{ font-family: Arial; font-weight: bold; font-size: 32px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h2, .h2{ font-family: Arial; font-weight: bold; font-size: 27px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h3, .h3{ font-family: Arial; font-weight: bold; font-size: 24px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h4, .h4{ font-family: Arial; font-weight: bold; font-size: 21px; font-style: italic; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h5, .h5{ font-family: Arial; font-weight: bold; font-size: 19px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h6, .h6{ font-family: Arial; font-weight: bold; font-size: 16px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}.CustomStyle{ font-family: \"Courier New\"; font-weight: bold; font-size: 16px; text-decoration: none; color: #2E74B5; background-color: transparent;}div#container{ width: 560px; position: relative; margin: 0 auto 0 auto; text-align: left;}body{ background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 1.1875; margin: 0; text-align: center;}#menu{ text-align: left; float: left; margin: 0; width: 100%; font-family: Arial; font-weight: normal; font-size: 13px; list-style-type: none; padding: 15px 0px 4px 10px; overflow: hidden;}#menu li{ float: left;}#menu li a.active, #menu li a:hover.active{ position: relative; font-weight: normal; text-decoration: none; z-index: 2;}#menu li a{ padding: 5px 14px 8px 14px; margin-right: 3px; text-decoration: none; border-bottom: none; position: relative; top: 0; -webkit-transition: 200ms all linear; -moz-transition: 200ms all linear; transition: 200ms all linear;}#menu li a:hover{ font-weight: normal; text-decoration: none; top: -4px;}#menu{ border-bottom: 1px solid #C0C0C0;}#menu li a.active, #menu li a:hover.active{ background-color: #FFFFFF; color: #666666;}#menu li a{ border: 1px solid #C0C0C0; border-top-left-radius: 5px; border-top-right-radius: 5px; background-color: #EEEEEE; color: #666666;}#menu li a:hover{ background: #C0C0C0; color: #666666;}#wb_Form1{ background-color: #FBFBFB; background-image: none; border: 0px solid #CCCCCC;}#Label1{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox1{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox1:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label2{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox2{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox2:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Button1{ border: 1px solid #2E6DA4; border-radius: 4px; background-color: #3370B7; background-image: none; color: #FFFFFF; font-family: Arial; font-weight: normal; font-size: 13px; -webkit-appearance: none; margin: 0;}#Editbox3{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox3:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label3{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Label4{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox4{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox4:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label5{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox5{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox5:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}</style>"; html += "</head>"; html += "<body>"; html += "<div id=\"container\">"; html += "<div id=\"wb_menu\" style=\"position:absolute;left:8px;top:0px;width:540px;height:34px;z-index:11;overflow:hidden;\">"; html += "<ul id=\"menu\">"; html += "<li><a href=\""; html += link_pengaturan_koneksi; html += "\" title=\"Home Automation\" class=\"active\">Pengaturan Koneksi</a></li>"; html += "<li><a href=\""; html += link_pengaturan_pengguna; html += "\" title=\"Home Automation\">Pengaturan Pengguna</a></li>"; html += "<li><a href=\""; html += link_informasi_firmware; html += "\" title=\"Home Automation\">Informasi Firmware</a></li>"; html += "<li><a href=\""; html += link_logout; html += "\">Logout</a></li>"; html += "</ul>"; html += "</div>"; html += "<div id=\"wb_Form1\" style=\"position:absolute;left:8px;top:36px;width:540px;height:215px;z-index:12;\">"; html += "<form method=\"post\" action=\""; html += target; html += "\" id=\"Form1\">"; html += "<label for=\"Label1\" id=\"Label1\" style=\"position:absolute;left:10px;top:15px;width:102px;height:26px;line-height:26px;z-index:0;\">Wi-Fi SSID</label>"; html += "<input type=\"text\" id=\"Editbox1\" style=\"position:absolute;left:130px;top:14px;width:400px;height:26px;z-index:4;\" name=\"wifi_ssid\" value=\""; html += wifi_ssid; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<label for=\"Label2\" id=\"Label2\" style=\"position:absolute;left:10px;top:46px;width:112px;height:26px;line-height:26px;z-index:1;\">Wi-Fi Password</label>"; html += "<input type=\"password\" id=\"Editbox2\" style=\"position:absolute;left:130px;top:45px;width:400px;height:26px;z-index:2;\" name=\"wifi_password\" value=\""; html += wifi_password; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<label for=\"Label3\" id=\"Label3\" style=\"position:absolute;left:10px;top:77px;width:112px;height:26px;line-height:26px;z-index:5;\">MQTT Broker</label>"; html += "<input type=\"text\" id=\"Editbox3\" style=\"position:absolute;left:130px;top:76px;width:400px;height:26px;z-index:6;\" name=\"mqtt_broker\" value=\""; html+= mqtt_broker; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<label for=\"Label4\" id=\"Label4\" style=\"position:absolute;left:10px;top:108px;width:112px;height:26px;line-height:26px;z-index:7;\">MQTT Username</label>"; html += "<input type=\"text\" id=\"Editbox4\" style=\"position:absolute;left:130px;top:107px;width:400px;height:26px;z-index:8;\" name=\"mqtt_username\" value=\""; html += mqtt_username; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<label for=\"Label5\" id=\"Label5\" style=\"position:absolute;left:10px;top:139px;width:112px;height:26px;line-height:26px;z-index:9;\">MQTT Password</label>"; html += "<input type=\"password\" id=\"Editbox5\" style=\"position:absolute;left:130px;top:138px;width:400px;height:26px;z-index:10;\" name=\"mqtt_password\" value=\""; html += mqtt_password; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<input type=\"submit\" id=\"Button1\" name=\"\" value=\"Simpan\" style=\"position:absolute;left:142px;top:175px;width:96px;height:25px;z-index:3;\">"; html += "</form>"; html += "</div>"; html += "</div>"; if(message != ""){ html += "<script type=\"text/javascript\">alert(\""; html += message; html += "\");</script>"; } html += "</body>"; html += "</html>"; return html; } String HTMLForm::pengaturanPengguna(String target, String message, String link_pengaturan_koneksi, String link_pengaturan_pengguna, String link_informasi_firmware, String link_logout, String username, String password, String konfirmasi_password){ /* Spesifikasi : - Fungsi ini digunakan untuk membuat kode HTML halaman pengaturan pengguna. - Keluaran dari fungsi ini berupa objek kelas String. */ String html = ""; html += "<html>"; html += "<head>"; html += "<meta charset=\"utf-8\">"; html += "<title>Home Automation</title>"; html += "<style>a{ color: #0000FF; text-decoration: underline;}a:visited{ color: #800080;}a:active{ color: #FF0000;}a:hover{ color: #0000FF; text-decoration: underline;}input:focus, textarea:focus, select:focus{ outline: none;}.visibility-hidden{ visibility: hidden;}h1, .h1{ font-family: Arial; font-weight: bold; font-size: 32px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h2, .h2{ font-family: Arial; font-weight: bold; font-size: 27px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h3, .h3{ font-family: Arial; font-weight: bold; font-size: 24px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h4, .h4{ font-family: Arial; font-weight: bold; font-size: 21px; font-style: italic; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h5, .h5{ font-family: Arial; font-weight: bold; font-size: 19px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h6, .h6{ font-family: Arial; font-weight: bold; font-size: 16px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}.CustomStyle{ font-family: \"Courier New\"; font-weight: bold; font-size: 16px; text-decoration: none; color: #2E74B5; background-color: transparent;}div#container{ width: 560px; position: relative; margin: 0 auto 0 auto; text-align: left;}body{ background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 1.1875; margin: 0; text-align: center;}#menu{ text-align: left; float: left; margin: 0; width: 100%; font-family: Arial; font-weight: normal; font-size: 13px; list-style-type: none; padding: 15px 0px 4px 10px; overflow: hidden;}#menu li{ float: left;}#menu li a.active, #menu li a:hover.active{ position: relative; font-weight: normal; text-decoration: none; z-index: 2;}#menu li a{ padding: 5px 14px 8px 14px; margin-right: 3px; text-decoration: none; border-bottom: none; position: relative; top: 0; -webkit-transition: 200ms all linear; -moz-transition: 200ms all linear; transition: 200ms all linear;}#menu li a:hover{ font-weight: normal; text-decoration: none; top: -4px;}#menu{ border-bottom: 1px solid #C0C0C0;}#menu li a.active, #menu li a:hover.active{ background-color: #FFFFFF; color: #666666;}#menu li a{ border: 1px solid #C0C0C0; border-top-left-radius: 5px; border-top-right-radius: 5px; background-color: #EEEEEE; color: #666666;}#menu li a:hover{ background: #C0C0C0; color: #666666;}#wb_Form1{ background-color: #FBFBFB; background-image: none; border: 0px solid #CCCCCC;}#Label1{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox1{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox1:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label2{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox2{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox2:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Button1{ border: 1px solid #2E6DA4; border-radius: 4px; background-color: #3370B7; background-image: none; color: #FFFFFF; font-family: Arial; font-weight: normal; font-size: 13px; -webkit-appearance: none; margin: 0;}#Editbox3{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox3:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label3{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}</style>"; html += "</head>"; html += "<body>"; html += "<div id=\"container\">"; html += "<div id=\"wb_menu\" style=\"position:absolute;left:8px;top:0px;width:540px;height:34px;z-index:7;overflow:hidden;\">"; html += "<ul id=\"menu\">"; html += "<li><a href=\""; html += link_pengaturan_koneksi; html += "\" title=\"Home Automation\">Pengaturan Koneksi</a></li>"; html += "<li><a href=\""; html += link_pengaturan_pengguna; html += "\" title=\"Home Automation\" class=\"active\">Pengaturan Pengguna</a></li>"; html += "<li><a href=\""; html += link_informasi_firmware; html += "\" title=\"Home Automation\">Informasi Firmware</a></li>"; html += "<li><a href=\""; html += link_logout; html += "\">Logout</a></li>"; html += "</ul>"; html += "</div>"; html += "<div id=\"wb_Form1\" style=\"position:absolute;left:8px;top:36px;width:540px;height:154px;z-index:8;\">"; html += "<form method=\"post\" action=\""; html += target; html += "\" id=\"Form1\">"; html += "<label for=\"Label1\" id=\"Label1\" style=\"position:absolute;left:10px;top:15px;width:102px;height:26px;line-height:26px;z-index:0;\">Username</label>"; html += "<input type=\"text\" id=\"Editbox1\" style=\"position:absolute;left:150px;top:14px;width:380px;height:26px;z-index:4;\" name=\"username\" value=\""; html += username; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<label for=\"Label2\" id=\"Label2\" style=\"position:absolute;left:10px;top:46px;width:112px;height:26px;line-height:26px;z-index:1;\">Password</label>"; html += "<input type=\"password\" id=\"Editbox2\" style=\"position:absolute;left:150px;top:45px;width:380px;height:26px;z-index:2;\" name=\"password\" value=\""; html += password; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<label for=\"Label3\" id=\"Label3\" style=\"position:absolute;left:10px;top:77px;width:124px;height:26px;line-height:26px;z-index:5;\">Konfirmasi Password</label>"; html += "<input type=\"password\" id=\"Editbox3\" style=\"position:absolute;left:150px;top:76px;width:380px;height:26px;z-index:6;\" name=\"konfirmasi_password\" value=\""; html += konfirmasi_password; html += "\" maxlength=\"32\" spellcheck=\"false\">"; html += "<input type=\"submit\" id=\"Button1\" name=\"\" value=\"Simpan\" style=\"position:absolute;left:150px;top:117px;width:96px;height:25px;z-index:3;\">"; html += "</form>"; html += "</div>"; html += "</div>"; if(message != ""){ html += "<script type=\"text/javascript\">alert(\""; html += message; html += "\");</script>"; } html += "</body>"; html += "</html>"; return html; } String HTMLForm::informasiFirmware(FIRMWARE_IN informasi_firmware, String link_pengaturan_koneksi, String link_pengaturan_pengguna, String link_informasi_firmware, String link_logout){ /* Spesifikasi : - Fungsi ini digunakan untuk membuat kode HTML halaman informasi firmware. - Keluaran dari fungsi ini berupa objek kelas String. */ String html = ""; html += "<html>"; html += "<head>"; html += "<meta charset=\"utf-8\">"; html += "<title>Home Automation</title>"; html += "<style>a{ color: #0000FF; text-decoration: underline;}a:visited{ color: #800080;}a:active{ color: #FF0000;}a:hover{ color: #0000FF; text-decoration: underline;}input:focus, textarea:focus, select:focus{ outline: none;}.visibility-hidden{ visibility: hidden;}h1, .h1{ font-family: Arial; font-weight: bold; font-size: 32px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h2, .h2{ font-family: Arial; font-weight: bold; font-size: 27px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h3, .h3{ font-family: Arial; font-weight: bold; font-size: 24px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h4, .h4{ font-family: Arial; font-weight: bold; font-size: 21px; font-style: italic; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h5, .h5{ font-family: Arial; font-weight: bold; font-size: 19px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}h6, .h6{ font-family: Arial; font-weight: bold; font-size: 16px; text-decoration: none; color: #000000; background-color: transparent; margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; display: inline;}.CustomStyle{ font-family: \"Courier New\"; font-weight: bold; font-size: 16px; text-decoration: none; color: #2E74B5; background-color: transparent;}div#container{ width: 560px; position: relative; margin: 0 auto 0 auto; text-align: left;}body{ background-color: #FFFFFF; color: #000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 1.1875; margin: 0; text-align: center;}#menu{ text-align: left; float: left; margin: 0; width: 100%; font-family: Arial; font-weight: normal; font-size: 13px; list-style-type: none; padding: 15px 0px 4px 10px; overflow: hidden;}#menu li{ float: left;}#menu li a.active, #menu li a:hover.active{ position: relative; font-weight: normal; text-decoration: none; z-index: 2;}#menu li a{ padding: 5px 14px 8px 14px; margin-right: 3px; text-decoration: none; border-bottom: none; position: relative; top: 0; -webkit-transition: 200ms all linear; -moz-transition: 200ms all linear; transition: 200ms all linear;}#menu li a:hover{ font-weight: normal; text-decoration: none; top: -4px;}#menu{ border-bottom: 1px solid #C0C0C0;}#menu li a.active, #menu li a:hover.active{ background-color: #FFFFFF; color: #666666;}#menu li a{ border: 1px solid #C0C0C0; border-top-left-radius: 5px; border-top-right-radius: 5px; background-color: #EEEEEE; color: #666666;}#menu li a:hover{ background: #C0C0C0; color: #666666;}#wb_Form1{ background-color: #FBFBFB; background-image: none; border: 0px solid #CCCCCC;}#Label1{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox1{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox1:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label2{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Editbox2{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox2:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Button1{ border: 1px solid #2E6DA4; border-radius: 4px; background-color: #3370B7; background-image: none; color: #FFFFFF; font-family: Arial; font-weight: normal; font-size: 13px; -webkit-appearance: none; margin: 0;}#Editbox3{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox3:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Editbox4{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox4:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Editbox5{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox5:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Editbox6{ border: 1px solid #CCCCCC; border-radius: 4px; background-color: #FFFFFF; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; line-height: 16px; padding: 4px 4px 4px 4px; margin: 0; text-align: left;}#Editbox6:focus{ border-color: #66AFE9; box-shadow: inset 0px 1px 1px rgba(0,0,0,0.075), 0px 0px 8px rgba(102,175,233,0.60); outline: 0;}#Label3{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Label4{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Label5{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}#Label6{ border: 0px solid #CCCCCC; border-radius: 4px; background-color: transparent; background-image: none; color :#000000; font-family: Arial; font-weight: normal; font-size: 13px; padding: 4px 4px 4px 4px; margin: 0; text-align: left; vertical-align: top;}</style>"; html += "</head>"; html += "<body>"; html += "<div id=\"container\">"; html += "<div id=\"wb_menu\" style=\"position:absolute;left:8px;top:0px;width:540px;height:34px;z-index:7;overflow:hidden;\">"; html += "<ul id=\"menu\">"; html += "<li><a href=\""; html += link_pengaturan_koneksi; html += "\" title=\"Home Automation\">Pengaturan Koneksi</a></li>"; html += "<li><a href=\""; html += link_pengaturan_pengguna; html += "\" title=\"Home Automation\">Pengaturan Pengguna</a></li>"; html += "<li><a href=\""; html += link_informasi_firmware; html += "\" title=\"Home Automation\" class=\"active\">Informasi Firmware</a></li>"; html += "<li><a href=\""; html += link_logout; html += "\">Logout</a></li>"; html += "</ul>"; html += "</div>"; html += "<div id=\"wb_Form1\" style=\"position:absolute;left:8px;top:36px;width:540px;height:210px;z-index:8;\">"; html += "<label for=\"Label1\" id=\"Label1\" style=\"position:absolute;left:10px;top:15px;width:124px;height:26px;line-height:26px;z-index:0;\">Firmware Name</label>"; html += "<input type=\"text\" id=\"Editbox1\" style=\"position:absolute;left:150px;top:14px;width:380px;height:26px;z-index:4;\" value=\""; html += informasi_firmware.firmwareName; html += "\" spellcheck=\"false\" readonly>"; html += "<label for=\"Label2\" id=\"Label2\" style=\"position:absolute;left:10px;top:46px;width:124px;height:26px;line-height:26px;z-index:1;\">Firmware Description</label>"; html += "<input type=\"text\" id=\"Editbox2\" style=\"position:absolute;left:150px;top:45px;width:380px;height:26px;z-index:2;\" value=\""; html += informasi_firmware.firmwareDescription; html += "\" spellcheck=\"false\" readonly>"; html += "<label for=\"Label3\" id=\"Label3\" style=\"position:absolute;left:10px;top:77px;width:124px;height:26px;line-height:26px;z-index:5;\">Firmware Version</label>"; html += "<input type=\"text\" id=\"Editbox3\" style=\"position:absolute;left:150px;top:76px;width:380px;height:26px;z-index:6;\" value=\""; html += informasi_firmware.firmwareVersion; html += "\" spellcheck=\"false\" readonly>"; html += "<label for=\"Label4\" id=\"Label4\" style=\"position:absolute;left:10px;top:108px;width:124px;height:26px;line-height:26px;z-index:5;\">Legal Copyright</label>"; html += "<input type=\"text\" id=\"Editbox4\" style=\"position:absolute;left:150px;top:107px;width:380px;height:26px;z-index:6;\" value=\""; html += informasi_firmware.legalCopyright; html += "\" spellcheck=\"false\" readonly>"; html += "<label for=\"Label5\" id=\"Label5\" style=\"position:absolute;left:10px;top:139px;width:124px;height:26px;line-height:26px;z-index:5;\">Company Name</label>"; html += "<input type=\"text\" id=\"Editbox5\" style=\"position:absolute;left:150px;top:138px;width:380px;height:26px;z-index:6;\" value=\""; html += informasi_firmware.companyName; html += "\" spellcheck=\"false\" readonly>"; html += "<label for=\"Label6\" id=\"Label6\" style=\"position:absolute;left:10px;top:170px;width:124px;height:26px;line-height:26px;z-index:5;\">Firmware Type</label>"; html += "<input type=\"text\" id=\"Editbox6\" style=\"position:absolute;left:150px;top:169px;width:380px;height:26px;z-index:6;\" value=\""; html += informasi_firmware.firmwareType; html += "\" spellcheck=\"false\" readonly>"; html += "</div>"; html += "</div>"; html += "</body>"; html += "</html>"; return html; } String HTMLForm::getArg(HTML_FORM_ARG arg){ /* Spesifikasi : - Fungsi ini digunakan untuk mendapatkan arg pada Form HTML. - Keluaran dari fungsi ini berupa objek kelas String. */ return htmlFormArg[arg]; } //------------------------------------------------------------------------------
bcd08a363cc41539b04ac21e9fb7aac68bec797a
f81af68bd0d7c5584094b193467be7fd1f5ed36b
/iGP11.Core/codebuilder.h
7a1532da6143f10e376e543d64daa0aa0d01ec05
[]
no_license
S17L/iGP11
0cbc163bbe8156526572ad3d8deacb65765ba14f
b6fb41f097f651bedb88f78fabc6ea53e1d1bfd5
refs/heads/master
2020-03-26T05:27:28.251995
2018-08-13T10:13:25
2018-08-13T10:13:25
144,558,285
0
0
null
null
null
null
UTF-8
C++
false
false
12,581
h
codebuilder.h
#pragma once #include "stdafx.h" #include "igp11core.h" namespace core { namespace dto { struct Texel final { int x = 0; int y = 0; Texel() {} Texel(int x, int y) { this->x = x; this->y = y; } bool isEqual(const Texel &other) const { return x == other.x && y == other.y; } }; struct Pixel final { float x = 0; float y = 0; Pixel() {} Pixel(float x, float y) { this->x = x; this->y = y; } }; } static const unsigned int TexelCacheSize = 4; typedef unsigned int type_slot; typedef unsigned int type_tex_id; static const type_tex_id OutputTexId = 0; static type_tex_id _tex_id = 1; inline type_tex_id nextTexId() { return _tex_id++; } enum BokehDoFPassType { first = 0, second = 1, third = 2 }; class IElement { public: virtual ~IElement() {} virtual std::string translate() = 0; }; class DefineElement final : public IElement { private: std::string _name; std::string _value; public: DefineElement(const std::string &name, const std::string &value) : _name(name), _value(value) {} virtual ~DefineElement() {} virtual std::string translate() override; std::string getName() { return _name; } void setValue(const std::string &value) { _value = value; } }; class LineElement final : public IElement { private: std::string _line; public: LineElement(const std::string &line) : _line(line) {} virtual std::string translate() override { return _line; }; std::string getLine() { return _line; } void replace(const std::string &line) { _line = line; } }; class CodeVisitor final { private: std::list<std::shared_ptr<DefineElement>> _defines; std::list<std::shared_ptr<LineElement>> _lines; std::list<std::shared_ptr<IElement>> _elements; public: CodeVisitor(const std::string &code); void visitDefine(const std::string &name, const std::string &value); void visitLine(const std::string &startsWith, const std::string &line); std::string build(); }; class IAlterationElement { public: virtual ~IAlterationElement() {} virtual void accept(CodeVisitor &visitor) = 0; }; class DefineAlterationElement final : public IAlterationElement { private: std::string _name; std::string _value; public: DefineAlterationElement(const std::string &name, const std::string &value) : _name(name), _value(value) {} virtual ~DefineAlterationElement() {} virtual void accept(CodeVisitor &visitor) override { visitor.visitDefine(_name, _value); } }; class LineAlterationElement final : public IAlterationElement { private: std::string _startsWith; std::string _line; public: LineAlterationElement(const std::string &startsWith, const std::string &line) : _startsWith(startsWith), _line(line) {} virtual ~LineAlterationElement() {} virtual void accept(CodeVisitor &visitor) override { visitor.visitLine(_startsWith, _line); } }; class TexelCache final { friend class Pixel; friend class PixelArray; friend class PixelsResult; friend class Texel; private: core::Nullable<dto::Texel> _texels[TexelCacheSize] = {}; unsigned int _lastTexelIndex = -1; std::string _variableName; TexelCache(std::string variableName) : _variableName(variableName) {} unsigned int iterateTexelIndex(unsigned int index) { return index >= TexelCacheSize - 1 ? 0 : index + 1; } void setTexel(dto::Texel texel, unsigned int index) { if (index >= TexelCacheSize) { throw core::exception::OperationException(ENCRYPT_STRING("core::texelcache"), ENCRYPT_STRING("index is out of range")); } _lastTexelIndex = index; _texels[index].set(texel); } unsigned int indexOf(const dto::Texel &texel) { return core::linq::makeEnumerable(_texels, TexelCacheSize) .indexOf([&](const core::Nullable<dto::Texel> &item)->bool { return item.hasValue() && item->isEqual(texel); }); } unsigned int getNextTexelIndex(std::list<int> omit) { auto nextTexelIndex = iterateTexelIndex(_lastTexelIndex); auto omitEnumerable = core::linq::makeEnumerable(omit); for (auto i = 0; i < TexelCacheSize; i++) { if (omitEnumerable.contains([&](const int &index)->bool { return index == nextTexelIndex; })) { nextTexelIndex = iterateTexelIndex(nextTexelIndex); } else { return nextTexelIndex; } } return -1; } std::string toVariable(unsigned int index) { return core::stringFormat("%s_%u", _variableName.c_str(), index); } std::string toInitializeVariables(); }; class Texel final { friend class Pixel; friend class PixelArray; private: dto::Texel _texel; std::string _textureName; std::string _samplerName; std::string _texcoord; float _weight; public: Texel(dto::Texel texel, std::string textureName, std::string samplerName, std::string texcoord, float weight) : _texel(texel), _textureName(textureName), _samplerName(samplerName), _texcoord(texcoord), _weight(weight) {} bool isEqual(const Texel &other) const { return _texel.isEqual(other._texel); } std::string toInitializeVariable(std::string variableName); std::string toGetValue(std::string variableName); }; class Pixel final { private: std::shared_ptr<TexelCache> _texelCache; dto::Pixel _pixel; std::list<Texel> _texels; std::string toSetTextureCacheTexels(int map[TexelCacheSize]); public: Pixel(std::shared_ptr<TexelCache> texelCache, dto::Pixel pixel, Texel first) { _texelCache = texelCache; _pixel = pixel; _texels.push_back(first); } Pixel(std::shared_ptr<TexelCache> texelCache, dto::Pixel pixel, Texel first, Texel second) { _texelCache = texelCache; _pixel = pixel; _texels.push_back(first); _texels.push_back(second); } Pixel(std::shared_ptr<TexelCache> texelCache, dto::Pixel pixel, Texel first, Texel second, Texel third, Texel forth) { _texelCache = texelCache; _pixel = pixel; _texels.push_back(first); _texels.push_back(second); _texels.push_back(third); _texels.push_back(forth); } std::list<Texel> getTexels() const { return _texels; } float getX() { return _pixel.x; } float getY() { return _pixel.y; } std::string toGetValue(std::string &value); std::string toGetTexelVariables(std::list<std::string> &variableNames); }; class PixelsResult { friend class PixelArray; private: std::shared_ptr<TexelCache> _texelCache; public: std::list<Pixel> _pixels; std::list<Texel> _texels; std::string toInitializeTexelCache(); }; class PixelArray final { private: std::string _textureName; std::string _samplerName; std::string _texcoord; std::string _texelName; std::list<dto::Pixel> _pixels; std::list<dto::Texel> _texels; public: PixelArray(std::string textureName, std::string samplerName, std::string texcoord, std::string texelName) : _textureName(textureName), _samplerName(samplerName), _texcoord(texcoord), _texelName(texelName) {} void add(float x, float y); PixelsResult getPixels(); }; enum class TextureDataType { typefloat = 0 }; struct Texture final { type_tex_id id = nextTexId(); TextureDataType dataType; dto::Resolution resolution; Texture() {} Texture(TextureDataType dataType, dto::Resolution resolution) { this->dataType = dataType; this->resolution = resolution; } }; struct Pass { std::string vsFunctionName; std::string psFunctionName; std::list<type_tex_id> in; std::list<type_tex_id> out; Pass( std::string vsFunctionName, std::string psFunctionName) { this->vsFunctionName = vsFunctionName; this->psFunctionName = psFunctionName; } }; struct TechniqueCode final { std::string vsCode; std::string psCode; TechniqueCode() {} TechniqueCode(std::string vsCode, std::string psCode) { this->vsCode = vsCode; this->psCode = psCode; } }; struct Technique { std::string name; TechniqueCode code; type_slot color = 0; type_slot depth = 1; std::list<Pass> passes; std::map<type_slot, Texture> textures; Technique() {} Technique( std::string name, TechniqueCode code) { this->name = name; this->code = code; } }; class ConcreteHlslTechniqueBuilder final { private: IResourceProvider *_cachedResourceProvider; IResourceProvider *_realResourceProvider; std::list<std::shared_ptr<IAlterationElement>> _elements; std::string getResource(const std::string &key); public: ConcreteHlslTechniqueBuilder(IResourceProvider *cachedResourceProvider, IResourceProvider *realResourceProvider) : _cachedResourceProvider(cachedResourceProvider), _realResourceProvider(realResourceProvider) {} void add(IAlterationElement *element); std::string buildPixelShaderCode(); std::string buildVertexShaderCode(); }; class HlslTechniqueBuilder final { private: dto::Resolution _resolution; std::unique_ptr<IResourceProvider> _cachedResourceProvider; std::unique_ptr<IResourceProvider> _realResourceProvider; void applyBokehDoFPassType(ConcreteHlslTechniqueBuilder *builder, BokehDoFPassType pass, const dto::BokehDoF &bokehDoF); void applyDepthBuffer(ConcreteHlslTechniqueBuilder *builder, const dto::DepthBuffer &depthBuffer); std::unique_ptr<ConcreteHlslTechniqueBuilder> getConcreteShaderCodeBuilder(); public: HlslTechniqueBuilder(dto::Resolution resolution); HlslTechniqueBuilder(dto::Resolution resolution, std::string directoryPath); Technique buildAlpha(); Technique buildBokehDoF(dto::BokehDoF bokehDoF, dto::DepthBuffer depthBuffer); Technique buildDenoise(dto::Denoise denoise); Technique buildDepth(dto::DepthBuffer depthBuffer); Technique buildGaussianBlur(dto::GaussianBlur gaussianBlur); Technique buildHDR(dto::HDR hdr); Technique buildLiftGammaGain(dto::LiftGammaGain liftGammaGain); Technique buildLumaSharpen(dto::LumaSharpen); Technique buildLuminescence(); Technique buildTonemap(dto::Tonemap tonemap); Technique buildVibrance(dto::Vibrance vibrance); }; typedef std::function<Technique(const std::string &data)> TechniqueFactoryFunction; class HlslTechniqueFactory final { private: HlslTechniqueBuilder *_hlslTechniqueBuilder; core::ISerializer *_serializer; dto::DepthBuffer _depthBuffer; std::map<core::TechniqueType, TechniqueFactoryFunction> _policies; public: HlslTechniqueFactory( HlslTechniqueBuilder *hlslTechniqueBuilder, core::ISerializer *serializer, dto::DepthBuffer depthBuffer); virtual ~HlslTechniqueFactory() {} virtual Technique create(core::TechniqueType type, const std::string &data); }; }
44172c7af41542304eb909006c9212828603426f
627c7e0e26a353031a2a896b3be65271728bddf2
/Encubadora/Encubadora.ino
d915ec14985c4e342543bff68904fd1458882173
[]
no_license
SantiagoFonsecap/LaIncubadoraDeLosHuevosDelDrag-n
a4128fcbe1b4991d52d46227c0c1224fb88a2502
9ce4197619817160215a22485ce551667ff602df
refs/heads/main
2023-06-06T18:20:33.389317
2021-07-27T20:03:24
2021-07-27T20:03:24
390,111,810
0
0
null
null
null
null
UTF-8
C++
false
false
2,564
ino
Encubadora.ino
#include <Wire.h> //Para pantalla LED #include <LiquidCrystal_I2C.h> //PantallaLED #include <DHT.h> //Sensor Temp/Hum #include <DHT_U.h> #include <Servo.h> //Servo int sensor=3; int ventilador=6; int calor=5; int Buttom = 1; int PINSERVO = 7; // pin 7 conectado a señal del servo int PULSOMIN = 760; // pulso minimo en microsegundos int PULSOMAX = 2420; // pulso maximo en microsegundos int temperatura; int humedad; String first, second; int espera=0; int grados=90; LiquidCrystal_I2C lcd(0x27, 16, 2); DHT dht(sensor, DHT11); Servo servo1; void setup(){ servo1.attach(PINSERVO, PULSOMIN, PULSOMAX); lcd.begin(); lcd.backlight(); Serial.begin(9600); dht.begin(); pinMode(sensor, INPUT); pinMode(ventilador, OUTPUT); pinMode(Buttom, INPUT); } void loop() { if (digitalRead(Buttom)==HIGH){ //Modo de Incubación temperatura=dht.readTemperature(); humedad=dht.readHumidity(); first =(temperatura); second = (humedad); Serial.println(temperatura); while (temperatura<37.8){ temperatura=dht.readTemperature(); digitalWrite(ventilador,HIGH); digitalWrite(calor,HIGH); delay(5000); espera+=5000; digitalWrite(calor,LOW); } if (espera >= 3600000){ if (grados>0){ for(grados;grados>=0;grados-=3){ servo1.write(grados); delay(200); Serial.println(grados); } } else{ for(grados;grados<=180;grados+=3){ servo1.write(grados); delay(200); Serial.println(grados); } } espera=0; } lcd.clear(); lcd.print("Temperatura: "+ first); lcd.setCursor(0,1); lcd.print("Humedad: " + second); delay(1000); espera+=1000; digitalWrite(ventilador,LOW); } if (digitalRead(Buttom)==LOW){ //Modo de Eclosión servo1.write(90); temperatura=dht.readTemperature(); humedad=dht.readHumidity(); first =(temperatura); second = (humedad); Serial.println(temperatura); while (temperatura<36.5){ temperatura=dht.readTemperature(); digitalWrite(ventilador,HIGH); digitalWrite(calor,HIGH); delay(5000); digitalWrite(calor,LOW); } //No hay vueltas en este modo lcd.clear(); lcd.print("Temperatura: "+ first); lcd.setCursor(0,1); lcd.print("Humedad: " + second); delay(1000); espera+=1000; digitalWrite(ventilador,LOW); } }
61519eba30fd57e63dade39c197b2b4160bcec9e
91a2d88fe128699be57fd70896e2ba3ac5ab173a
/Searching & Sorting Applications/chefres.cpp
55f5c39aa720b5523c1ff0bc8f0a8444b4a976ff
[]
no_license
Shaleengovil25/Competitive-programming
98a9584aa340ecfa8e5d1efc7ab14407ada492ae
5d26f86142acc66cf64f02738242e5f7bce0e5db
refs/heads/master
2022-11-18T23:46:32.683706
2020-07-16T20:00:02
2020-07-16T20:00:02
263,993,641
1
0
null
null
null
null
UTF-8
C++
false
false
987
cpp
chefres.cpp
//Time O(query*log(intervals)) Auxilliary_Space O(1) #include <bits/stdc++.h> using namespace std; int main() { // your code goes here int t; cin >> t; while(t--){ int intervals,query; cin >> intervals >> query; vector< pair<int,int> > v; int l,r; for(int i=0;i<intervals;i++){ cin >> l >> r; v.push_back(make_pair(l,r)); } sort(v.begin(),v.end()); while(query--){ int q; cin >> q; int pos = lower_bound(v.begin(), v.end(), make_pair(q,0)) - v.begin(); if(pos == 0){ cout << v[pos].first - q << endl; } else{ if(v[pos-1].second > q){ cout << "0" << endl; } else if(pos < v.size()){ cout << v[pos].first - q << endl; } else{ cout << "-1" << endl; } } } } return 0; } https://www.codechef.com/problems/CHEFRES
180f63f1e1bc40a814987a2a984e427d2612a2b3
06c50a42fb4c8ee0aaf8b8ffb3681c14873db01a
/externals/SDL2/include/haptic/nintendoswitch/SDL_syshaptic.cpp
6fdf7e8a3be59902a11366ad15f3e7c34010689b
[ "Zlib" ]
permissive
Toadsword/PokEngine
4e42f88ec781c23421db159129642657ad7ce56f
bbf4d68cc2bf96c34cb16a6c19d3c5b849c4d811
refs/heads/master
2022-11-16T08:04:33.947034
2020-07-07T20:49:12
2020-07-07T20:49:12
277,910,114
0
0
null
null
null
null
UTF-8
C++
false
false
12,128
cpp
SDL_syshaptic.cpp
/* Simple DirectMedia Layer Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #include "../../SDL_internal.h" #ifdef SDL_HAPTIC_NINTENDO_SWITCH extern "C" { #include "SDL_timer.h" #include "../../thread/SDL_systhread.h" #include "SDL_haptic.h" #include "../SDL_syshaptic.h" #include "SDL_assert.h" } #include <nn/hid.h> #include <nn/hid/hid_Npad.h> #include <nn/hid/hid_NpadJoy.h> #include <nn/hid/hid_Vibration.h> struct haptic_hwdata { nn::hid::NpadIdType npad_id; nn::hid::VibrationDeviceHandle vibration_devices[2]; nn::hid::VibrationDevicePosition motor_position[2]; int num_vibration_devices; SDL_Thread *thread; SDL_mutex *mutex; Uint32 stopTicks; SDL_atomic_t stopThread; }; struct haptic_hweffect { int unused; }; /* I stole this thread idea from SDL's Xinput haptic code. */ /* !!! FIXME: do all the devices on one thread? */ static int SDLCALL NpadHapticThread(void *arg) { haptic_hwdata *hwdata = (haptic_hwdata *) arg; const nn::hid::VibrationValue stop_vibrating = nn::hid::VibrationValue::Make(); while (!SDL_AtomicGet(&hwdata->stopThread)) { SDL_Delay(50); SDL_LockMutex(hwdata->mutex); /* If we're currently running and need to stop... */ if (hwdata->stopTicks) { if ((hwdata->stopTicks != SDL_HAPTIC_INFINITY) && SDL_TICKS_PASSED(SDL_GetTicks(), hwdata->stopTicks)) { hwdata->stopTicks = 0; for (int i = 0; i < hwdata->num_vibration_devices; i++) { nn::hid::SendVibrationValue(hwdata->vibration_devices[i], stop_vibrating); } } } SDL_UnlockMutex(hwdata->mutex); } return 0; } int SDL_SYS_HapticInit(void) { return 0; } int SDL_SYS_NumHaptics(void) { return nn::hid::IsVibrationPermitted() ? SDL_NumJoysticks() : 0; } const char * SDL_SYS_HapticName(int index) { return SDL_JoystickNameForIndex(index); } static int NpadHapticOpen(SDL_Haptic * haptic, const nn::hid::NpadIdType &npad_id) { haptic->effects = NULL; if (!nn::hid::IsVibrationPermitted()) { return SDL_SetError("Vibration not permitted by system settings"); } /* Prepare effects memory. */ haptic_effect *effects = (haptic_effect *) SDL_calloc(1, sizeof (haptic_effect)); if (effects == NULL) { return SDL_OutOfMemory(); } /* Allocate the hwdata */ haptic_hwdata *hwdata = (haptic_hwdata *) SDL_calloc(1, sizeof (*haptic->hwdata)); if (hwdata == NULL) { SDL_free(effects); return SDL_OutOfMemory(); } haptic_hwdata &hw = *hwdata; const nn::hid::NpadStyleSet style = nn::hid::GetNpadStyleSet(npad_id); const int numdevs = nn::hid::GetVibrationDeviceHandles(hw.vibration_devices, SDL_arraysize(hw.vibration_devices), npad_id, style); if (numdevs <= 0) { SDL_free(hwdata); SDL_free(effects); return SDL_SetError("Couldn't get vibration handles for this device"); } hw.mutex = SDL_CreateMutex(); if (hw.mutex == NULL) { SDL_free(hwdata); SDL_free(effects); return SDL_SetError("Couldn't create Npad haptic mutex"); } for (int i = 0; i < numdevs; i++) { nn::hid::VibrationDeviceInfo info; nn::hid::InitializeVibrationDevice(hw.vibration_devices[i]); nn::hid::GetVibrationDeviceInfo(&info, hw.vibration_devices[i]); hw.motor_position[i] = info.position; } hw.npad_id = npad_id; hw.num_vibration_devices = numdevs; SDL_AtomicSet(&hw.stopThread, 0); haptic->hwdata = hwdata; haptic->effects = effects; haptic->supported = SDL_HAPTIC_LEFTRIGHT; haptic->neffects = 1; haptic->nplaying = 1; char threadName[32]; SDL_snprintf(threadName, sizeof(threadName), "SDLNpadHapticDev_0x%X", (unsigned int) npad_id); hw.thread = SDL_CreateThreadInternal(NpadHapticThread, threadName, 4 * 4096, haptic->hwdata); if (hw.thread == NULL) { SDL_DestroyMutex(hw.mutex); SDL_free(haptic->effects); SDL_free(haptic->hwdata); haptic->effects = NULL; haptic->hwdata = NULL; return SDL_SetError("Couldn't create Npad haptic thread"); } return 0; } int SDL_SYS_HapticOpen(SDL_Haptic * haptic) { Sint32 npad_id_int32; if (SDL_NintendoSwitch_JoystickNpadIdForIndex(haptic->index, &npad_id_int32) == -1) { return -1; } const nn::hid::NpadIdType npad_id = (const nn::hid::NpadIdType) npad_id_int32; return NpadHapticOpen(haptic, npad_id); } int SDL_SYS_HapticMouse(void) { return -1; /* no haptic mice on this platform. */ } int SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick) { if (!nn::hid::IsVibrationPermitted()) { return 0; } Sint32 npad_id_int32; if (SDL_NintendoSwitch_JoystickNpadId(joystick, &npad_id_int32) == -1) { return 0; } const nn::hid::NpadIdType npad_id = (const nn::hid::NpadIdType) npad_id_int32; const nn::hid::NpadStyleSet style = nn::hid::GetNpadStyleSet(npad_id); nn::hid::VibrationDeviceHandle vibration_devices[4]; return (nn::hid::GetVibrationDeviceHandles(vibration_devices, SDL_arraysize(vibration_devices), npad_id, style) > 0); } int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick) { Sint32 npad_id_int32; if (SDL_NintendoSwitch_JoystickNpadId(joystick, &npad_id_int32) == -1) { return -1; } const nn::hid::NpadIdType npad_id = (const nn::hid::NpadIdType) npad_id_int32; return NpadHapticOpen(haptic, npad_id); } int SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick) { Sint32 npad_id; if (SDL_NintendoSwitch_JoystickNpadId(joystick, &npad_id) == -1) { return 0; } return (haptic->hwdata->npad_id == ((nn::hid::NpadIdType) npad_id)) ? 1 : 0; } void SDL_SYS_HapticClose(SDL_Haptic * haptic) { SDL_AtomicSet(&haptic->hwdata->stopThread, 1); SDL_WaitThread(haptic->hwdata->thread, NULL); SDL_free(haptic->effects); haptic->effects = NULL; haptic->neffects = 0; SDL_DestroyMutex(haptic->hwdata->mutex); SDL_free(haptic->hwdata); haptic->hwdata = NULL; } void SDL_SYS_HapticQuit(void) { // no-op. // !!! FIXME: the higher level doesn't close open devices on subsystem // quit and we don't keep a list ourselves. This is a bug at the higher level. // make sure your app closes all devices manually until this is fixed! } int SDL_SYS_HapticNewEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * base) { SDL_assert(base->type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */ effect->hweffect = (haptic_hweffect *) SDL_calloc(1, sizeof (haptic_hweffect)); if (effect->hweffect == NULL) { SDL_OutOfMemory(); return -1; } const int result = SDL_SYS_HapticUpdateEffect(haptic, effect, base); if (result < 0) { SDL_free(effect->hweffect); effect->hweffect = NULL; } return result; } static void NpadDoVibration(const SDL_Haptic *haptic, const SDL_HapticLeftRight &leftright) { /* XInput docs (what SDL_HapticLeftRight is trying to mimic) say this: "The left motor is the low-frequency rumble motor. The right motor is the high-frequency rumble motor. The two motors are not the same, and they create different vibration effects." So I take this to mean if you have a left/right motor pair available on your Npad, give the one on the left with a non-zero amplitudeLow, and the one on the right a non-zero amplitudeHigh, and use the default low/high frequencies for both. If you only have one, we can either try setting both amplitudes, or maybe just average them? I'm not sure. */ /* SDL_HapticEffect has max magnitude of 32767, so clamp and normalize */ const float small = (float) SDL_min(leftright.small_magnitude, 32767); const float large = (float) SDL_min(leftright.large_magnitude, 32767); const float nnleft = small / 32767.0f; const float nnright = large / 32767.0f; haptic_hwdata &hw = *haptic->hwdata; const nn::hid::VibrationValue vval = nn::hid::VibrationValue::Make(nnleft, nn::hid::VibrationFrequencyLowDefault, nnright, nn::hid::VibrationFrequencyHighDefault); for (int i = 0; i < hw.num_vibration_devices; i++) { nn::hid::SendVibrationValue(hw.vibration_devices[i], vval); } } int SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic, struct haptic_effect *effect, SDL_HapticEffect * data) { SDL_assert(data->type == SDL_HAPTIC_LEFTRIGHT); SDL_LockMutex(haptic->hwdata->mutex); if (haptic->hwdata->stopTicks) { /* running right now? Update it. */ NpadDoVibration(haptic, data->leftright); } SDL_UnlockMutex(haptic->hwdata->mutex); return 0; } int SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect, Uint32 iterations) { SDL_assert(effect->effect.type == SDL_HAPTIC_LEFTRIGHT); /* should catch this at higher level */ SDL_LockMutex(haptic->hwdata->mutex); if (effect->effect.leftright.length == SDL_HAPTIC_INFINITY || iterations == SDL_HAPTIC_INFINITY) { haptic->hwdata->stopTicks = SDL_HAPTIC_INFINITY; } else if ((!effect->effect.leftright.length) || (!iterations)) { /* do nothing. Effect runs for zero milliseconds. */ } else { haptic->hwdata->stopTicks = SDL_GetTicks() + (effect->effect.leftright.length * iterations); if ((haptic->hwdata->stopTicks == SDL_HAPTIC_INFINITY) || (haptic->hwdata->stopTicks == 0)) { haptic->hwdata->stopTicks = 1; /* fix edge cases. */ } } SDL_UnlockMutex(haptic->hwdata->mutex); NpadDoVibration(haptic, effect->effect.leftright); return 0; } int SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect) { return SDL_SYS_HapticStopAll(haptic); } void SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect) { SDL_SYS_HapticStopEffect(haptic, effect); SDL_free(effect->hweffect); effect->hweffect = NULL; } int SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic, struct haptic_effect *effect) { return SDL_Unsupported(); } int SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain) { return SDL_Unsupported(); } int SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter) { return SDL_Unsupported(); } int SDL_SYS_HapticPause(SDL_Haptic * haptic) { return SDL_Unsupported(); } int SDL_SYS_HapticUnpause(SDL_Haptic * haptic) { return SDL_Unsupported(); } int SDL_SYS_HapticStopAll(SDL_Haptic * haptic) { SDL_LockMutex(haptic->hwdata->mutex); haptic->hwdata->stopTicks = 0; SDL_UnlockMutex(haptic->hwdata->mutex); const nn::hid::VibrationValue stop_vibrating = nn::hid::VibrationValue::Make(); for (int i = 0; i < haptic->hwdata->num_vibration_devices; i++) { nn::hid::SendVibrationValue(haptic->hwdata->vibration_devices[i], stop_vibrating); } return 0; } #endif /* SDL_HAPTIC_NINTENDO_SWITCH */ /* vi: set ts=4 sw=4 expandtab: */
ca5bae49238a1e15cee4fc9c56cabcfcf2d076b2
d9383228e881013d8757d58aa06cb9ed1c8644e7
/queue.cpp
78c9fe3c706b50d80ac936d20b30b2659db15019
[]
no_license
briancmpbll/data_structures
a8a45dd6bf18bb0a4319cd15158ab8aeb0bc1cb4
f3e6d9fc4461a2e21b9e6872993ac8ca09fa946b
refs/heads/master
2020-02-26T13:09:03.816585
2016-06-20T05:25:31
2016-06-20T05:25:31
60,498,346
0
0
null
null
null
null
UTF-8
C++
false
false
2,034
cpp
queue.cpp
#include <iostream> #include <vector> #include "common.h" using namespace std; template <class T> class Queue { public: Queue() : _size(0) {} int size() const { return _size; } void print() const { NodePtr<T> current = _head; while(current != nullptr) { cout << current->data << " "; current = current->next; } cout << endl; } void print_reverse() const { NodePtr<T> current = _tail; while (current != nullptr) { cout << current->data << " "; current = current->prev; } cout << endl; } int peek() const { if (_tail == nullptr) { throw string("No data."); } return _tail->data; } void enqueue(T data) { NodePtr<T> newNode(new LinkedListNode<T>(data)); if (_head != nullptr) { _head->prev = newNode; } newNode->next = _head; _head = newNode; ++_size; if (_size == 1) { _tail = newNode; } } void dequeue() { if (_tail == nullptr) { return; } _tail = _tail->prev; --_size; if (_tail != nullptr) { _tail->next = nullptr; } if (_size <= 1) { _head = _tail; } } protected: NodePtr<T> _head; NodePtr<T> _tail; int _size; }; int main(int argc, char **argv) { vector<int> numbers = {9, 5, 4, 10, 16, 8, 21, 46, 5}; Queue<int> queue; try { queue.peek(); } catch (const string &e) { cout << e << endl; } cout << "///// push" << endl; for (const int &x : numbers) { queue.enqueue(x); cout << queue.peek() << endl; queue.print(); queue.print_reverse(); } for (int i = 0; i < 3; ++i) { queue.dequeue(); cout << queue.peek() << std::endl; queue.print(); queue.print_reverse(); } for (const int &x : numbers) { queue.enqueue(x); cout << queue.peek() << endl; queue.print(); queue.print_reverse(); } while (queue.size() > 0) { cout << queue.peek() << std::endl; queue.dequeue(); queue.print(); queue.print_reverse(); } }
ca6dd9e0c7f52be4b4ac3854b59118532580b3e3
0262e23341de77f030aaafac50db37b1027d93ff
/JetpackArcher/draftJetpackArcher2/FontRasterizer.h
6500ffa25262a88c1e560df20b3b0b57234a6d1d
[]
no_license
RyanJeff/JetpackArcher
e172f59c1aa912246317ca54070547ab71b10214
0da54c1cb89477a106aa50a9b96a333c8e51c3a6
refs/heads/master
2021-01-02T08:09:29.723268
2014-10-10T20:48:50
2014-10-10T20:48:50
null
0
0
null
null
null
null
UTF-8
C++
false
false
809
h
FontRasterizer.h
#pragma once #include "BaseCamera.h" #include "Effect.h" #include "Vertex.h" class FontRasterizer { private: BaseCamera* m2DCam; XMFLOAT4X4 m2DProj; LitTexEffect* mEffect; int mNumRows; int mNumCols; ID3D11ShaderResourceView* mFontImage; ID3D11Buffer* VB; ID3D11Buffer* IB; void DrawCharacter(char c, float xPos, float yPos, float charWidth, float charHeight, Vertex::NormalTexVertex* v, int charCount); void InitVB(ID3D11Device* device); void InitIB(ID3D11Device* device); public: FontRasterizer(BaseCamera* cam, CXMMATRIX proj, LitTexEffect* effect, int numRows, int numCols, ID3D11ShaderResourceView* texture, ID3D11Device* device); ~FontRasterizer(); void DrawFont(ID3D11DeviceContext* context, FXMVECTOR pos, float fontWidth, float fontHeight, int charsPerLine, std::string text); };
19c67a379a4d4bae11e3d207142b48b479fe8540
6bb302f305fe429728976d119aa20fbdf8c62811
/includes/Nibbler.hh
f1c9bf1bb22a6c3a550eb4ab9d6925a75ddb5d92
[]
no_license
Aschen/Nibbler
2fe05fe495959e26dc163a8e80d4b52985699fb8
565fc4a079507e5d4b4926bb48bbe1e2f97f4b83
refs/heads/master
2021-01-01T06:45:38.385740
2016-02-23T09:11:18
2016-02-23T09:11:18
40,981,281
0
0
null
null
null
null
UTF-8
C++
false
false
957
hh
Nibbler.hh
#ifndef NIBBLER_HH #define NIBBLER_HH #include <string> #include <vector> #include <stdexcept> #include <sstream> #include <iostream> #include <algorithm> #include <unistd.h> #include <pthread.h> #include <signal.h> #define SBLOCK 40 typedef std::pair<unsigned int, unsigned int> Coord; typedef std::pair<Coord, Coord> Couple; typedef enum e_key { UP = 1, DOWN = -1, LEFT = 2, RIGHT = -2, SPACE = 3, QUIT = 4, OTHERS = 5 } Key; typedef enum e_object { WALL = 0, SNAKE, POWERUP, PORTAL, EMPTY } Object; typedef enum e_direct { MUP = 0, MDOWN, MLEFT, MRIGHT } Direction; typedef enum e_flag { EXIT = 0, MENU, PLAY } Flag; typedef enum e_portal { IN = 0, OUT } Way; std::ostream &operator<<(std::ostream &os, const Coord &coord); std::ostream &operator<<(std::ostream &os, Key key); #endif // NIBBLER_HH
b645c76eda60ae1b9fd565d89fceed2697715843
7579d827cb7b50b438dfd9ef6fa80ba2797848c9
/sources/plug_cef/include/luna/wrappers/wrapper_cef_CEFManager.h
23d0f6bdc8bb64bd29d7dc10f597460e5d021129
[]
no_license
roche-emmanuel/sgt
809d00b056e36b7799bbb438b8099e3036377377
ee3a550f6172c7d14179d9d171e0124306495e45
refs/heads/master
2021-05-01T12:51:39.983104
2014-09-08T03:35:15
2014-09-08T03:35:15
79,538,908
3
0
null
null
null
null
UTF-8
C++
false
false
2,271
h
wrapper_cef_CEFManager.h
#ifndef _WRAPPERS_WRAPPER_CEF_CEFMANAGER_H_ #define _WRAPPERS_WRAPPER_CEF_CEFMANAGER_H_ #include <plug_common.h> #include "lua/LuaObject.h" #include <CEFManager.h> class wrapper_cef_CEFManager : public cef::CEFManager, public luna_wrapper_base { public: ~wrapper_cef_CEFManager() { logDEBUG3("Calling delete function for wrapper cef_CEFManager"); if(_obj.pushFunction("delete")) { //_obj.pushArg((cef::CEFManager*)this); // No this argument or the object will be referenced again! _obj.callFunction<void>(); } }; wrapper_cef_CEFManager(lua_State* L, lua_Table* dum, const cef::CEFManager::Traits & traits) : cef::CEFManager(traits), luna_wrapper_base(L) { register_protected_methods(L); if(_obj.pushFunction("buildInstance")) { _obj.pushArg((cef::CEFManager*)this); _obj.callFunction<void>(); } }; // Private virtual methods: protected: // Protected virtual methods: // cef::CEFViewBase * cef::CEFManager::DoCreateView(const cef::CEFViewBase::Traits & traits) cef::CEFViewBase * DoCreateView(const cef::CEFViewBase::Traits & traits) { THROW_IF(!_obj.pushFunction("DoCreateView"),"No implementation for abstract function cef::CEFManager::DoCreateView"); _obj.pushArg((cef::CEFManager*)this); _obj.pushArg(&traits); return (_obj.callFunction<cef::CEFViewBase*>()); }; public: // Public virtual methods: // int cef::CEFManager::AddRef() int AddRef() { if(_obj.pushFunction("AddRef")) { _obj.pushArg((cef::CEFManager*)this); return (_obj.callFunction<int>()); } return CEFManager::AddRef(); }; // int cef::CEFManager::Release() int Release() { if(_obj.pushFunction("Release")) { _obj.pushArg((cef::CEFManager*)this); return (_obj.callFunction<int>()); } return CEFManager::Release(); }; // int cef::CEFManager::GetRefCt() int GetRefCt() { if(_obj.pushFunction("GetRefCt")) { _obj.pushArg((cef::CEFManager*)this); return (_obj.callFunction<int>()); } return CEFManager::GetRefCt(); }; // Protected non-virtual methods: // Protected non-virtual checkers: // Protected non-virtual function binds: void register_protected_methods(lua_State* L) { }; }; #endif
751987faf232197919082441db1e00ce96fa8624
37ffd116535acab191da2b4c62dfd58868f8287b
/contains_duplicate_2/solution.cpp
029eb0669157082abf77b937ece35d50fe9ced0a
[]
no_license
huwenboshi/leetcode_exercises
c1a494dd4452d2644d21d7bb337f8b268508df17
73bb1741070b50b7729afe7e2edb79d224b2a6d4
refs/heads/master
2019-06-24T14:20:27.149089
2016-08-30T06:43:08
2016-08-30T06:43:08
66,914,041
1
0
null
null
null
null
UTF-8
C++
false
false
716
cpp
solution.cpp
#include <iostream> #include <vector> #include <unordered_map> #include <map> using namespace std; class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int k) { unordered_map<int,int> num_pos; for(int i=0; i<nums.size(); i++) { if(num_pos.find(nums[i]) == num_pos.end()) num_pos[nums[i]] = i; else { if(i-num_pos[nums[i]] <= k) return true; num_pos[nums[i]] = i; } } return false; } }; int main() { Solution sol; int array[] = {1,2,3,4,2,5}; vector<int> nums(array, array+6); cout << sol.containsNearbyDuplicate(nums, 7) << endl;; }
9d4549d4b4c199a62a570683f1bdfea28b5cd2b7
c175cc8629f2523099a078d699f4a23d3c258b5f
/testbed.cpp
b7c284a4c00a7b952152734f6647ad44afe6e691
[]
no_license
fsworld009/AOSproject-submission
0761d7f716cfbdbf35eb958b6ac06d41d20035e6
ca0a44f44dbb96ad428db3518919cf639fad1b18
refs/heads/master
2020-06-04T09:43:54.364889
2015-01-02T23:10:38
2015-01-02T23:10:38
28,576,761
0
0
null
null
null
null
UTF-8
C++
false
false
17,221
cpp
testbed.cpp
#include <stdio.h> #include <string.h> #include <linux/socket.h> #include <netinet/in.h> #include <pthread.h> #include <stdlib.h> #include <unistd.h> #include <netdb.h> #include <iostream> #include <fstream> #include <sstream> #include <vector> using namespace std; typedef struct req { req *prev; req *next; unsigned long time; }req; typedef struct config { int num_nodes; int reliable; int congested; unsigned long alloc_time; req reqlist[46]; }config; config read_config() { ifstream config_file; config_file.open("config.txt"); string buffer; config c; memset(&c, 0x00, sizeof(c)); int trans[37]; memset(trans, 0x00, sizeof(trans)); int count = 0; int next = 0; while(count < 45) { count ++; if( count %5 == 0) { continue; } next ++; trans[next] = count; } getline(config_file, buffer); while( ! config_file.eof()) { if( buffer[0] == '#' || strlen(buffer.c_str()) == 0 ) { getline(config_file, buffer); continue; } //cout << buffer << endl; if( strcmp(buffer.c_str(), "request_start") == 0) { getline(config_file, buffer); while (strcmp(buffer.c_str(), "request_end") != 0) { if( buffer[0] == '#' || strlen(buffer.c_str()) == 0) { getline(config_file, buffer); continue; } istringstream iss(buffer); string result; getline(iss, result, '('); //Finish parsing this getline(iss, result, ','); //cout << "Result: " << result << endl; int node = trans[strtol(result.c_str(), NULL, 10)]; req* current = &(c.reqlist[node]); while (current->next != NULL) { current = current->next; } current->next = (req*) malloc(sizeof(req)); memset(current->next, 0x00, sizeof(req)); current->next->prev = current; unsigned long milliseconds; string time; string temp; getline(iss, time, ')'); istringstream t_stream(time); getline(t_stream, temp, ':'); //minutes milliseconds = strtol(temp.c_str(), NULL, 10); milliseconds *= 60; getline(t_stream, temp, ':'); //seconds milliseconds += strtol(temp.c_str(), NULL, 10); milliseconds *= 1000; getline(t_stream, temp, ')'); //milliseconds milliseconds += strtol(temp.c_str(), NULL, 10); current->time = milliseconds; getline(config_file, buffer); } continue; } istringstream iss(buffer); string result; getline(iss, result, '='); string test; if( result == "num_nodes") { iss >> c.num_nodes; } else if( result == "net_reliable") { iss >> c.reliable; } else if( result == "net_congested") { iss >> c.congested; } else if (result == "res_alloc_time") { unsigned long milliseconds; string time; string current; getline(iss, time); istringstream t_stream(time); getline(t_stream, current, ':'); //minutes milliseconds = strtol(current.c_str(), NULL, 10); milliseconds *= 60; getline(t_stream, current, ':'); //seconds milliseconds += strtol(current.c_str(), NULL, 10); milliseconds *= 1000; getline(t_stream, current); //milliseconds milliseconds += strtol(current.c_str(), NULL, 10); c.alloc_time = milliseconds; } getline(config_file, buffer); } return c; } int forward (char* msg, char* to_addr, int port) { int num = port; int sockfd; struct addrinfo *result; struct sockaddr_in *server_addr; int err = getaddrinfo(to_addr, NULL, NULL, &result); if( err != 0) { return 5; } if( result == NULL) { return 4; } sockfd = socket(result->ai_family, result->ai_socktype, result->ai_protocol); if (sockfd == -1) { return 1; } server_addr = (struct sockaddr_in *) result->ai_addr; (*server_addr).sin_port = htons(num); if (connect(sockfd, result->ai_addr, result->ai_addrlen) == -1) { return 2; } if (write(sockfd, msg, strlen(msg)) != strlen(msg)) { return 3; } close(sockfd); return 0; } void contact_servers(int num_nodes, char* msg, int port) { int count = num_nodes; int current = 1; char to_addr[1024]; while (count != 0) { if (current % 5 != 0) { count --; } memset(to_addr, 0x00, sizeof(to_addr)); if (current < 10) { sprintf(to_addr, "net0%d.utdallas.edu", current); } else { sprintf(to_addr, "net%d.utdallas.edu", current); } int result = forward(msg, to_addr, port); if (result != 0) { cout << "Contacting listening server " << current << " failed: " << result << endl; } current ++; } if( current % 5 != 0) { current = current + 5 - (current %5); } memset(to_addr, 0x00, sizeof(to_addr)); if (current < 10) { sprintf(to_addr, "net0%d.utdallas.edu", current); } else { sprintf(to_addr, "net%d.utdallas.edu", current); } int result = forward(msg, to_addr, port); if (result != 0) { cout << "Contacting listening server " << current << " failed: " << result << endl; } return; } void write_config(config c) { for (int x = 1; x <= 45; x++) { char fname[32]; if (x < 10) { sprintf(fname, "config0%d", x); } else { sprintf(fname, "config%d", x); } ofstream ofile(fname); if( x % 5 == 0) { if( c.reliable == 2) { ofile << 3 << endl; } else if( c.congested == 1) { ofile << 2 << endl; } else { ofile << 1 << endl; } ofile.close(); continue; } ofile << c.alloc_time << endl; req* current = &(c.reqlist[x]); while (current->next != NULL) { ofile << current->time << endl; current = current->next; } ofile.close(); } } //define quorum structure struct Quorum { int id; vector<int> quorum_members; }; vector<Quorum> QuorumAssignment(int n) { //define a vector to store all quorums vector<Quorum> quorum_list; /*determining size of the matrix for implementing square grid quorum assignment method*/ int K = 1; while ((K*K) < n) K++; // create a K*K matrix and enter the node numbers int count = 1; int** myMatrix = new int*[K]; // initializing 2D matrix for (int i = 0; i < K; i++) { myMatrix[i] = new int[K]; } for (int i = 0; i < K; i++) for (int j = 0; j < K; j++) myMatrix[i][j] = -1; for (int row = 0; row < K; row++) // iterate through rows for (int col = 0; col < K; col++) // iterate through columns { if (count <= n) { // count for all nodes //entering the node number in its correct location in the matrix myMatrix[row][col] = count; count++; } } // Each quorum is an array of node numbers in that quorum for (int row = 0; row < K; row++) // iterate through rows { for (int col = 0; col < K; col++) // iterate through columns { if (quorum_list.size() == n) break; Quorum q; //get quorum id q.id = myMatrix[row][col]; // first k elements of the quorum array for (int idx = 0; idx < K; idx++) { if (myMatrix[row][idx] != -1) q.quorum_members.push_back(myMatrix[row][idx]); } /* stores all the values in the row addressed by variable row into the first k indices of the quorum array*/ for (int temp = 0; temp < K; temp++) { if (temp == row) continue; else { if (myMatrix[temp][col] != -1) q.quorum_members.push_back(myMatrix[temp][col]); } } //insert the quorum into the quorum list quorum_list.push_back(q); } } //delete for (int idx = 0; idx < K; idx++) delete [] myMatrix[idx]; delete [] myMatrix; return quorum_list; } void write_quorums( vector<Quorum> quorums) { int trans[37]; memset(trans, 0x00, sizeof(trans)); int count = 0; int next = 0; while(count < 45) { count ++; if( count %5 == 0) { continue; } next ++; trans[next] = count; } //for( int x = 0; x < 37; x++) //{ // cout << trans[x] << " "; //} //cout << endl; vector<Quorum>::iterator iter; for (iter = quorums.begin(); iter != quorums.end(); iter++) { Quorum q = (*iter); char fname[32]; if ( trans[q.id] < 10) { sprintf(fname, "quorum0%d", trans[q.id]); } else { sprintf(fname, "quorum%d", trans[q.id]); } ofstream ofile(fname); vector<int>::iterator it; for (it = q.quorum_members.begin(); it != q.quorum_members.end(); it++) { ofile << trans[(*it)] << endl; } ofile.close(); } } typedef struct crit_sec { crit_sec *prev; crit_sec *next; int node; unsigned long requested; unsigned long started; unsigned long finished; } crit_sec; typedef struct data { int msg_count; int avg_length; unsigned long avg_wait; unsigned long runtime; bool conflict; } data; bool get_conflict( crit_sec* head) { bool confl = false; crit_sec* c1 = head; while( c1->next != NULL ) { int n1 = c1->node; crit_sec* c2 = c1; if (c1->started == 0 || c1->finished == 0) { c1 = c1->next; continue; } while( c2->next != NULL ) { c2 = c2->next; if (c2->started == 0 || c2->finished == 0) { continue; } if( (c1->started < c2->started && c1->finished > c2->started) || (c1->started < c2->finished && c1->finished > c2->finished)) { confl = true; break; } } if( confl) { break; } c1 = c1->next; } return confl; } unsigned long get_runtime( crit_sec* head ) { crit_sec* current = head; unsigned long max = current->finished; while( current->next != NULL) { current = current->next; if (current->finished > max) { max = current->finished; } } return max; } unsigned long get_wait(crit_sec* head) { unsigned long total_wait = 0; int num_req = 0; crit_sec* current = head; while( current != NULL) { if (current->started != 0 && current->requested != 0) { num_req ++; total_wait += current->started - current->requested; } current = current->next; } if (num_req == 0) { return -1; } return (total_wait / num_req); //loss of precision, we round to milliseconds } void write_results(crit_sec* head, int r) { char fname[20]; memset(fname, '\0', sizeof(fname)); sprintf(fname, "output%d", r); ofstream ofile(fname); crit_sec* current = head; while(current != NULL) { if(current->finished != 0) { ofile << current->node << " entered critical section at: " << current->started << " and exited at: " << current->finished << endl; } current = current->next; } ofile.close(); return; } data* get_results(int num_nodes, int r) { int trans[37]; memset(trans, 0x00, sizeof(trans)); int count = 0; int next = 0; data* d; d = (data*) malloc(sizeof(data)); memset(d, 0x00, sizeof(data)); while(count < 45) { count ++; if( count %5 == 0) { continue; } next ++; trans[next] = count; } d->msg_count = 0; int total_length = 0; int temp_length; crit_sec* head; head = (crit_sec*) malloc(sizeof(crit_sec)); memset(head, 0x00, sizeof(crit_sec)); crit_sec* current = head; for( int x = 1; x<= num_nodes; x++) { char fname[10]; string buffer; sprintf(fname, "log%.2d", trans[x]); ifstream ifile; ifile.open(fname); if( ! ifile.is_open() ) { cout << "Failed to open " << fname << endl; continue; } cout << "Opened " << fname << endl; getline(ifile, buffer); while( ! ifile.eof()) { if(buffer[0] != 'c') { temp_length = strtol(buffer.c_str(), NULL, 10); total_length += temp_length; d->msg_count ++; getline(ifile, buffer); continue; } if(buffer[1] == '3') { getline(ifile, buffer); current->requested = strtol(buffer.c_str(), NULL, 10); current->node = x; getline(ifile, buffer); while( ! ifile.eof() && buffer[0] != 'c') { temp_length = strtol(buffer.c_str(), NULL, 10); total_length += temp_length; d->msg_count ++; getline(ifile, buffer); } if(ifile.eof()) { continue; } if(buffer[1] == '1') { getline(ifile, buffer); current->started = strtol(buffer.c_str(), NULL, 10); getline(ifile, buffer); while( ! ifile.eof() && buffer[0] != 'c') { temp_length = strtol(buffer.c_str(), NULL, 10); total_length += temp_length; d->msg_count ++; getline(ifile, buffer); } if(ifile.eof()) { continue; } if(buffer[1] == '2') { getline(ifile, buffer); current->finished = strtol(buffer.c_str(), NULL, 10); current->next = (crit_sec*) malloc(sizeof(crit_sec)); memset(current->next, '\0', sizeof(crit_sec)); current->next->prev = current; current = current->next; getline(ifile, buffer); continue; } continue; } continue; } getline(ifile, buffer); } //cout << "Reached EOF" << endl; if( current->requested != 0) { current->next = (crit_sec*) malloc(sizeof(crit_sec)); memset(current->next, '\0', sizeof(crit_sec)); current->next->prev = current; current = current->next; } ifile.close(); } d->conflict = get_conflict(head); d->runtime = get_runtime(head); d->avg_wait = get_wait(head); if( d->msg_count == 0) { d->avg_length = 0; return d; } d->avg_length = total_length / d->msg_count; write_results(head, r); return d; } void clear_logs() { system("rm -f log??"); } void cleanup() { system("rm -f quorum??"); system("rm -f config??"); } void term_wait(int num_nodes, unsigned int server_sock) { struct sockaddr_in client_addr; unsigned int client_sock; int addr_len; int count = 0; while( count < num_nodes) { client_sock = accept(server_sock, (struct sockaddr *)&client_addr, (socklen_t*) &addr_len); char buffer[1024]; recv(client_sock, buffer, 1024, 0); //send(client_sock, "\xff", 1, 0); count ++; cout << count << " / " << num_nodes << endl; close(client_sock); } } unsigned int term_listen(int aport) { struct sockaddr_in server_addr; unsigned int server_sock; int port = aport; server_sock = socket(AF_INET, SOCK_STREAM, 0); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); server_addr.sin_addr.s_addr = htonl(INADDR_ANY); bind(server_sock, (struct sockaddr *)&server_addr, sizeof(server_addr)); if (listen(server_sock, 1024) != 0) { cout << "Failed to listen to port: " << port << endl; } return server_sock; } int main(int argc, char *argv[]) { //read in config config c = read_config(); int lport, aport; ifstream iports("ports.txt"); iports >> lport >> aport; iports.close(); //quorums vector<Quorum> quorums = QuorumAssignment(c.num_nodes); write_quorums(quorums); //write config write_config(c); //create server to listen for termination unsigned int server_sock = term_listen(aport); //contact necessary servers to start char msg[10]; memset(msg, 0x00, sizeof(msg)); sprintf(msg, "0"); contact_servers(c.num_nodes, msg, lport); sleep(20); //run algorithm 1 memset(msg, 0x00, sizeof(msg)); sprintf(msg, "START"); contact_servers(c.num_nodes, msg, aport); term_wait(c.num_nodes, server_sock); memset(msg, 0x00, sizeof(msg)); sprintf(msg, "END"); contact_servers(c.num_nodes, msg, aport); //collect results data* res1 = get_results(c.num_nodes, 1); clear_logs(); cout << "Results 1 collected" << endl; //switch algorithm memset(msg, 0x00, sizeof(msg)); sprintf(msg, "1"); cout << "Contacting for Round 2" << endl; contact_servers(c.num_nodes, msg, lport); cout << "Contact complete" << endl; sleep(20); //run algorithm 2 memset(msg, 0x00, sizeof(msg)); sprintf(msg, "START"); contact_servers(c.num_nodes, msg, aport); term_wait(c.num_nodes, server_sock); memset(msg, 0x00, sizeof(msg)); sprintf(msg, "END"); contact_servers(c.num_nodes, msg, aport); sleep(20); //tell listening servers to exit memset(msg, 0x00, sizeof(msg)); sprintf(msg, "EXIT"); contact_servers(c.num_nodes, msg, lport); //collect results data* res2 = get_results(c.num_nodes, 2); clear_logs(); cleanup(); close(server_sock); cout << "Message Count: " << endl; cout << " Maekawa: " << res1->msg_count << endl; cout << " Our Algorithm: " << res2->msg_count << endl; cout << "Average Message Length : " << endl; cout << " Maekawa: " << res1->avg_length << endl; cout << " Our Algorithm: " << res2->avg_length << endl; cout << "Average Wait: " << endl; cout << " Maekawa: " << res1->avg_wait << endl; cout << " Our Algorithm: " << res2->avg_wait << endl; cout << "Running Time: " << endl; cout << " Maekawa: " << res1->runtime << endl; cout << " Our Algorithm: " << res2->runtime << endl; cout << "Mutual Exlusion Maintained: " << endl; if( ! res1->conflict) { cout << " Maekawa: True" << endl; } else { cout << " Maekawa: False" << endl; } if( ! res2->conflict) { cout << " Our Algorithm: True" << endl; } else { cout << " Our Algorithm: False" << endl; } return 0; } // send to listening server --> send(whatev_sock, '0', 1); 'start' //analyze collected data //change all times to longs //how to read message length, possibly include as a field? //add control message for requesting critical section
33191c4646d8358eeaf2814068d41418526b209c
1e66ccdcf39ca46f83eaccd46354622220210733
/Arduino snippets/Bin_to_dec.ino
21013d5d873388bd90a188b6dd84971d1a31ef5d
[]
no_license
stormzero/Arduino_Codebase
7ae6018e3ff57d632168ca7c7275d9cc0d3c0a42
715527f2c4ea6e517f578520f2b0becfd05dd385
refs/heads/master
2021-06-28T22:48:04.566630
2017-09-16T21:22:09
2017-09-16T21:22:09
103,784,565
0
0
null
null
null
null
UTF-8
C++
false
false
2,990
ino
Bin_to_dec.ino
/* Converts 8 bit Binary word to Decimal & Hex. The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) * Switches:- bit 0 to bit 5 connected to A0 to A5 * bit 6 to digital pin 8 * bit 7 to digital pin 9 * Second connection on all switches to Ground. * Internal pullup resistors are * activated on all input pins. */ // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5,4,3,2); void setup() { // Set switch input pins & pullups. int b0a=A0; int b1a=A1; int b2a=A2; int b3a=A3; int b0=A0;int b1=A1;int b2=A2;int b3=A3;int b4=A4; int b5=A5;int b6=8;int b7=9; pinMode(A0,INPUT_PULLUP);pinMode(A1,INPUT_PULLUP); pinMode(A2,INPUT_PULLUP);pinMode(A3,INPUT_PULLUP); pinMode(A4,INPUT_PULLUP);pinMode(A5,INPUT_PULLUP); pinMode(8,INPUT_PULLUP);pinMode(9,INPUT_PULLUP); digitalWrite(A0,HIGH);digitalWrite(A1,HIGH); digitalWrite(A2,HIGH);digitalWrite(A3,HIGH); digitalWrite(A4,HIGH);digitalWrite(A5,HIGH); digitalWrite(8,HIGH);digitalWrite(9,HIGH); lcd.begin(16, 2); // Print a message to the LCD. lcd.print("Dec="); } void loop() { int hexL=0;int hexH=0; int dec=0; int b0=A0;int b1=A1;int b2=A2;int b3=A3;int b4=A4; int b5=A5;int b6=8;int b7=9; //Get binary word b0=digitalRead(A0);b1=digitalRead(A1);b2=digitalRead(A2);b3=digitalRead(A3); b4=digitalRead(A4);b5=digitalRead(A5);b6=digitalRead(8);b7=digitalRead(9); int bit0=0;int bit1=0;int bit2=0;int bit3=0;int bit4=0;int bit5=0;int bit6=0;int bit7=0; // Display binary word lcd.setCursor(0,1); lcd.print("Bin="); lcd.print(b7);lcd.print(b6);lcd.print(b5);lcd.print(b4); lcd.print(b3);lcd.print(b2);lcd.print(b1);lcd.print(b0); //Convert bits to decimal if (b0==1){bit0=1;} b0=0; if(b1==1){bit1=2;} b1=0; if(b2==1){ b2=0;bit2=4;} if(b3==1){bit3=8;} b3=0; if(b4==1){bit4=16;} b4=0; if(b5==1){bit5=32;} b5=0; if(b6==1){bit6=64;} b6=0; if(b7==1){bit7=128;} b7=0; dec=(bit0+bit1+bit2+bit3+bit4+bit5+bit6+bit7); //display decimal lcd.setCursor(4,0);lcd.print(dec); //Remove previous decimal display lcd.print(" "); lcd.setCursor(9,0);lcd.print("HEX="); hexH=(bit4+bit5+bit6+bit7);hexH=hexH >> 4; if (hexH <10){lcd.print(hexH);}; if(hexH==10){lcd.print("A");}; if(hexH==11){lcd.print("B");};if(hexH==12){lcd.print("C");}; if(hexH==13){lcd.print("D");};if(hexH==14){lcd.print("E");}; if(hexH==15){lcd.print("F");}; hexL=(bit0+bit1+bit2+bit3); if(hexL <10){lcd.print(hexL);}; if(hexL==10){lcd.print("A");}; if(hexL==11){lcd.print("B");};if(hexL==12){lcd.print("C");}; if(hexL==13){lcd.print("D");};if(hexL==14){lcd.print("E");}; if(hexL==15){lcd.print("F");}; }
d404723593fb8e3c1d17c3124b3c9069152e90cc
321eb29e4ee6977de16765a438e81065c9376fd1
/bloem_arduino/bloem_arduino.ino
600f8b1b6321bb6fcc827b1d693e95b2f93226e0
[ "LicenseRef-scancode-warranty-disclaimer" ]
no_license
metermeter/bloem-arduino
6fe03a68ea9f8b891b01862ea0c23d5b00800f5c
384dca482abd8688b918a4af5befa44147d5dbd2
refs/heads/master
2016-09-06T17:05:29.159319
2015-03-02T09:41:52
2015-03-02T09:41:52
23,840,311
0
0
null
null
null
null
UTF-8
C++
false
false
3,190
ino
bloem_arduino.ino
int debugPin = 2; boolean debug = false; int waterPin = A1; int waterLed = 13; int waterAan = 11; int waterValue = 0; int waterLimitLower = 0; int waterLimitUpper = 100; boolean waterPulse = false; boolean waterFirst = true; int powerPin = A0; int powerLed = 12; int powerAan = 10; int powerValue = 0; int powerLimitLower = 0; int powerLimitUpper = 1023; boolean powerPulse = false; boolean powerFirst = true; void setup() { // set as input and enable the internal pull-up resistor pinMode(waterAan, INPUT_PULLUP); pinMode(waterLed, OUTPUT); pinMode(powerAan, INPUT_PULLUP); pinMode(powerLed, OUTPUT); pinMode(debugPin, INPUT_PULLUP); debug = !digitalRead(debugPin); Serial.begin(115200); Serial.println("METERMETER OK"); Serial.print("powerpin: "); Serial.print(powerAan); Serial.print(","); if(digitalRead(powerAan)) { digitalWrite(powerLed, HIGH); Serial.println("1"); } else { digitalWrite(powerLed, LOW); Serial.println("0"); } Serial.print("waterpin: "); Serial.print(waterAan); Serial.print(","); if(digitalRead(waterAan)) { digitalWrite(waterLed, HIGH); Serial.println("1"); } else { digitalWrite(waterLed, LOW); Serial.println("0"); } if(debug) { Serial.println("DEBUG PARTY MODE!"); for(int i = 1; i < 40; i++){ digitalWrite(waterLed, i%2); digitalWrite(powerLed, (i+1)%2); delay(100); } digitalWrite(waterLed, HIGH); digitalWrite(powerLed, LOW); } else { Serial.println("NORMAL OPERATION MODE"); } } // the loop routine runs over and over again forever: void loop() { boolean checkWater = digitalRead(waterAan); boolean checkPower = digitalRead(powerAan); if(debug) { Serial.print("water: "); if(checkWater) { Serial.print(analogRead(waterPin)); } else { Serial.print("x"); } Serial.print(" power: "); if(checkPower) { Serial.println(analogRead(powerPin)); } else { Serial.println("x"); } digitalWrite(waterLed, !digitalRead(waterLed)); digitalWrite(powerLed, !digitalRead(powerLed)); delay(1000); } else { digitalWrite(waterLed, checkWater); // water if(checkWater) { boolean waterPulsePrevious = waterPulse; waterValue = analogRead(waterPin); if(waterValue < waterLimitLower || waterValue > waterLimitUpper) { waterPulse = true; } else { waterPulse = false; } if(waterPulsePrevious && !waterPulse) { if(!waterFirst) { Serial.println("water,1"); } else { waterFirst = false; } } } // power digitalWrite(powerLed, checkPower); if(checkPower) { boolean powerPulsePrevious = powerPulse; powerValue = analogRead(powerPin); if(powerValue < powerLimitLower || powerValue > powerLimitUpper) { powerPulse = true; } else { powerPulse = false; } if(powerPulsePrevious && !powerPulse) { if(!powerFirst) { Serial.println("elec,1"); } else { powerFirst = false; } } } } }
c7c70ae2cc2342490d4d3b5dd9be2a7d696e61ad
e055c4e76ab1da03db14c0fdf9908e9d63115ca0
/codeforces/800/easy_problem.cpp
c5c27e6fbd39527d06af48dacbdc960590154847
[]
no_license
pmdev15/competitiveprogramming
2514fca2015de83256d65d4ed1224dd823d3ea61
2cbe16934df7bd74b413fcf1208c0b250e30af16
refs/heads/main
2023-03-15T00:26:09.870133
2021-03-16T14:35:22
2021-03-16T14:35:22
316,480,373
1
0
null
null
null
null
UTF-8
C++
false
false
274
cpp
easy_problem.cpp
#include <iostream> using namespace std; int main() { int n,m; cin>>n; for (int i = 0; i < n; i++) { cin>>m; if (m==1) { cout<<"HARD"; return 0; } } cout<<"Easy"; return 0; }
f1467654461916f68bca5b147bb64ed1eb705c71
8e31537d2e0672e55c36ecb1dab65d74cb7f31c1
/src/system/spawner.hpp
3be83beedfba2784ca050c09fb78777b9b591a4d
[]
no_license
marcogmaia/rltk_rl
37e03a653d6c3cc88ffef954cc256145e6b99b5a
f15ee4b1c57d9d8937d8314d0b8807efe35e63e3
refs/heads/main
2023-04-26T15:40:43.893330
2021-05-23T19:35:06
2021-05-23T19:35:06
null
0
0
null
null
null
null
UTF-8
C++
false
false
224
hpp
spawner.hpp
#pragma once #include "utils/rect.hpp" namespace radl { /** * @brief Spawn an enemy inside the delimited rect * * @param rect */ void enemy_spawner(component::rect_t rect); void add_enemies(); } // namespace radl
932706746e45652b6c3deb0e7fd43a79d14206cb
fab0133d18d7ed079166e5fc0d19ddef6c9d1064
/https:/codeforces.com/contest/131/problem/C.cpp
24c0f2ce95eafb13a419a98830b08c221df8974a
[]
no_license
sarthak11yadav/Competitive-Programming
f0a708223c524ed419efb4d7741390b79de8e76d
5bf2abced61940c19d9e6d60d2181638f069d372
refs/heads/master
2022-12-24T11:56:34.389709
2020-10-12T08:35:43
2020-10-12T08:35:43
303,455,130
3
0
null
null
null
null
UTF-8
C++
false
false
755
cpp
C.cpp
//https://codeforces.com/contest/131/problem/C #include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; ll inf = (ll)1e18; ll mod = 1000000001; ll ways(ll n, ll k) { ll C[n + 1][k + 1]; ll i, j; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = C[i - 1][j - 1] + C[i - 1][j]; } } return C[n][k]; } ll max1 = (ll)1e9; int main() { ll i, j, k, n, m, ct = 0, t; ll ans = 0; cin >> n >> m >> t; k = 4; while (k <=n && t - k >= 1) { if(t-k<=m) ans += ways(n, k) * ways(m, t - k); k++; } cout << ans << endl; return 0;
075e12979db5c9787e858a217ea14d943196d6be
ba1b9659b7756bc16cd9077897b249383c842434
/executables/test_XML.cpp
4e10ecfb540a3357216e52099c7f973d2ccd68af
[]
no_license
evolvazpr/evolva
4d60d5a9cdea2268b649c6ac42567faf9a289ab8
e987ea5a6f4e14b8bee48da7387cd9c7f6b6228d
refs/heads/master
2021-01-21T04:41:06.644573
2016-06-12T01:51:17
2016-06-12T01:51:17
53,046,045
0
0
null
2016-03-05T11:00:36
2016-03-03T11:41:57
null
UTF-8
C++
false
false
1,486
cpp
test_XML.cpp
#include <string> #include "../EvolvaException.hpp" #include "../XmlIo.hpp" #include <iostream> #include <cstdlib> #include<fstream> // not unit test int print_start() { char buf[100]; std::ifstream file; std::cout << "\nThis is a test for XmlIo class.\n\nIt opens test.xml file, " "writes into its nodes, changes value of Field - Width element,\n" "and saves file.\ntest.xml file now contains:\n\n"; file.open("test.xml"); if (!file.is_open()) return -1; while(!file.eof()) { file >> buf; std::cout << buf; std::cout << "\n"; } std::cout << "\n"; file.close(); return 0; } int print_end() { char buf[100]; std::ifstream file; std::cout << "\nAt exit test.xml contains:\n\n"; file.open("test.xml"); if (!file.is_open()) return -1; while(!file.eof()) { file >> buf; std::cout << buf; std::cout << "\n"; } std::cout << "\n"; file.close(); return 0; } int main(void) { int ret = 0; try { double test; if(print_start()) return -1; ret = system("cp ./test.xml ./OLDtest.xml"); XmlIo xml("test.xml\0"); test = xml["Field"]["Width"]; std::cout << "Field width: " << test << "\n"; xml["Field"]["Width"] = 10; xml.CreateElement({"a", "b", "c", "d"}); xml.CreateElement({"not_empty"}); xml["not_empty"] = 5; xml.SaveFile(); if(print_end()) ret = -2; ret = system("mv ./OLDtest.xml ./test.xml"); } catch (std::exception& exception) { std::cout << exception.what() << std::endl; } return ret; }
d116b314c1081e6d31f2e5fe56418fd087cbefbb
143324a51d88a625ea9b26f74b3bc82dfe33cf86
/src/robot_statemachine/rsm_rviz_plugins/src/PlantWaypointTool.cpp
8ced1d9a33df4b2374d29f2db6a0d13e5750ac42
[ "BSD-3-Clause", "MIT" ]
permissive
iamrajee-ust/slam_rosmelodic_ws
049b698f03fb73f3aae06337bcbf5435839bf53b
b2ee00bc522938cfb79336068cd905de757e84b5
refs/heads/master
2023-05-12T17:41:39.469744
2021-06-06T03:08:26
2021-06-06T03:08:26
null
0
0
null
null
null
null
UTF-8
C++
false
false
3,738
cpp
PlantWaypointTool.cpp
#include <rsm_rviz_plugins/PlantWaypointTool.h> namespace rsm { PlantWaypointTool::PlantWaypointTool() : moving_flag_node_( NULL), current_flag_property_( NULL) { shortcut_key_ = 'w'; ros::NodeHandle nh("rsm"); _add_waypoint_client = nh.serviceClient<rsm_msgs::AddWaypoint>( "addWaypoint"); } PlantWaypointTool::~PlantWaypointTool() { for (unsigned i = 0; i < flag_nodes_.size(); i++) { scene_manager_->destroySceneNode(flag_nodes_[i]); } } void PlantWaypointTool::onInitialize() { flag_resource_ = "package://rsm_rviz_plugins/media/flag.dae"; if (rviz::loadMeshFromResource(flag_resource_).isNull()) { ROS_ERROR("PlantWaypointTool: failed to load model resource '%s'.", flag_resource_.c_str()); return; } moving_flag_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode(); Ogre::Entity* entity = scene_manager_->createEntity(flag_resource_); moving_flag_node_->attachObject(entity); moving_flag_node_->setVisible(false); } void PlantWaypointTool::activate() { if (moving_flag_node_) { moving_flag_node_->setOrientation(Ogre::Quaternion()); moving_flag_node_->setVisible(true); current_flag_property_ = new rviz::VectorProperty( "Waypoint " + QString::number(flag_nodes_.size())); current_flag_property_->setReadOnly(true); getPropertyContainer()->addChild(current_flag_property_); state_ = Moving; } } void PlantWaypointTool::deactivate() { if (moving_flag_node_) { moving_flag_node_->setVisible(false); delete current_flag_property_; current_flag_property_ = NULL; } } int PlantWaypointTool::processMouseEvent(rviz::ViewportMouseEvent& event) { if (!moving_flag_node_) { return Render; } Ogre::Vector3 intersection; Ogre::Plane ground_plane(Ogre::Vector3::UNIT_Z, 0.0f); if (rviz::getPointOnPlaneFromWindowXY(event.viewport, ground_plane, event.x, event.y, intersection)) { moving_flag_node_->setVisible(true); if (state_ == Moving) { moving_flag_node_->setPosition(intersection); current_flag_property_->setVector(intersection); } if (event.leftDown()) { state_ == Position; pos_ = intersection; moving_flag_node_->setPosition(pos_); state_ = Orientation; return Render; } else if (event.type == QEvent::MouseMove && event.left() && state_ == Orientation) { //compute angle in x-y plane double angle = atan2(intersection.y - pos_.y, intersection.x - pos_.x); moving_flag_node_->setVisible(true); //we need base_orient, since the arrow goes along the -z axis by default (for historical reasons) moving_flag_node_->setOrientation( Ogre::Quaternion(Ogre::Radian(angle), Ogre::Vector3::UNIT_Z)); return Render; } else if (event.leftUp() && state_ == Orientation) { //compute angle in x-y plane double angle = atan2(intersection.y - pos_.y, intersection.x - pos_.x); makeFlag(pos_, angle); return (Finished | Render); } } else { moving_flag_node_->setVisible(false); // If the mouse is not pointing at the ground plane, don't show the flag. return Render; } } void PlantWaypointTool::makeFlag(const Ogre::Vector3& position, double angle) { rsm_msgs::AddWaypoint srv; rsm_msgs::Waypoint waypoint; waypoint.pose.position.x = position.x; waypoint.pose.position.y = position.y; waypoint.pose.position.z = position.z; waypoint.pose.orientation = tf::createQuaternionMsgFromYaw(angle); srv.request.waypoint = waypoint; srv.request.position = -1; if (!_add_waypoint_client.call(srv)) { ROS_ERROR("Failed to call Add Waypoint service"); } } void PlantWaypointTool::save(rviz::Config config) const { } void PlantWaypointTool::load(const rviz::Config& config) { } } // end namespace rsm PLUGINLIB_EXPORT_CLASS(rsm::PlantWaypointTool, rviz::Tool)
2f32bda345d7c3b48fa6a7b3f3b5207de0e8e60f
49f88ff91aa582e1a9d5ae5a7014f5c07eab7503
/gen/services/resource_coordinator/public/mojom/coordination_unit_provider.mojom-shared.h
4c202307a40bf2916e001d3a703389469e5dd906
[]
no_license
AoEiuV020/kiwibrowser-arm64
b6c719b5f35d65906ae08503ec32f6775c9bb048
ae7383776e0978b945e85e54242b4e3f7b930284
refs/heads/main
2023-06-01T21:09:33.928929
2021-06-22T15:56:53
2021-06-22T15:56:53
379,186,747
0
1
null
null
null
null
UTF-8
C++
false
false
8,223
h
coordination_unit_provider.mojom-shared.h
// Copyright 2016 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef SERVICES_RESOURCE_COORDINATOR_PUBLIC_MOJOM_COORDINATION_UNIT_PROVIDER_MOJOM_SHARED_H_ #define SERVICES_RESOURCE_COORDINATOR_PUBLIC_MOJOM_COORDINATION_UNIT_PROVIDER_MOJOM_SHARED_H_ #include <stdint.h> #include <functional> #include <ostream> #include <type_traits> #include <utility> #include "base/compiler_specific.h" #include "base/containers/flat_map.h" #include "mojo/public/cpp/bindings/array_data_view.h" #include "mojo/public/cpp/bindings/enum_traits.h" #include "mojo/public/cpp/bindings/interface_data_view.h" #include "mojo/public/cpp/bindings/lib/bindings_internal.h" #include "mojo/public/cpp/bindings/lib/serialization.h" #include "mojo/public/cpp/bindings/map_data_view.h" #include "mojo/public/cpp/bindings/string_data_view.h" #include "services/resource_coordinator/public/mojom/coordination_unit_provider.mojom-shared-internal.h" #include "services/resource_coordinator/public/mojom/coordination_unit.mojom-shared.h" #include "mojo/public/cpp/bindings/lib/interface_serialization.h" #include "mojo/public/cpp/bindings/native_enum.h" #include "mojo/public/cpp/bindings/lib/native_struct_serialization.h" #include "base/component_export.h" namespace resource_coordinator { namespace mojom { } // namespace mojom } // namespace resource_coordinator namespace mojo { namespace internal { } // namespace internal } // namespace mojo namespace resource_coordinator { namespace mojom { // Interface base classes. They are used for type safety check. class CoordinationUnitProviderInterfaceBase {}; using CoordinationUnitProviderPtrDataView = mojo::InterfacePtrDataView<CoordinationUnitProviderInterfaceBase>; using CoordinationUnitProviderRequestDataView = mojo::InterfaceRequestDataView<CoordinationUnitProviderInterfaceBase>; using CoordinationUnitProviderAssociatedPtrInfoDataView = mojo::AssociatedInterfacePtrInfoDataView<CoordinationUnitProviderInterfaceBase>; using CoordinationUnitProviderAssociatedRequestDataView = mojo::AssociatedInterfaceRequestDataView<CoordinationUnitProviderInterfaceBase>; class CoordinationUnitProvider_CreateFrameCoordinationUnit_ParamsDataView { public: CoordinationUnitProvider_CreateFrameCoordinationUnit_ParamsDataView() {} CoordinationUnitProvider_CreateFrameCoordinationUnit_ParamsDataView( internal::CoordinationUnitProvider_CreateFrameCoordinationUnit_Params_Data* data, mojo::internal::SerializationContext* context) : data_(data), context_(context) {} bool is_null() const { return !data_; } template <typename UserType> UserType TakeRequest() { UserType result; bool ret = mojo::internal::Deserialize<::resource_coordinator::mojom::FrameCoordinationUnitRequestDataView>( &data_->request, &result, context_); DCHECK(ret); return result; } inline void GetIdDataView( ::resource_coordinator::mojom::CoordinationUnitIDDataView* output); template <typename UserType> WARN_UNUSED_RESULT bool ReadId(UserType* output) { auto* pointer = data_->id.Get(); return mojo::internal::Deserialize<::resource_coordinator::mojom::CoordinationUnitIDDataView>( pointer, output, context_); } private: internal::CoordinationUnitProvider_CreateFrameCoordinationUnit_Params_Data* data_ = nullptr; mojo::internal::SerializationContext* context_ = nullptr; }; class CoordinationUnitProvider_CreatePageCoordinationUnit_ParamsDataView { public: CoordinationUnitProvider_CreatePageCoordinationUnit_ParamsDataView() {} CoordinationUnitProvider_CreatePageCoordinationUnit_ParamsDataView( internal::CoordinationUnitProvider_CreatePageCoordinationUnit_Params_Data* data, mojo::internal::SerializationContext* context) : data_(data), context_(context) {} bool is_null() const { return !data_; } template <typename UserType> UserType TakeRequest() { UserType result; bool ret = mojo::internal::Deserialize<::resource_coordinator::mojom::PageCoordinationUnitRequestDataView>( &data_->request, &result, context_); DCHECK(ret); return result; } inline void GetIdDataView( ::resource_coordinator::mojom::CoordinationUnitIDDataView* output); template <typename UserType> WARN_UNUSED_RESULT bool ReadId(UserType* output) { auto* pointer = data_->id.Get(); return mojo::internal::Deserialize<::resource_coordinator::mojom::CoordinationUnitIDDataView>( pointer, output, context_); } private: internal::CoordinationUnitProvider_CreatePageCoordinationUnit_Params_Data* data_ = nullptr; mojo::internal::SerializationContext* context_ = nullptr; }; class CoordinationUnitProvider_CreateProcessCoordinationUnit_ParamsDataView { public: CoordinationUnitProvider_CreateProcessCoordinationUnit_ParamsDataView() {} CoordinationUnitProvider_CreateProcessCoordinationUnit_ParamsDataView( internal::CoordinationUnitProvider_CreateProcessCoordinationUnit_Params_Data* data, mojo::internal::SerializationContext* context) : data_(data), context_(context) {} bool is_null() const { return !data_; } template <typename UserType> UserType TakeRequest() { UserType result; bool ret = mojo::internal::Deserialize<::resource_coordinator::mojom::ProcessCoordinationUnitRequestDataView>( &data_->request, &result, context_); DCHECK(ret); return result; } inline void GetIdDataView( ::resource_coordinator::mojom::CoordinationUnitIDDataView* output); template <typename UserType> WARN_UNUSED_RESULT bool ReadId(UserType* output) { auto* pointer = data_->id.Get(); return mojo::internal::Deserialize<::resource_coordinator::mojom::CoordinationUnitIDDataView>( pointer, output, context_); } private: internal::CoordinationUnitProvider_CreateProcessCoordinationUnit_Params_Data* data_ = nullptr; mojo::internal::SerializationContext* context_ = nullptr; }; class CoordinationUnitProvider_GetSystemCoordinationUnit_ParamsDataView { public: CoordinationUnitProvider_GetSystemCoordinationUnit_ParamsDataView() {} CoordinationUnitProvider_GetSystemCoordinationUnit_ParamsDataView( internal::CoordinationUnitProvider_GetSystemCoordinationUnit_Params_Data* data, mojo::internal::SerializationContext* context) : data_(data), context_(context) {} bool is_null() const { return !data_; } template <typename UserType> UserType TakeRequest() { UserType result; bool ret = mojo::internal::Deserialize<::resource_coordinator::mojom::SystemCoordinationUnitRequestDataView>( &data_->request, &result, context_); DCHECK(ret); return result; } private: internal::CoordinationUnitProvider_GetSystemCoordinationUnit_Params_Data* data_ = nullptr; mojo::internal::SerializationContext* context_ = nullptr; }; } // namespace mojom } // namespace resource_coordinator namespace std { } // namespace std namespace mojo { } // namespace mojo namespace resource_coordinator { namespace mojom { inline void CoordinationUnitProvider_CreateFrameCoordinationUnit_ParamsDataView::GetIdDataView( ::resource_coordinator::mojom::CoordinationUnitIDDataView* output) { auto pointer = data_->id.Get(); *output = ::resource_coordinator::mojom::CoordinationUnitIDDataView(pointer, context_); } inline void CoordinationUnitProvider_CreatePageCoordinationUnit_ParamsDataView::GetIdDataView( ::resource_coordinator::mojom::CoordinationUnitIDDataView* output) { auto pointer = data_->id.Get(); *output = ::resource_coordinator::mojom::CoordinationUnitIDDataView(pointer, context_); } inline void CoordinationUnitProvider_CreateProcessCoordinationUnit_ParamsDataView::GetIdDataView( ::resource_coordinator::mojom::CoordinationUnitIDDataView* output) { auto pointer = data_->id.Get(); *output = ::resource_coordinator::mojom::CoordinationUnitIDDataView(pointer, context_); } } // namespace mojom } // namespace resource_coordinator #endif // SERVICES_RESOURCE_COORDINATOR_PUBLIC_MOJOM_COORDINATION_UNIT_PROVIDER_MOJOM_SHARED_H_
9e9b83bf1fcc1ff058a7159890359493d7a51f54
64015107ddd0d3fa3c2147d959881fab45e87696
/producer_consumer.cpp
cb5981baae1f5bd0f94478629516e3108da2524e
[]
no_license
aanupindi/Threadpooling
c359e55da7a4d4c4952ae7cff9ef9a4b36e5efaa
3f328fff36c48b83ed746e954e701c4874d43eb0
refs/heads/master
2021-01-22T08:14:18.071573
2017-07-15T14:46:32
2017-07-15T14:46:32
92,609,010
0
0
null
null
null
null
UTF-8
C++
false
false
2,724
cpp
producer_consumer.cpp
#include <iostream> #include <thread> #include <deque> #include <mutex> #include <chrono> #include <condition_variable> #include <future> #include <vector> using namespace std; class Buffer{ std::deque<int> _buffer; std::mutex bufferMutex; std::condition_variable BufferCV; std::mutex printMutex; static const int totalSize = 10; public: Buffer(){ } void PrintData(const std::string& action, int value){ std::unique_lock<std::mutex> printlocker(printMutex); cout << action << value << endl; } void AddValue(int value = 0){ std::string action("Adding value: "); std::unique_lock<std::mutex> locker(bufferMutex); // lock the buffer BufferCV.wait(locker, [&](){return (_buffer.size() < totalSize) ;}); // wait until there is space in the buffer. int val; if(value == 0) val = rand() % 100; else val = -1; _buffer.push_back(val); locker.unlock(); BufferCV.notify_all(); PrintData(action,val); } int GetValue(){ std::string action("Removing value "); std::unique_lock<std::mutex> locker(bufferMutex); BufferCV.wait(locker, [&](){return (_buffer.size() > 0) ;}); int current = _buffer.front(); if(current != -1) _buffer.pop_front(); locker.unlock(); BufferCV.notify_all(); PrintData(action,current); return current; } void TerminateProduction(){ AddValue(-1); } }; class Producer{ Buffer &buffer; int limit = 10; std::thread *prodThread; public: Producer(Buffer& b):buffer(b){ } void Start(){ prodThread = new std::thread(&Producer::PushData, this); } void PushData(){ int current = 0; //cout << "Producer::PushData"<<endl; while(current < limit){ buffer.AddValue(); ++current; } buffer.TerminateProduction(); } void WaitUntilDone(){ prodThread->join(); } }; class Consumer { Buffer& buffer; std::thread *consumerThread; public: Consumer(Buffer& b):buffer(b){ } void Start(){ cout << "Consumer:: GetData"<<endl; consumerThread = new std::thread(&Consumer::GetData, this); } void GetData(){ int value ; while(value != -1){ value = buffer.GetValue(); cout <<"Thread Number: " << std::this_thread::get_id() <<" consumer value :" << value <<endl; } cout << "Done executing thread " << std::this_thread::get_id() << std::endl; return; } void WaitUntilDone(){ consumerThread->join(); } }; int main(int argc, char* argv[]){ Buffer b; Producer p(b); cout << "Starting all threads.\n"; std::vector<Consumer*> consumerThreads(5); for(auto &consumerThread : consumerThreads){ consumerThread = new Consumer(b); consumerThread->Start(); } p.Start(); p.WaitUntilDone(); for(const auto &consumerThread : consumerThreads){ consumerThread->WaitUntilDone(); } return 0; }
ea9717680f374b7bfb866e12dff437f05c8fe0d9
00cb2614d51fcbcd8d83ec0b423239cc7d050344
/GameEngine/Source/HealthBar.h
1d514180196c412b1bb9f9f2082d3b21c997f3c4
[]
no_license
stacieem/GameEngine
6a439df7bd030d832d45b721679200361e3f6fb0
93926c922d0cd57592773efc597c677738242c64
refs/heads/master
2020-03-15T23:38:30.263383
2017-11-16T18:23:50
2017-11-16T18:23:50
132,398,032
1
1
null
null
null
null
UTF-8
C++
false
false
1,600
h
HealthBar.h
// // HealthBar.h // GameEngine // // Created by Tim Arterbury on 8/29/17. // // #pragma once #include "../JuceLibraryCode/JuceHeader.h" class HealthBar : public Component { public: HealthBar() { lives = 1; addAndMakeVisible(lifeLabel); lifeLabel.setText("- LIFE -", dontSendNotification); lifeLabel.setJustificationType(Justification::centredTop); lifeLabel.setFont(Font(14.0f)); addAndMakeVisible(multiplierLabel); multiplierLabel.setText("x", dontSendNotification); multiplierLabel.setJustificationType(Justification::right); multiplierLabel.setFont(Font(28.0f)); File f = File(File::getCurrentWorkingDirectory().getFullPathName() + "/textures/heart.png"); img = ImageFileFormat::loadFrom(f); img = img.rescaled(30, 30); } void paint(Graphics &g) override { if (lives > 5) { multiplierLabel.setText("x" + String(lives), dontSendNotification); g.drawImageAt(img, 70, 20); multiplierLabel.setVisible(true); return; } multiplierLabel.setVisible(false); int x = 0; for (int i = 0; i < lives; i++) { g.drawImageAt(img, x, 20); x += 35; } } void resized() override { lifeLabel.setBounds(getLocalBounds()); multiplierLabel.setBounds(105, 20, 40, 30); } void setLives(int lives) { this->lives = lives; } void setLifeTexture(File file) { if (texFile == file) { return; } texFile = file; img = ImageFileFormat::loadFrom(file); img = img.rescaled(30, 30); } private: Label lifeLabel; Label multiplierLabel; Image img; File texFile; int lives; };
bdfd1abd31df0e18fb703bf05af68e9fe80ca609
eed562d67bebd70aded0e7c28a8255a508b6f451
/project_final/src/log.cpp
57c1e31f12d62bd1e8ec8b3d471adccc9d04bdd1
[]
no_license
jintak0401/2G_2S__DBMS
5e037d71bbb1fb3cd94f4ecf0ad28750e2816d7b
422249f556adfadf1ce76b8b800d7b0d2182288a
refs/heads/master
2021-04-07T23:14:12.887773
2020-03-20T11:52:15
2020-03-20T11:52:15
248,715,736
0
0
null
null
null
null
UTF-8
C++
false
false
7,801
cpp
log.cpp
#include "log.h" #include <pthread.h> uint64_t LSN = 0; uint64_t position = 0; //long position = 0; long trx_prev_LSN[20] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; checking_record_t checking_record = NULL; //long* trx_prev_LSN; std::list <log_record_t> log_tail; int log_fd = open("log_file", O_RDWR | O_CREAT, 0644); pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t flush_mutex = PTHREAD_MUTEX_INITIALIZER; log_record_t make_log(Type type, int tid, int prev_LSN, int table_id, pagenum_t page_num, int offset, char old_image[], char new_image[]){ log_record_t log = (log_record_t)malloc(sizeof(_log_record_t)); //log_record_t log = new _log_record_t(); if (log == NULL){ perror("[ log.cpp ] < make_log >"); exit(EXIT_FAILURE); } log->LSN = LSN; log->prev_LSN = prev_LSN; log->tid = tid; log->type = type; log->table_id = table_id; log->page_num = page_num; log->offset = offset; if (type == UPDATE){ log->length = 120; } else { log->length = 0; } if (old_image != NULL){ strcpy(log->old_image, old_image); } if (new_image != NULL){ strcpy(log->new_image, new_image); } if (type == UPDATE){ LSN += sizeof(_log_record_t); } else { LSN += sizeof(_checking_record_t); } return log; } int log_buffer_write(Type type, int tid, int table_id, pagenum_t page_num, int index, char old_image[], char new_image[]){ int ret_LSN; // mutex =================================================== pthread_mutex_lock(&log_mutex); log_record_t log = make_log(type, tid, trx_prev_LSN[tid - 1], table_id, page_num, 128 * (index + 1) + 8, old_image, new_image); trx_prev_LSN[tid - 1] = log->LSN; log_tail.push_back(log); ret_LSN = log->LSN; if (type == COMMIT){ printf("\n(!!!! tid : %d commit!!!!)\n", tid); flush_log(); } pthread_mutex_unlock(&log_mutex); // mutex =================================================== return ret_LSN; } void flush_log(){ pthread_mutex_lock(&flush_mutex); for (std::list<log_record_t>::iterator it = log_tail.begin(); it != log_tail.end(); it = log_tail.erase(it)){ log_file_write(*it); free(*it); *it = NULL; //delete (*it); } pthread_mutex_unlock(&flush_mutex); } void log_file_write(log_record_t log){ if (log->type != UPDATE){ pwrite(log_fd, log, sizeof(_checking_record_t), log->LSN); if (position <= log->LSN){ position += sizeof(_checking_record_t); } } else { pwrite(log_fd, log, sizeof(_log_record_t), log->LSN); if (position <= log->LSN){ position += sizeof(_log_record_t); } } } void abort(int tid){ log_record_t read_log = NULL; log_record_t write_log = NULL; leaf_t leaf; record_t record; // mutex===================================================== pthread_mutex_lock(&log_mutex); flush_log(); int tmp = position - 1; read_log = (log_record_t)malloc(sizeof(_log_record_t)); //read_log = new _log_record_t(); /* *while(pread(log_fd, read_log, sizeof(_log_record_t), trx_prev_LSN[tid - 1]) > 0) { * if (read_log->tid == tid){ * break; * } * else { * tmp--; * } *} */ pread(log_fd, read_log, sizeof(_log_record_t), trx_prev_LSN[tid - 1]); while (read_log->type != BEGIN) { write_log = make_log(UPDATE, tid, read_log->prev_LSN, read_log->table_id, read_log->page_num, read_log->offset, read_log->new_image, read_log->old_image); while ((leaf = (leaf_t)buffer_read_page(read_log->table_id, read_log->page_num)) == NULL); record = &leaf->record[((read_log->offset - 8) / 128) - 1]; printf("\n(!!! < tid : %d > UNDO!!!) [ table %d ]'s [ page %d ]\t\t key : %ld\t\t < value : %s", tid, read_log->table_id, read_log->page_num, record->key, record->value); strcpy(record->value, read_log->old_image); printf(" ------> %s >\n", record->value); leaf->page_LSN = write_log->LSN; log_tail.push_back(write_log); buffer_write_page(write_log->table_id, write_log->page_num, (page_t)leaf, 1); pread(log_fd, read_log, sizeof(_log_record_t), read_log->prev_LSN); } //delete write_log; //delete read_log; write_log = make_log(ABORT, tid, -1, 0, 0, 0, NULL, NULL); log_tail.push_back(write_log); flush_log(); printf("\n(!!!! tid : %d abort!!!!)\n", tid); pthread_mutex_unlock(&log_mutex); // mutex===================================================== } void recovery(){ log_record_t log; leaf_t leaf; record_t record; bool loser[20]; std::list<log_record_t> log_recovery; checking_record = (checking_record_t)malloc(sizeof(_checking_record_t)); if (checking_record == NULL){ printf("checking_record error < recovery > [ log.cpp ]"); exit(EXIT_FAILURE); } /* * trx_prev_LSN = (long*)malloc(sizeof(long) * 20); * * for (int i = 0; i < 20; i++){ * trx_prev_LSN[i] = -1; * } */ // loser 선별용 bool 배열 초기화 for (int i = 0; i < 20; i++){ loser[i] = false; } // log_file 로 부터 읽어들임 while (true) { log = (log_record_t)malloc(sizeof(_log_record_t)); //log = new _log_record_t(); if (pread(log_fd, checking_record, sizeof(_checking_record_t), position) <= 0) { break; } if (checking_record->type != UPDATE){ pread(log_fd, log, sizeof(_checking_record_t), position); position += sizeof(_checking_record_t); LSN += sizeof(_checking_record_t); } // UPDATE else { pread(log_fd, log, sizeof(_log_record_t), position); position += sizeof(_log_record_t); LSN += sizeof(_log_record_t); } //log_tail.push_back(log); log_recovery.push_back(log); trx_prev_LSN[log->tid - 1] = log->LSN; } free(log); log = NULL; //delete log; // redo for (std::list<log_record_t>::iterator it = log_recovery.begin(); it != log_recovery.end(); it++){ if ((*it)->type == BEGIN){ loser[(*it)->tid - 1] = true; } // commit 이면 log_buffer 에서 log들 삭제 if ((*it)->type == COMMIT || (*it)->type == ABORT){ for (std::list<log_record_t>::iterator inner = log_recovery.begin(); inner != it; inner++){ if ((*inner)->tid == (*it)->tid){ free(*inner); *inner = NULL; //delete (*inner); inner = log_recovery.erase(inner); inner--; } } loser[(*it)->tid - 1] = false; free(*it); it = log_recovery.erase(it); it--; } // abort 일 경우 loser 에서 삭제 /* *else if ((*it)->type == ABORT){ * loser[(*it)->tid - 1] = false; *} */ // update 일 경우 redo 진행 else if ((*it)->type == UPDATE){ while ((leaf = (leaf_t)buffer_read_page((*it)->table_id, (*it)->page_num)) == NULL); // consider if (leaf->page_LSN < (*it)->LSN) { record = &leaf->record[(((*it)->offset - 8) / 128) - 1]; printf("\n(!!! < tid : %d > REDO!!!) [ table %d ]'s [ page %d ]\t\t key : %ld\t\t < value : %s", (*it)->tid, (*it)->table_id, (*it)->page_num, record->key, record->value); strcpy(record->value, (*it)->new_image); printf(" ------> %s >\n", record->value); leaf->page_LSN = (*it)->LSN; buffer_write_page((*it)->table_id, (*it)->page_num, (page_t)leaf, 1); } else { buffer_write_page((*it)->table_id, (*it)->page_num, (page_t)leaf, 0); } } } for (std::list<log_record_t>::iterator it = log_recovery.begin(); it != log_recovery.end(); it = log_recovery.erase(it)) { free(*it); *it = NULL; } // loser 에 대해 undo for (int i = 0; i < 20; i++){ if (loser[i] == true){ abort(i + 1); } } }
efb0b424a33b06bc256eff6ee5a6deaac7cd296d
b2531eced9be01fe6c8daf6949633454f24db47f
/CISCO/MFCApplication1/CVersion.h
ddd7242a6b011095675bc2f0b4017a4003e51f39
[]
no_license
CheretaevIvan/VisualStudioProjects
6f7575c97ead4b118a21d70c5a3ba1895e955cb5
abdcac001e0d73387e2f7a704b8ea69e30ade2be
refs/heads/master
2021-01-10T18:17:30.379719
2016-03-20T21:10:21
2016-03-20T21:10:21
54,338,383
0
0
null
null
null
null
WINDOWS-1251
C++
false
false
2,064
h
CVersion.h
// Автоматически создаваемые классы-оболочки IDispatch, созданные при помощи мастера добавления класса из библиотеки типов #import "C:\\Program Files (x86)\\Microsoft Office\\Office15\\MSWORD.OLB" no_namespace // CVersion класс-оболочка class CVersion : public COleDispatchDriver { public: CVersion(){} // Вызывает конструктор по умолчанию для COleDispatchDriver CVersion(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {} CVersion(const CVersion& dispatchSrc) : COleDispatchDriver(dispatchSrc) {} // Атрибуты public: // Операции public: // Version методы public: LPDISPATCH get_Application() { LPDISPATCH result; InvokeHelper(0x3e8, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL); return result; } long get_Creator() { long result; InvokeHelper(0x3e9, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL); return result; } LPDISPATCH get_Parent() { LPDISPATCH result; InvokeHelper(0x3ea, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL); return result; } CString get_SavedBy() { CString result; InvokeHelper(0x3eb, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL); return result; } CString get_Comment() { CString result; InvokeHelper(0x3ec, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL); return result; } DATE get_Date() { DATE result; InvokeHelper(0x3ed, DISPATCH_PROPERTYGET, VT_DATE, (void*)&result, NULL); return result; } long get_Index() { long result; InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL); return result; } void OpenOld() { InvokeHelper(0x65, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } void Delete() { InvokeHelper(0x66, DISPATCH_METHOD, VT_EMPTY, NULL, NULL); } LPDISPATCH Open() { LPDISPATCH result; InvokeHelper(0x67, DISPATCH_METHOD, VT_DISPATCH, (void*)&result, NULL); return result; } // Version свойства public: };
da79ef9826c03932b5922398daa5d4903b761c31
6a013efbb58fa36c74730ab2829a984805070c97
/src/sortAlgorithms/BubbleSort.h
41bccda688a36a29479e26e3638d1c0702b396bb
[]
no_license
juanpa1220/MPointer
15c392ef02d03b8b31920b7daaf9bde683452203
76f51af895c2a03fa0fc7f9f85a69cc2ce8c1550
refs/heads/master
2020-03-29T04:07:22.312724
2018-10-09T19:26:21
2018-10-09T19:26:21
149,484,033
0
0
null
null
null
null
UTF-8
C++
false
false
404
h
BubbleSort.h
// // Created by Juan Pablo Martínez Brenes on 10/9/18. // #ifndef MPOINTER_BUBBLESORT_H #define MPOINTER_BUBBLESORT_H #include "../dataStructures/DoublyLinkedList.h" class BubbleSort { private: DoublyLinkedList<MPointer<int>> lista; int size; public: BubbleSort(DoublyLinkedList<MPointer<int>> list); void sortList(); void displayList(); }; #endif //MPOINTER_BUBBLESORT_H
f797c1d57d98915b1f9eafa44f74feb60c9b734e
28ce3e11525fd327180b4e51a0fd324d5ba5a2c2
/light.cpp
29c448f5c00952c44803cb755ae575a9ac256dab
[]
no_license
minamiliu/HF21_204_Project
2e155ebb9afeb01590829f5428f76a0979b97fe1
c26c24be165e5f7c6883c0335d67c1a391074938
refs/heads/master
2020-12-02T06:37:57.107066
2017-02-08T06:58:58
2017-02-08T06:58:58
71,750,548
0
0
null
null
null
null
SHIFT_JIS
C++
false
false
3,750
cpp
light.cpp
//============================================ // // タイトル: 未来創造展チーム204 // プログラム名: light.cpp // 作成者: HAL東京ゲーム学科 劉南宏 // 作成日: 2016/11/10 // //============================================ //============================================ //インクルードファイル //============================================ #include "main.h" #include "light.h" #include "renderer.h" #include "manager.h" //============================================ // マクロ定義 //============================================ //============================================ // 静的メンバー変数の初期化 //============================================ CLight *CLight::m_apLight[MAX_LIGHT] = {}; //============================================================================= //コンストラクタ //============================================================================= CLight::CLight() { m_pD3DLight = NULL; for(int cntLight = 0; cntLight < MAX_LIGHT; cntLight++) { if(m_apLight[cntLight] == NULL) { m_apLight[cntLight] = this; m_nID = cntLight; break; } } } //============================================================================= //デストラクタ //============================================================================= CLight::~CLight() { } //============================================================================= //ライト初期化 //============================================================================= HRESULT CLight::Init(D3DXVECTOR3 vecDir, D3DXCOLOR diffuse) { LPDIRECT3DDEVICE9 pDevice; pDevice = CManager::GetRenderer()->GetDevice(); m_pD3DLight = new D3DLIGHT9; // D3DLIGHT9構造体を0でクリアする ZeroMemory( m_pD3DLight, sizeof(D3DLIGHT9)); // ライト0のタイプの設定 m_pD3DLight->Type = D3DLIGHT_DIRECTIONAL; // ライト0の拡散光の設定 m_pD3DLight->Diffuse = diffuse; m_pD3DLight->Ambient = D3DXCOLOR( 0.2f, 0.2f, 0.2f, 0.2f); // ライト0の方向の設定 D3DXVec3Normalize( (D3DXVECTOR3*)&m_pD3DLight->Direction, &vecDir); // ライト0をレンダリングパイプラインに設定 pDevice->SetLight( m_nID, m_pD3DLight); // ライト0を使用使用状態に pDevice->LightEnable( m_nID, TRUE); return S_OK; } //============================================================================= //ライト解放 //============================================================================= void CLight::Uninit(void) { // テクスチャの破棄 if(m_pD3DLight != NULL) { delete m_pD3DLight; m_pD3DLight = NULL; } } //============================================================================= //ライトの生成 //============================================================================= CLight *CLight::Create(D3DXVECTOR3 vecDir, D3DXCOLOR diffuse) { CLight *pLight = new CLight; pLight->Init( vecDir, diffuse); return pLight; } //============================================================================= //総ライトを有効にする //============================================================================= void CLight::SetAllLightOn(void) { LPDIRECT3DDEVICE9 pDevice; pDevice = CManager::GetRenderer()->GetDevice(); // ライティングモードをON pDevice->SetRenderState( D3DRS_LIGHTING, TRUE); } //============================================================================= //総ライトを破棄する //============================================================================= void CLight::ReleaseAll(void) { for(int cntLight = 0; cntLight < MAX_LIGHT; cntLight++) { if(m_apLight[cntLight] != NULL) { m_apLight[cntLight]->Uninit(); m_apLight[cntLight] = NULL; } } }
e7c03d21359c1c9cdc9360a47973dd651958e92a
f9525acb8e5a0f794b079dd90fc573deec9c9e7a
/exotica/include/exotica/Tools/Printable.h
62efb5bc13b044f93079c12bef04813b2fc2d328
[ "BSD-3-Clause" ]
permissive
LongfeiProjects/exotica
068827d6e67fa29998e0a3838eec4477ecdf4963
206b296edf9bf3b653ca3984b1449151ca17d374
refs/heads/master
2020-03-28T16:48:25.583321
2018-09-02T11:29:53
2018-09-03T12:28:36
148,729,994
1
0
null
null
null
null
UTF-8
C++
false
false
3,531
h
Printable.h
#ifndef PRINTABLE_H #define PRINTABLE_H #include <Eigen/Geometry> #include <iostream> #include <kdl/frames.hpp> #include <map> #include <vector> /** * \brief A set of debugging tools: basically these provide easy ways of checking code execution through std::cout prints */ #ifndef __PRETTY_FUNCTION__ #define __PRETTY_FUNCTION__ __func__ #endif #ifdef EXOTICA_DEBUG_MODE #define CHECK_EXECUTION std::cout << "\033[1;32m[EXOTica]:\033[0m Ok in " << __FILE__ << " at line " << __LINE__ << " within function " << __PRETTY_FUNCTION__ << ".\n"; //!< With endline #define INDICATE_FAILURE std::cerr << "\033[1;32m[EXOTica]:\033[0m \033[1;31mFailed in " << __FILE__ << " at line " << __LINE__ << " within function " << __PRETTY_FUNCTION__ << ".\033[0m\n"; //!< With endline #define WARNING(x) std::cout << "\033[1;32m[EXOTica]:\033[0m \033[33mWarning in " << __PRETTY_FUNCTION__ << ": " << x << "\033[0m\n"; //!< With endline #define ERROR(x) std::cerr << "\033[1;32m[EXOTica]:\033[0m \033[1;31mFailed in " << __FILE__ << " at line " << __LINE__ << " within function " << __PRETTY_FUNCTION__ << ".\n" \ << x << "\033[0m\n"; //!< With endline #define INFO(x) std::clog << "\033[1;32m[EXOTica]:\033[0m Info in " << __PRETTY_FUNCTION__ << ": " << x << "\n"; //!< With endline #else #define CHECK_EXECUTION // No operation #define INDICATE_FAILURE std::cerr << "\033[1;32m[EXOTica]:\033[0m \033[1;31mFailed in " << __FILE__ << " at line " << __LINE__ << " within function " << __PRETTY_FUNCTION__ << ".\033[0m\n"; //!< With endline #define WARNING(x) std::cout << "\033[1;32m[EXOTica]:\033[0m \033[33mWarning in " << __PRETTY_FUNCTION__ << ": " << x << "\033[0m\n"; //!< With endline #define ERROR(x) std::cerr << "\033[1;32m[EXOTica]:\033[0m \033[1;31mFailed in " << __FILE__ << " at line " << __LINE__ << " within function " << __PRETTY_FUNCTION__ << ".\n" \ << x << "\033[0m\n"; //!< With endline #define INFO(x) #endif #define HIGHLIGHT(x) std::cout << "\033[1;32m[EXOTica]:\033[0m \033[36m" << x << "\033[0m\n"; #define HIGHLIGHT_NAMED(name, x) std::cout << "\033[1;32m[EXOTica]:\033[0m \033[35m[" << name << "]\033[0m \033[36m" << x << "\033[0m\n"; #define WARNING_NAMED(name, x) std::cout << "\033[1;32m[EXOTica]:\033[0m \033[35m[" << name << "]\033[0m \033[33m" << x << "\033[0m\n"; #define INFO_NAMED(name, x) std::cout << "\033[1;32m[EXOTica]:\033[0m \033[35m[" << name << "]\033[0m " << x << "\n"; #define INFO_PLAIN(x) std::cout << x << "\n"; class Printable { public: virtual void print(std::ostream& os) const = 0; }; std::ostream& operator<<(std::ostream& os, const Printable& s); template <typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& s) { for (auto& p : s) os << p << "\n"; return os; } template <typename I, typename T> std::ostream& operator<<(std::ostream& os, const std::map<I, T>& s) { for (auto& p : s) os << p.first << ": " << p.second << "\n"; return os; } std::string toString(const KDL::Frame& s); std::string toString(const Eigen::Isometry3d& s); std::string toString(const Eigen::Affine3d& s); #endif // PRINTABLE_H
7768a07c2da1db8adc41e3e610afdfa03d5d3bb4
34cd98992c44ffc529f23737bc2858d49fc78e87
/39.cpp
3f72ea0b992a3805b82ce992880cc8cec69e25d7
[]
no_license
AntiParazite/Algorithms
1b5d8372df25c61bcad06eb8a88660d1f4d07442
448239602ac5fd8f8fa5a45572cebb7099fa52b3
refs/heads/master
2020-04-12T16:51:11.667902
2018-12-20T21:43:12
2018-12-20T21:43:12
162,625,937
2
0
null
null
null
null
UTF-8
C++
false
false
740
cpp
39.cpp
#include <stdio.h> #include <stdlib.h> struct Object { int key; struct Object *next; }; struct Object *head = NULL; void Print (void){ struct Object *p; p = head; while (p != NULL){ printf ("->%d",p->key); p = p->next; } printf ("\n"); } void Push (int k){ struct Object *p; p = (struct Object *) malloc(sizeof(struct Object)); p->key = k; p->next = head; head = p; } void Pop (void){ struct Object *p; p = head; head = p->next; free (p); } int main (void){ struct Object *key; Push (1); Print (); Push (4); Print (); Push (16); Print (); Push (9); Print (); Pop (); Print (); getchar(); return 0; }
fd0f5ff74b886b10908eafacf73ba49726da46f4
ac75558b13b1eb5a220ea7b84739c87ad50f6da5
/BAPS/Non Super Boring Substring.cpp
d2ff5c35ca965a395223ab0dfffff992adcbc7d7
[]
no_license
Anik-Modak/CompetitiveProgramming
670a53f323292b16484ca28f340e123e8da8fcff
3fa0b9712f6bb4879d53a066fa16274e480b31a4
refs/heads/master
2022-03-22T06:21:30.654964
2019-12-10T12:58:35
2019-12-10T12:58:35
184,308,402
1
0
null
null
null
null
UTF-8
C++
false
false
701
cpp
Non Super Boring Substring.cpp
//Anik_Modak #include<bits/stdc++.h> using namespace std; bool pallandrome(string s) { string a=s; reverse(a.begin(),a.end()); if(a==s) return 0; else return 1; } int main() { int t,ca; cin>>t; for(int ca=1; ca<=t; ca++) { int n,ans; cin>>n; getchar(); string s; cin>>s; ans=s.size(); for(int i=1; i<n; i++) { for(int j=0; j<s.size()-i; j++) { string sub=s.substr(j,i+1); if(sub.size()==n){ if(pallandrome(sub)) ans++; } else ans++; } } cout<<ans<<endl; } }
23e212b12f95a206a7a3d7888a5277596eddc7bc
6dcc73b950483b31227af567dedafaf8857efe6e
/UI/TextSpeech/textspeech.cpp
84f8364f6e4455a40bcabd300cabe01464fd747a
[]
no_license
jafo2128/hmi_sdk
aef424041261412da51bcbd0fe6262503400cac0
a7065fdda9cbbb486aba3ca54b8dffc31ae579f4
refs/heads/master
2021-01-14T08:55:50.746164
2016-02-06T00:26:35
2016-02-06T00:26:35
48,529,688
0
0
null
2015-12-24T06:54:22
2015-12-24T06:54:22
null
UTF-8
C++
false
false
2,564
cpp
textspeech.cpp
#include "textspeech.h" #include "Config/Config.h" TextSpeech::TextSpeech(QObject *parent) : QObject(parent),_binit(0),_bReading(0) { initSpeech();//初始化语音 } TextSpeech::~TextSpeech() { } #ifdef WIN32 //初始化语音函数 bool TextSpeech::initSpeech() { if(_binit) return true; _binit = this->_voice.setControl("96749377-3391-11D2-9EE3-00C04F797396");//设置COM的名称用来初始化COM的模型,返回是否加载成功 if(_binit) { connect(&this->_voice,SIGNAL(signal(QString, int, void*)), this, SLOT(dealevent(QString, int, void*))); } return _binit; } //文本转语音朗读函数 bool TextSpeech::speak(QString txt) { if(!_binit) return false; int result = this->_voice.dynamicCall("Speak(QString, SpeechVoiceSpeakFlags)", txt ,1).toInt();//执行第一个参数的方法名,以第二个参数返回是否执行成功 _bReading = true; return result;//返回是否执行阅读函数 } //判断语音系统是否运行函数 bool TextSpeech::isSpeaking() { return _bReading; } //设置语音朗读速度-10到10 void TextSpeech::setRate(int rate) { if(!_binit) return; this->_voice.dynamicCall("SetRate(int)", rate); } //设置语音音量0到100 void TextSpeech::setVolume(int value) { if(!_binit) return; this->_voice.dynamicCall("SetVolume(int)", value); } void TextSpeech::dealevent(QString name, int arc , void* argv) { if(name == "EndStream(int,QVariant)") { _bReading = false; emit speakComplete(); } } #else //初始化语音函数 bool TextSpeech::initSpeech() { if(_binit) return true; _voice=new TextToSpeech(TTS_MODE_SPEAK); _binit=true; return true; } //文本转语音朗读函数 bool TextSpeech::speak(QString txt) { LOGI("speak:voice"); if(_voice==NULL) return false; _bReading = true; bool ret= _voice->TextToVoice(txt.toUtf8().data()); _bReading = false; return ret; } //判断语音系统是否运行函数 bool TextSpeech::isSpeaking() { return _bReading; } //设置语音朗读速度-10到10 void TextSpeech::setRate(int rate) { // audioFormat.setSampleRate(rate); } //设置语音音量0到100 void TextSpeech::setVolume(int value) { // if(audioOut==NULL) // return; // audioOut->setVolume(value); } void TextSpeech::dealevent(QString name, int arc , void* argv) { if(name == "EndStream(int,QVariant)") { _bReading = false; emit speakComplete(); } } #endif
e4676069622e5eb2eaa68a533b08a2cd011b0ee2
773a5d4d8705b9ffe0dfcda93095d6a9827cffe8
/timer_buffer.cpp
bd480c3b9d49bd4876f8759dba10ae0f2b155627
[]
no_license
tt-jsr/timer
015cc497072b71f20107f201d9b23d72e8fc25aa
9ab41a1a1204725715ebc5fe21e2c74bc98b9a9c
refs/heads/master
2022-01-27T16:58:48.389954
2021-12-31T18:16:32
2021-12-31T18:16:32
235,155,921
0
0
null
null
null
null
UTF-8
C++
false
false
1,197
cpp
timer_buffer.cpp
#include "timer.h" #include "timer_buffer.h" #define MAX_DIGITS 5 TimerBuffer::TimerBuffer() :pos(0) { memset(buf, 0, BUFFER_SIZE); } void TimerBuffer::addChar(char c) { if (pos == MAX_DIGITS+1) { memmove(buf, buf+1, MAX_DIGITS-1); buf[MAX_DIGITS] = '\0'; --pos; buf[pos] = '\0'; } buf[pos++] = c; buf[pos] = '\0'; } int TimerBuffer::getSeconds() { if (buf[0] == '\0') return 0; int idx = (int)pos-1; int secs = buf[idx] - '0'; --idx; if (idx < 0) return secs; secs += (buf[idx] - '0') * 10; --idx; if (idx < 0) return secs; secs += (buf[idx] - '0') * 60; --idx; if (idx < 0) return secs; secs += (buf[idx] - '0') * 600; --idx; if (idx < 0) return secs; secs += (buf[idx] - '0') * 3600; return secs; } void TimerBuffer::format(char *outbuf, size_t buflen) { int secs = getSeconds(); int hours = secs/3600; secs -= hours*3600; int min = secs/60; secs -= min*60; if (hours) snprintf(outbuf, buflen, "%d:%02d:%02d", hours, min, secs); else snprintf(outbuf, buflen, "%d:%02d", min, secs); }
df65504e4fcdaca8478d9b4b3be8081ae12f0ca3
e37e947fa32a1b29d197bb044d71843a82e5059e
/EventSystem/Button.cpp
39f92b6c37c8e34d32eb9711dd69844d155dd5ef
[]
no_license
aguspoles/EventSystem
d4f6547eb55d6625432dccd87fc0ce36f43726e8
dee6cf51d455e16a28c0687b3c8ec72bb9f4c355
refs/heads/master
2020-09-05T14:43:22.193127
2019-11-07T02:36:04
2019-11-07T02:36:04
220,134,974
0
0
null
null
null
null
UTF-8
C++
false
false
165
cpp
Button.cpp
#include "Button.h" #include "framework.h" #include "Events/KeyEvent.h" void Button::OnButtonPressedEvent() { KeyPressedEvent event(65, 1); callbackFn(event); }
8e6ba07dfaf62932dc44d4143c913fdd0af80aba
2920db67e3abc01c3d5fe8b39d7b1af5726af2f1
/VM.h
63c56a1e2a8f2f30521e6db482b7fddac40a0666
[]
no_license
emfprhs119/OpenMugen
ef0ee7dd19dc813bdf3fa21d2d175962df15fb7b
460dd6a8e37f5b5dfdc7e20774e147ecfc441693
refs/heads/master
2021-01-21T10:38:05.667704
2017-05-25T11:21:37
2017-05-25T11:21:37
87,546,464
1
0
null
2017-04-07T13:06:08
2017-04-07T13:06:07
null
UTF-8
C++
false
false
4,245
h
VM.h
// Open Mugen is a redevelopment of Elecbyte's M.U.G.E.N wich will be 100% compatible to it // Copyright (C) 2004 Sahin Vardar // // If you know bugs or have a wish on Open Muegn or (money/girls/a car) for me ;-) // Feel free and email me: sahin_v@hotmail.com ICQ:317502935 // Web: http://openmugen.sourceforge.net/ // -------------------------------------------------------------------------- // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #ifndef VM_H #define VM_H #define NUMFUNCT 141 class CVirtualMachine { CPlayer *m_pPlayer1,*m_pPlayer2; public: CVirtualMachine(); ~CVirtualMachine(); float Execute(INSTRUCTION *pInst); void PushValue(); void PopValue(); void AddOP(); void SubOP(); void DivOP(); void MulOP(); void EqualOP(); void NotEqual(); void Less(); void Greater(); void LessEqual(); void GreaterEqual(); void InterValOP1(); void InterValOP2(); void InterValOP3(); void InterValOP4(); void InterValOP5(); void InterValOP6(); void InterValOP7(); void InterValOP8(); void LogNot(); void LogAnd(); void LogOr(); void LogXor(); void Not(); void And(); void Or(); void Xor(); void Square(); void Abs(); void Neg(); void Acos(); void Alive(); void Anim(); void AnimElem(); void AnimeElemNo(); void AnimeElemTime(); void AnimExist(); void AnimTime(); void Asin(); void Atan(); void AuthorName(); void BackEdgeBodyDist(); void BackEdgeDist(); void CanRecover(); void Ceil(); void Command(); void Const(); void ConstCoordinate(); void Cos(); void Ctrl(); void DrawGame(); void Exp(); void Facing(); void Floor(); void FrontEdgeBodyDist(); void FrontEdgeDist(); void FVar(); void GameTime(); void GetHitVar(); void HitCount(); //void HitDefAttr() void HitFall(); void HitOver(); void HitPauseTime(); void HitShakeOver(); void HitVel(); void PlayerIdent(); void IfElse(); void InGuardDist(); void IsHelper(); void IsHomeTeam(); void Life(); void LifeMax(); void LogN(); void Log(); void Lose(); void MatchNo(); void MatchOver(); void MoveContact(); void MoveGuarded(); void MoveHit(); void MoveType(); void MoveReversed(); void Name(); void NumEnemy(); void NumExplod(); void NumHelper(); void NumPartner(); void NumProj(); void NumProjID(); void NumTarget(); void P1Name(); void P2BodyDist(); void P2Dist(); void P2Life(); void P2MoveType(); void P2Name(); void P2StateNo(); void P2StateType(); void P3Name(); void P4Name(); void PalNo(); void ParentDist(); void Pi(); void PlayerIDExist(); void PrevStateNo(); void Pos(); void Power(); void PowerMax(); void ProjCancelTime(); void Random(); void RootDist(); void RoundNo(); void RoundsExisted(); void RoundState(); void ScreenPos(); void SelfAnimExist(); void Sin(); void StateNo(); void StateType(); void SysFVar(); void SysVar(); void Tan(); void TeamMode(); void TeamSide(); void TicksPerSecond(); void Time(); void UniqHitCount(); void Var(); void Vel(); void Win(); void ProjContact(); void ProjContactTime(); void ProjGuarded(); void ProjGuardedTime(); void NOP(){}; void MODOP(); //helper functions void Save(); void Restore(); void InitFunctTable(); void SetPlayers(CPlayer *p1,CPlayer *p2); //variables CStack m_Stack; int nCurrentIns; INSTRUCTION *pCurrentIns; Stacktype m_pop; float temp1,temp2,temp3; float nSave; //pointer to player void *m_p1; void *m_p2; typedef void (CVirtualMachine::*pt2Member)(); pt2Member pFuncTable[NUMFUNCT]; }; #endif
2307351f6750a999755020be1a80423e860a87a9
7d55ba65045b4bfa6265dd15195ddcbd42291434
/MINGW&c++/58.cpp
c62b472b3f3533423a4eae5c9ef20255074a58dc
[]
no_license
LinggYuu/shua-ti
5bbb114de1c6987df0dd4ca7430893e407053cde
7c83f6f567afa9dfce4cc0f54b3d176d8e7887f1
refs/heads/master
2021-06-20T09:03:42.710842
2021-03-17T17:24:25
2021-03-17T17:24:25
196,388,378
1
0
null
null
null
null
UTF-8
C++
false
false
571
cpp
58.cpp
// p1031 #include<iostream> #include<algorithm> using namespace std; int N; int card[101]; int cnt; int main() { int ave; cin>>N; for(int i=1;i<=N;i++) { cin>>card[i]; ave+=card[i]; } ave/=N; for(int i=1;i<N;i++) { if(card[i]==ave) continue; else if(card[i]<ave) { card[i+1]-=ave-card[i]; cnt++; } else { card[i+1]+=(card[i]-ave); cnt++; } } cout<<cnt; system("pause"); return 0; }
fac9eb1b756d242c180a617fd47b477fa350ac1d
685dfa51cd8bf245362bff705e3a27f619103eed
/Engine/game-item.cpp
fd782b472a5a697873d5bb54222c56b7436c5920
[]
no_license
gboyle/gargle
5b3c3068dcbb53e33e29bef8dd2704dcd5d7f1ee
978752d2b9c3a991221f0d8b7348641536f0bfe5
refs/heads/master
2020-03-27T06:22:46.917716
2018-08-29T04:32:50
2018-08-29T04:32:50
146,101,291
0
0
null
null
null
null
UTF-8
C++
false
false
11,094
cpp
game-item.cpp
#include "game-item.h" #include "game-util.h" Item::Item(std::mt19937 &gen) { std::uniform_int_distribution<> dis_x(0, Graphics::ScreenWidth - w); std::uniform_int_distribution<> dis_y(0, Graphics::ScreenHeight - h); std::uniform_int_distribution<> dis_v(-3, 3); x = dis_x(gen); y = dis_y(gen); dx = dis_v(gen); dy = dis_v(gen); } void Item::move() { x += dx; y += dy; if (!inside(x, 0, Graphics::ScreenWidth - w)) { dx = -dx; x += dx; } if (!inside(y, 0, Graphics::ScreenHeight - h)) { dy = -dy; y += dy; } } Extent Item::extent() const { return {x, x + w, y, y + h}; } void Item::draw(Graphics &gfx) const { gfx.PutPixel(14 + x, 0 + y, 138, 77, 0); gfx.PutPixel(7 + x, 1 + y, 138, 77, 0); gfx.PutPixel(13 + x, 1 + y, 138, 77, 0); gfx.PutPixel(20 + x, 1 + y, 138, 77, 0); gfx.PutPixel(6 + x, 2 + y, 138, 77, 0); gfx.PutPixel(13 + x, 2 + y, 138, 77, 0); gfx.PutPixel(20 + x, 2 + y, 138, 77, 0); gfx.PutPixel(6 + x, 3 + y, 138, 77, 0); gfx.PutPixel(6 + x, 4 + y, 138, 77, 0); gfx.PutPixel(14 + x, 4 + y, 138, 77, 0); gfx.PutPixel(21 + x, 4 + y, 138, 77, 0); gfx.PutPixel(7 + x, 5 + y, 138, 77, 0); gfx.PutPixel(13 + x, 5 + y, 138, 77, 0); gfx.PutPixel(21 + x, 5 + y, 138, 77, 0); gfx.PutPixel(7 + x, 6 + y, 138, 77, 0); gfx.PutPixel(20 + x, 6 + y, 138, 77, 0); gfx.PutPixel(6 + x, 7 + y, 138, 77, 0); gfx.PutPixel(14 + x, 7 + y, 51, 28, 0); gfx.PutPixel(15 + x, 7 + y, 51, 28, 0); gfx.PutPixel(20 + x, 7 + y, 138, 77, 0); gfx.PutPixel(12 + x, 8 + y, 51, 28, 0); gfx.PutPixel(13 + x, 8 + y, 51, 28, 0); gfx.PutPixel(14 + x, 8 + y, 51, 28, 0); gfx.PutPixel(7 + x, 9 + y, 138, 77, 0); gfx.PutPixel(11 + x, 9 + y, 51, 28, 0); gfx.PutPixel(12 + x, 9 + y, 102, 57, 0); gfx.PutPixel(13 + x, 9 + y, 138, 77, 0); gfx.PutPixel(14 + x, 9 + y, 138, 77, 0); gfx.PutPixel(15 + x, 9 + y, 51, 28, 0); gfx.PutPixel(21 + x, 9 + y, 138, 77, 0); gfx.PutPixel(10 + x, 10 + y, 51, 28, 0); gfx.PutPixel(11 + x, 10 + y, 51, 28, 0); gfx.PutPixel(12 + x, 10 + y, 102, 57, 0); gfx.PutPixel(13 + x, 10 + y, 138, 77, 0); gfx.PutPixel(14 + x, 10 + y, 138, 77, 0); gfx.PutPixel(15 + x, 10 + y, 51, 28, 0); gfx.PutPixel(20 + x, 10 + y, 138, 77, 0); gfx.PutPixel(9 + x, 11 + y, 51, 28, 0); gfx.PutPixel(10 + x, 11 + y, 138, 77, 0); gfx.PutPixel(11 + x, 11 + y, 138, 77, 0); gfx.PutPixel(12 + x, 11 + y, 51, 28, 0); gfx.PutPixel(13 + x, 11 + y, 51, 28, 0); gfx.PutPixel(14 + x, 11 + y, 51, 28, 0); gfx.PutPixel(15 + x, 11 + y, 51, 28, 0); gfx.PutPixel(16 + x, 11 + y, 51, 28, 0); gfx.PutPixel(9 + x, 12 + y, 51, 28, 0); gfx.PutPixel(10 + x, 12 + y, 138, 77, 0); gfx.PutPixel(11 + x, 12 + y, 138, 77, 0); gfx.PutPixel(12 + x, 12 + y, 111, 62, 0); gfx.PutPixel(13 + x, 12 + y, 102, 57, 0); gfx.PutPixel(14 + x, 12 + y, 102, 57, 0); gfx.PutPixel(15 + x, 12 + y, 102, 57, 0); gfx.PutPixel(16 + x, 12 + y, 51, 28, 0); gfx.PutPixel(9 + x, 13 + y, 51, 28, 0); gfx.PutPixel(10 + x, 13 + y, 109, 61, 0); gfx.PutPixel(11 + x, 13 + y, 138, 77, 0); gfx.PutPixel(12 + x, 13 + y, 138, 77, 0); gfx.PutPixel(13 + x, 13 + y, 138, 77, 0); gfx.PutPixel(14 + x, 13 + y, 138, 77, 0); gfx.PutPixel(15 + x, 13 + y, 138, 77, 0); gfx.PutPixel(16 + x, 13 + y, 51, 28, 0); gfx.PutPixel(5 + x, 14 + y, 51, 28, 0); gfx.PutPixel(7 + x, 14 + y, 51, 28, 0); gfx.PutPixel(8 + x, 14 + y, 51, 28, 0); gfx.PutPixel(9 + x, 14 + y, 51, 28, 0); gfx.PutPixel(10 + x, 14 + y, 51, 28, 0); gfx.PutPixel(11 + x, 14 + y, 138, 77, 0); gfx.PutPixel(12 + x, 14 + y, 138, 77, 0); gfx.PutPixel(13 + x, 14 + y, 138, 77, 0); gfx.PutPixel(14 + x, 14 + y, 138, 77, 0); gfx.PutPixel(15 + x, 14 + y, 138, 77, 0); gfx.PutPixel(16 + x, 14 + y, 51, 28, 0); gfx.PutPixel(4 + x, 15 + y, 51, 28, 0); gfx.PutPixel(5 + x, 15 + y, 138, 77, 0); gfx.PutPixel(6 + x, 15 + y, 51, 28, 0); gfx.PutPixel(7 + x, 15 + y, 116, 65, 0); gfx.PutPixel(8 + x, 15 + y, 138, 77, 0); gfx.PutPixel(9 + x, 15 + y, 138, 77, 0); gfx.PutPixel(10 + x, 15 + y, 138, 77, 0); gfx.PutPixel(11 + x, 15 + y, 51, 28, 0); gfx.PutPixel(12 + x, 15 + y, 51, 28, 0); gfx.PutPixel(13 + x, 15 + y, 51, 28, 0); gfx.PutPixel(14 + x, 15 + y, 51, 28, 0); gfx.PutPixel(15 + x, 15 + y, 51, 28, 0); gfx.PutPixel(16 + x, 15 + y, 51, 28, 0); gfx.PutPixel(17 + x, 15 + y, 51, 28, 0); gfx.PutPixel(18 + x, 15 + y, 51, 28, 0); gfx.PutPixel(1 + x, 16 + y, 51, 28, 0); gfx.PutPixel(2 + x, 16 + y, 51, 28, 0); gfx.PutPixel(3 + x, 16 + y, 51, 28, 0); gfx.PutPixel(4 + x, 16 + y, 51, 28, 0); gfx.PutPixel(5 + x, 16 + y, 138, 77, 0); gfx.PutPixel(6 + x, 16 + y, 51, 28, 0); gfx.PutPixel(7 + x, 16 + y, 116, 65, 0); gfx.PutPixel(8 + x, 16 + y, 138, 77, 0); gfx.PutPixel(9 + x, 16 + y, 138, 77, 0); gfx.PutPixel(10 + x, 16 + y, 138, 77, 0); gfx.PutPixel(11 + x, 16 + y, 138, 77, 0); gfx.PutPixel(12 + x, 16 + y, 138, 77, 0); gfx.PutPixel(13 + x, 16 + y, 109, 61, 0); gfx.PutPixel(14 + x, 16 + y, 51, 28, 0); gfx.PutPixel(15 + x, 16 + y, 138, 77, 0); gfx.PutPixel(16 + x, 16 + y, 138, 77, 0); gfx.PutPixel(17 + x, 16 + y, 138, 77, 0); gfx.PutPixel(18 + x, 16 + y, 123, 69, 0); gfx.PutPixel(19 + x, 16 + y, 51, 28, 0); gfx.PutPixel(0 + x, 17 + y, 51, 28, 0); gfx.PutPixel(1 + x, 17 + y, 87, 49, 0); gfx.PutPixel(2 + x, 17 + y, 87, 49, 0); gfx.PutPixel(3 + x, 17 + y, 87, 49, 0); gfx.PutPixel(4 + x, 17 + y, 87, 49, 0); gfx.PutPixel(5 + x, 17 + y, 51, 28, 0); gfx.PutPixel(6 + x, 17 + y, 51, 28, 0); gfx.PutPixel(7 + x, 17 + y, 43, 24, 0); gfx.PutPixel(8 + x, 17 + y, 51, 28, 0); gfx.PutPixel(9 + x, 17 + y, 51, 28, 0); gfx.PutPixel(10 + x, 17 + y, 51, 28, 0); gfx.PutPixel(11 + x, 17 + y, 51, 28, 0); gfx.PutPixel(12 + x, 17 + y, 51, 28, 0); gfx.PutPixel(13 + x, 17 + y, 40, 22, 0); gfx.PutPixel(14 + x, 17 + y, 51, 28, 0); gfx.PutPixel(15 + x, 17 + y, 138, 77, 0); gfx.PutPixel(16 + x, 17 + y, 138, 77, 0); gfx.PutPixel(17 + x, 17 + y, 138, 77, 0); gfx.PutPixel(18 + x, 17 + y, 123, 69, 0); gfx.PutPixel(19 + x, 17 + y, 51, 28, 0); gfx.PutPixel(0 + x, 18 + y, 51, 28, 0); gfx.PutPixel(1 + x, 18 + y, 138, 77, 0); gfx.PutPixel(2 + x, 18 + y, 138, 77, 0); gfx.PutPixel(3 + x, 18 + y, 138, 77, 0); gfx.PutPixel(4 + x, 18 + y, 138, 77, 0); gfx.PutPixel(5 + x, 18 + y, 51, 28, 0); gfx.PutPixel(6 + x, 18 + y, 51, 28, 0); gfx.PutPixel(7 + x, 18 + y, 51, 28, 0); gfx.PutPixel(8 + x, 18 + y, 51, 28, 0); gfx.PutPixel(9 + x, 18 + y, 51, 28, 0); gfx.PutPixel(10 + x, 18 + y, 51, 28, 0); gfx.PutPixel(11 + x, 18 + y, 51, 28, 0); gfx.PutPixel(12 + x, 18 + y, 51, 28, 0); gfx.PutPixel(13 + x, 18 + y, 51, 28, 0); gfx.PutPixel(14 + x, 18 + y, 51, 28, 0); gfx.PutPixel(15 + x, 18 + y, 138, 77, 0); gfx.PutPixel(16 + x, 18 + y, 138, 77, 0); gfx.PutPixel(17 + x, 18 + y, 138, 77, 0); gfx.PutPixel(18 + x, 18 + y, 123, 69, 0); gfx.PutPixel(19 + x, 18 + y, 51, 28, 0); gfx.PutPixel(20 + x, 18 + y, 51, 28, 0); gfx.PutPixel(21 + x, 18 + y, 51, 28, 0); gfx.PutPixel(22 + x, 18 + y, 51, 28, 0); gfx.PutPixel(0 + x, 19 + y, 51, 28, 0); gfx.PutPixel(1 + x, 19 + y, 138, 77, 0); gfx.PutPixel(2 + x, 19 + y, 138, 77, 0); gfx.PutPixel(3 + x, 19 + y, 138, 77, 0); gfx.PutPixel(4 + x, 19 + y, 138, 77, 0); gfx.PutPixel(5 + x, 19 + y, 51, 28, 0); gfx.PutPixel(6 + x, 19 + y, 138, 77, 0); gfx.PutPixel(7 + x, 19 + y, 138, 77, 0); gfx.PutPixel(8 + x, 19 + y, 138, 77, 0); gfx.PutPixel(9 + x, 19 + y, 138, 77, 0); gfx.PutPixel(10 + x, 19 + y, 138, 77, 0); gfx.PutPixel(11 + x, 19 + y, 138, 77, 0); gfx.PutPixel(12 + x, 19 + y, 138, 77, 0); gfx.PutPixel(13 + x, 19 + y, 138, 77, 0); gfx.PutPixel(14 + x, 19 + y, 138, 77, 0); gfx.PutPixel(15 + x, 19 + y, 138, 77, 0); gfx.PutPixel(16 + x, 19 + y, 138, 77, 0); gfx.PutPixel(17 + x, 19 + y, 138, 77, 0); gfx.PutPixel(18 + x, 19 + y, 123, 69, 0); gfx.PutPixel(19 + x, 19 + y, 51, 28, 0); gfx.PutPixel(20 + x, 19 + y, 138, 77, 0); gfx.PutPixel(21 + x, 19 + y, 138, 77, 0); gfx.PutPixel(22 + x, 19 + y, 65, 36, 0); gfx.PutPixel(23 + x, 19 + y, 51, 28, 0); gfx.PutPixel(1 + x, 20 + y, 51, 28, 0); gfx.PutPixel(2 + x, 20 + y, 51, 28, 0); gfx.PutPixel(3 + x, 20 + y, 51, 28, 0); gfx.PutPixel(4 + x, 20 + y, 51, 28, 0); gfx.PutPixel(5 + x, 20 + y, 51, 28, 0); gfx.PutPixel(6 + x, 20 + y, 138, 77, 0); gfx.PutPixel(7 + x, 20 + y, 138, 77, 0); gfx.PutPixel(8 + x, 20 + y, 138, 77, 0); gfx.PutPixel(9 + x, 20 + y, 138, 77, 0); gfx.PutPixel(10 + x, 20 + y, 138, 77, 0); gfx.PutPixel(11 + x, 20 + y, 138, 77, 0); gfx.PutPixel(12 + x, 20 + y, 138, 77, 0); gfx.PutPixel(13 + x, 20 + y, 138, 77, 0); gfx.PutPixel(14 + x, 20 + y, 138, 77, 0); gfx.PutPixel(15 + x, 20 + y, 138, 77, 0); gfx.PutPixel(16 + x, 20 + y, 138, 77, 0); gfx.PutPixel(17 + x, 20 + y, 138, 77, 0); gfx.PutPixel(18 + x, 20 + y, 123, 69, 0); gfx.PutPixel(19 + x, 20 + y, 51, 28, 0); gfx.PutPixel(20 + x, 20 + y, 138, 77, 0); gfx.PutPixel(21 + x, 20 + y, 138, 77, 0); gfx.PutPixel(22 + x, 20 + y, 65, 36, 0); gfx.PutPixel(23 + x, 20 + y, 51, 28, 0); gfx.PutPixel(0 + x, 21 + y, 51, 28, 0); gfx.PutPixel(1 + x, 21 + y, 138, 77, 0); gfx.PutPixel(2 + x, 21 + y, 138, 77, 0); gfx.PutPixel(3 + x, 21 + y, 138, 77, 0); gfx.PutPixel(4 + x, 21 + y, 138, 77, 0); gfx.PutPixel(5 + x, 21 + y, 138, 77, 0); gfx.PutPixel(6 + x, 21 + y, 51, 28, 0); gfx.PutPixel(7 + x, 21 + y, 51, 28, 0); gfx.PutPixel(8 + x, 21 + y, 51, 28, 0); gfx.PutPixel(9 + x, 21 + y, 51, 28, 0); gfx.PutPixel(10 + x, 21 + y, 51, 28, 0); gfx.PutPixel(11 + x, 21 + y, 51, 28, 0); gfx.PutPixel(12 + x, 21 + y, 51, 28, 0); gfx.PutPixel(13 + x, 21 + y, 51, 28, 0); gfx.PutPixel(14 + x, 21 + y, 51, 28, 0); gfx.PutPixel(15 + x, 21 + y, 51, 28, 0); gfx.PutPixel(16 + x, 21 + y, 51, 28, 0); gfx.PutPixel(17 + x, 21 + y, 51, 28, 0); gfx.PutPixel(18 + x, 21 + y, 51, 28, 0); gfx.PutPixel(20 + x, 21 + y, 51, 28, 0); gfx.PutPixel(21 + x, 21 + y, 51, 28, 0); gfx.PutPixel(22 + x, 21 + y, 51, 28, 0); gfx.PutPixel(0 + x, 22 + y, 51, 28, 0); gfx.PutPixel(1 + x, 22 + y, 65, 36, 0); gfx.PutPixel(2 + x, 22 + y, 65, 36, 0); gfx.PutPixel(3 + x, 22 + y, 65, 36, 0); gfx.PutPixel(4 + x, 22 + y, 65, 36, 0); gfx.PutPixel(5 + x, 22 + y, 65, 36, 0); gfx.PutPixel(6 + x, 22 + y, 51, 28, 0); gfx.PutPixel(1 + x, 23 + y, 51, 28, 0); gfx.PutPixel(2 + x, 23 + y, 51, 28, 0); gfx.PutPixel(3 + x, 23 + y, 51, 28, 0); gfx.PutPixel(4 + x, 23 + y, 51, 28, 0); gfx.PutPixel(5 + x, 23 + y, 51, 28, 0); gfx.PutPixel(6 + x, 23 + y, 51, 28, 0); }
5da49470ed198701d20a8e7649da20b9f3385d00
7cb2ae97bbf6a6d2dfef73735391b4f7c070d6be
/sample/Project.hpp
ef92ef7ef5fe044868be7e59672c6231ff6ae7a0
[]
no_license
anybirds/NewbieHeaderTool
f40fd27bbeda361925f076d9f75903a51bcec8b5
21d5c9e4413072e4a4a862b1374bc068a6a64b72
refs/heads/master
2023-03-26T10:37:47.169615
2021-03-27T15:23:16
2021-03-27T15:23:16
349,009,244
0
0
null
null
null
null
UTF-8
C++
false
false
3,062
hpp
Project.hpp
#if defined(_MSC_VER) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) #include <Windows.h> #else #include <dlfcn.h> #endif #pragma once #include <iostream> #include <cstdint> #include <string> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <vector> #include <nlohmann/json.hpp> #include <Entity.hpp> #include <Asset.hpp> #include <Type.hpp> namespace Engine { class ENGINE_EXPORT [[Serialize]] ProjectSetting final : public Entity { TYPE(ProjectSetting) private: uint64_t serial; int startSceneIndex; public: uint64_t GetSerial() { return ++serial; } int GetStartSceneIndex() const { return startSceneIndex; } void SetStartSceneIndex(int startScene) { this->startSceneIndex = startSceneIndex; } friend class Project; }; /* Abstraction of a user project that includes User module, used Assets, and Scenes. */ class ENGINE_EXPORT Project final { public: static Project &GetInstance() { static Project project; return project; } static bool Load(const std::string &path); static bool Save(); static void Close(); private: Project() {} typedef void (*func)(); #if defined(_MSC_VER) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) HINSTANCE lib; #else void *lib; #endif func init; func clear; std::string path; std::string name; std::string directory; std::string libpath; ProjectSetting *setting; std::vector<std::string> scenes; std::unordered_map<uint64_t, Asset *> assets; std::unordered_set<Asset *> garbages; public: Project(const Project &) = delete; void operator=(const Project &) = delete; const std::string &GetName() const { return name; } const std::string &GetDirectoy() const { return directory; } ProjectSetting *GetSetting() const { return setting; } const std::string &GetScene(int index) const; void AddScene(const std::string &path); void RemoveScene(int index); template <class T, std::enable_if_t<std::is_base_of_v<Asset, T>, bool> = true> T *GetAsset(uint64_t serial) const { auto it = assets.find(serial); if (it != assets.end()) { return dynamic_cast<T *>(it->second); } else { return nullptr; } } template <class T, std::enable_if_t<std::is_base_of_v<Asset, T>, bool> = true> T *AddAsset() { T *asset = new T(); asset->serial = setting->GetSerial(); assets.insert({asset->serial, asset}); return asset; } void RemoveAsset(Asset *asset); friend class Scene; }; }
1e402a0e283c10d93356c3b775885f7566a0ca55
e2d31e3754624eeb0a2dace8691c5c25ed3b988e
/runtime/Math/Ray.cpp
4052a3ff0dd9e519e499c98e38cf7301a8e3490f
[ "MIT" ]
permissive
PanosK92/SpartanEngine
da7950d3e5a673b3fd7881c6e9370d84c8e361a1
9cf38d84c344dad43a2cb45f018914f7504f1047
refs/heads/master
2023-09-01T09:01:47.784814
2023-08-24T09:42:53
2023-08-24T09:42:53
61,415,047
1,655
169
MIT
2023-09-11T15:08:52
2016-06-18T03:27:49
C++
ISO-8859-1
C++
false
false
9,194
cpp
Ray.cpp
/* Copyright(c) 2016-2023 Panos Karabelas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions : The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ //= INCLUDES ======= #include "pch.h" //================== //= NAMESPACES ===== using namespace std; //================== namespace Spartan::Math { Ray::Ray(const Vector3& start, const Vector3& direction) { m_origin = start; m_direction = direction.Normalized(); } float Ray::HitDistance(const BoundingBox& box) const { // If undefined, no hit (infinite distance) if (box == BoundingBox::Undefined) return Helper::INFINITY_; // Check for ray origin being inside the box if (box.IsInside(m_origin) == Intersection::Inside) return 0.0f; float distance = Helper::INFINITY_; // Check for intersecting in the X-direction if (m_origin.x < box.GetMin().x && m_direction.x > 0.0f) { const float x = (box.GetMin().x - m_origin.x) / m_direction.x; if (x < distance) { const Vector3 point = m_origin + x * m_direction; if (point.y >= box.GetMin().y && point.y <= box.GetMax().y && point.z >= box.GetMin().z && point.z <= box.GetMax().z) { distance = x; } } } if (m_origin.x > box.GetMax().x && m_direction.x < 0.0f) { const float x = (box.GetMax().x - m_origin.x) / m_direction.x; if (x < distance) { const Vector3 point = m_origin + x * m_direction; if (point.y >= box.GetMin().y && point.y <= box.GetMax().y && point.z >= box.GetMin().z && point.z <= box.GetMax().z) { distance = x; } } } // Check for intersecting in the Y-direction if (m_origin.y < box.GetMin().y && m_direction.y > 0.0f) { const float x = (box.GetMin().y - m_origin.y) / m_direction.y; if (x < distance) { const Vector3 point = m_origin + x * m_direction; if (point.x >= box.GetMin().x && point.x <= box.GetMax().x && point.z >= box.GetMin().z && point.z <= box.GetMax().z) { distance = x; } } } if (m_origin.y > box.GetMax().y && m_direction.y < 0.0f) { const float x = (box.GetMax().y - m_origin.y) / m_direction.y; if (x < distance) { const Vector3 point = m_origin + x * m_direction; if (point.x >= box.GetMin().x && point.x <= box.GetMax().x && point.z >= box.GetMin().z && point.z <= box.GetMax().z) { distance = x; } } } // Check for intersecting in the Z-direction if (m_origin.z < box.GetMin().z && m_direction.z > 0.0f) { const float x = (box.GetMin().z - m_origin.z) / m_direction.z; if (x < distance) { const Vector3 point = m_origin + x * m_direction; if (point.x >= box.GetMin().x && point.x <= box.GetMax().x && point.y >= box.GetMin().y && point.y <= box.GetMax().y) { distance = x; } } } if (m_origin.z > box.GetMax().z && m_direction.z < 0.0f) { const float x = (box.GetMax().z - m_origin.z) / m_direction.z; if (x < distance) { const Vector3 point = m_origin + x * m_direction; if (point.x >= box.GetMin().x && point.x <= box.GetMax().x && point.y >= box.GetMin().y && point.y <= box.GetMax().y) { distance = x; } } } return distance; } float Ray::HitDistance(const Plane& plane, Vector3* intersection_point /*= nullptr*/) const { float d = plane.normal.Dot(m_direction); if (Helper::Abs(d) >= Helper::EPSILON) { float t = -(plane.normal.Dot(m_origin) + plane.d) / d; if (t >= 0.0f) { if (intersection_point) { *intersection_point = m_origin + t * m_direction; } return t; } else { return Helper::INFINITY_; } } else { return Helper::INFINITY_; } } float Ray::HitDistance(const Vector3& v1, const Vector3& v2, const Vector3& v3, Vector3* out_normal /*= nullptr*/, Vector3* out_bary /*= nullptr*/) const { // Based on Fast, Minimum Storage Ray/Triangle Intersection by Möller & Trumbore // http://www.graphics.cornell.edu/pubs/1997/MT97.pdf // Calculate edge vectors Vector3 edge1(v2 - v1); Vector3 edge2(v3 - v1); // Calculate determinant & check backfacing Vector3 p(m_direction.Cross(edge2)); float det = edge1.Dot(p); if (det >= Helper::EPSILON) { // Calculate u & v parameters and test Vector3 t(m_origin - v1); float u = t.Dot(p); if (u >= 0.0f && u <= det) { Vector3 q(t.Cross(edge1)); float v = m_direction.Dot(q); if (v >= 0.0f && u + v <= det) { float distance = edge2.Dot(q) / det; // Discard hits behind the ray if (distance >= 0.0f) { // There is an intersection, so calculate distance & optional normal if (out_normal) *out_normal = edge1.Cross(edge2); if (out_bary) *out_bary = Vector3(1 - (u / det) - (v / det), u / det, v / det); return distance; } } } } return Helper::INFINITY_; } float Ray::HitDistance(const Sphere& sphere) const { Vector3 centeredOrigin = m_origin - sphere.center; float squaredRadius = sphere.radius * sphere.radius; // Check if ray originates inside the sphere if (centeredOrigin.LengthSquared() <= squaredRadius) return 0.0f; // Calculate intersection by quadratic equation float a = m_direction.Dot(m_direction); float b = 2.0f * centeredOrigin.Dot(m_direction); float c = centeredOrigin.Dot(centeredOrigin) - squaredRadius; float d = b * b - 4.0f * a * c; // No solution if (d < 0.0f) return Helper::INFINITY_; // Get the nearer solution float dSqrt = sqrtf(d); float dist = (-b - dSqrt) / (2.0f * a); if (dist >= 0.0f) return dist; else return (-b + dSqrt) / (2.0f * a); } float Ray::Distance(const Vector3& point) const { const Vector3 closest_point = m_origin + (m_direction * (point - m_origin).Dot(m_direction)); return (closest_point - point).Length(); } float Ray::Distance(const Vector3& point, Vector3& closest_point) const { closest_point = m_origin + (m_direction * (point - m_origin).Dot(m_direction)); return (closest_point - point).Length(); } Vector3 Ray::ClosestPoint(const Ray& ray) const { // Algorithm based on http://paulbourke.net/geometry/lineline3d/ Vector3 p13 = m_origin - ray.m_origin; Vector3 p43 = ray.m_direction; Vector3 p21 = m_direction; float d1343 = p13.Dot(p43); float d4321 = p43.Dot(p21); float d1321 = p13.Dot(p21); float d4343 = p43.Dot(p43); float d2121 = p21.Dot(p21); float d = d2121 * d4343 - d4321 * d4321; if (Helper::Abs(d) < Helper::EPSILON) return m_origin; float n = d1343 * d4321 - d1321 * d4343; float a = n / d; return m_origin + a * m_direction; } }
2ecf6c17b0ed580dbc655b5cedd9f5f0403005bb
460c21d3edb583d70dd369b5cc44fd91f0b9fbc1
/dz25.1/dz25.1/dz25_1.cpp
af55e218bf44a2d553efa600bee4cff95fac227f
[]
no_license
makmen/cpp
37eded00ddb29967f352735f90786fd107ddb90a
8944815432b4e319059367a3f2dbe46bc0e486e5
refs/heads/master
2021-01-02T09:15:20.321423
2015-08-23T05:27:18
2015-08-23T05:27:18
35,114,881
1
0
null
null
null
null
UTF-8
C++
false
false
1,767
cpp
dz25_1.cpp
#include <iostream> using namespace std; class complex { double x; double y; public: complex(double _x, double _y) : x(_x), y(_y) { } complex(double _x) : x(_x), y(0) { } complex(const complex &obj) { x = obj.x; y = obj.y; } complex& operator = (const complex &obj) { if (this != &obj) { x = obj.x; y = obj.y; } return *this; } complex operator + (const complex &obj) { complex temp(x, y); temp.x = x + obj.x; temp.y = y + obj.y; return temp; } complex& operator += (double a) { x += a; return *this; } complex operator - (const complex &obj) { complex temp(x, y); temp.x = x - obj.x; temp.y = y - obj.y; return temp; } complex& operator -= (double a) { x -= a; return *this; } complex operator * (const complex &obj) { complex temp(x, y); temp.x = x * obj.x - y * obj.y; temp.y = x * obj.y + y * obj.x; return temp; } complex& operator *= (double a) { x *= a; y *= a; return *this; } complex operator / (const complex &obj) { complex temp(x, y); temp.x = (x * obj.x + y * obj.y) / (obj.x * obj.x + obj.y * obj.y); temp.y = (y * obj.x - x * obj.y) / (obj.x * obj.x + obj.y * obj.y); return temp; } complex& operator /= (double a) { x /= a; y /= a; return *this; } bool operator == (const complex &obj) { bool flag = false; if (x == obj.x && y == obj.y) { flag = true; } return flag; } void show() { cout << x; if (y >= 0) cout << " + i * " << y; else cout << " - i * " << y*(-1); cout << "\n"; } }; int main() { complex c1(5, 3); complex c2(5, -3); complex c3(4, -2); complex c4(1, 0); if (c1 == c2) { c1.show(); c2.show(); } c1.show(); c2.show(); c3.show(); c4.show(); return 0; }
9f13d1366280f58c2b36482907d2114db6fc0b64
c699171546a86547c3a069d0598d632756b6b9fc
/player.cpp
8619c3e3d0dba3b7d1fcfb1a821821c08ab28e2f
[]
no_license
neurocase/GLDrive2
f58323c9ed6647b4f2610aef2027912f7c16ca72
0b3bfaf229960f0bb61bf0011f4c7e633b3f1edc
refs/heads/master
2020-04-23T08:28:35.710546
2014-05-18T07:41:57
2014-05-18T07:41:57
null
0
0
null
null
null
null
UTF-8
C++
false
false
301
cpp
player.cpp
#include "include.h" #include "player.h" Player::Player(){ rotdir = 0; engineforce = 0; xpos = 0; ypos = 0; width = 0; height = 0; rot = 0; accel = 0; velx = 0; vely = 0; totvel =0; viewspeeddist=0; throttle = false; brake = false; hbrake = false; } Player::~Player(){ }
f4fb11b0190b0eb31c6a6ee4ee8261032f83b426
75bc948f21807a59207d510747fd5641a2dc9f59
/20151005_CommonTool/Modules/DialogControllers/SODlg.h
da83b1778c10f1d80a4896f15d97325c8f75d1c0
[]
no_license
EmbeddedSystemClass/U24
665a7211b790cd08035d7719775c58f0bc15072b
de2ef2884ad1a8a07df3a444d1db9f13a921a774
refs/heads/master
2021-06-15T09:40:47.079680
2016-09-14T12:29:57
2016-09-20T06:53:19
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,232
h
SODlg.h
#ifndef __SO_DLG__H__ #define __SO_DLG__H__ #pragma once #include <string> #include "afxwin.h" #include "..\DialogResources\resource.h" // CSODlg dialog /* #define IDD_SO_DIALOG_DIALOGS_DLL 101 #define IDD_LARGE_MSG_DIALOG_DIALOGS_DLL 102 #define IDS_APP_TITLE 103 #define IDC_SO_STATIC_DIALOGS_DLL 1000 #define IDC_FACTORYINFO_STATIC_DIALOGS_DLL 1001 #define IDC_EMPLOYEE_STATIC_DIALOGS_DLL 1002 #define IDC_SO_EDIT_DIALOGS_DLL 1003 #define IDC_EMPLOYEE_EDIT_DIALOGS_DLL 1004 #define IDOK_DIALOGS_DLL 1005 #define IDCANCEL_DIALOGS_DLL 1006 #define IDC_CAPTION_STATIC_DIALOGS_DLL 1007 #define IDC_MSG_STATIC_DIALOGS_DLL 1008 */ class CSODlg : public CDialog { DECLARE_DYNAMIC(CSODlg) public: CSODlg(CWnd* pParent = NULL); // standard constructor virtual ~CSODlg(); // Dialog Data enum { IDD = IDD_SO_DIALOG_DIALOGS_DLL }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support DECLARE_MESSAGE_MAP() public: afx_msg void OnBnClickedOk(); afx_msg void OnBnClickedCancel(); const CString GetEmployeeID() const; const CString GetSONumber() const; private: CString EmployeeID; CString SONumber; }; #endif //__SO_DLG__H__
b330b49104062bbc24134f0c89dcd66587b8b9cf
f290eb9d322fcf741ed2c31a65cf78c0b9c3dfcc
/Post.h
b45e4054e4e9a2d86997168e5516ab3c5737ec9f
[]
no_license
bmicov/OOP-HW3
5451138f7e2b5c1f3ac7ebed38311014ed430248
72c2fb5cd5f30bd3911c27ac955e371ad8273e34
refs/heads/master
2020-03-19T05:33:28.246782
2018-06-03T21:56:08
2018-06-03T21:56:08
135,943,541
0
0
null
null
null
null
UTF-8
C++
false
false
541
h
Post.h
#pragma once #include <fstream> enum Posts { LINK_POST, TEXT_POST, PIC_POST }; class Post { public: Post(); Post & operator=(const Post & other); Post(const Post & other); virtual ~Post(); void setContent(const char * content, unsigned id, unsigned ab); unsigned getId(); const char * getContent(); unsigned getAddedBy(); virtual Post * getInstance() = 0; virtual void visualize(const char * name) = 0; protected: void CopyFrom(const Post & other); protected: char * content; unsigned id; unsigned addedBy; //id of user };
ae92f239da665cde852c7f287ebd2de299e6cdff
fa88246ab9c48955bb50b7d15682e21e32de186b
/Graph data structure and algorithms /Task1/Floyd/Floyd_test.h
1bcd3acf6d1f6579f4c79e2a929ae5629a8c6ebc
[]
no_license
AlenkaKravc/MIPT
c44dc56e59f47e9e93d575f2840a0f0e771e8cdf
c7a606bf890787300d35af0d726f251ffcff0097
refs/heads/master
2020-03-08T04:09:26.801653
2018-04-03T13:48:22
2018-04-03T13:48:22
122,349,009
0
0
null
null
null
null
UTF-8
C++
false
false
1,658
h
Floyd_test.h
#include <gtest/gtest.h> #include "Graph.h" #ifndef FLOYD_FLOUD_TEST_H #define FLOYD_FLOUD_TEST_H TEST(Floyd_Test, Ckeck_Floyd_1){ int nVertex(4); std::vector <std::vector<int>> graph, graph_res; graph = { {0,5,9,100}, {100,0,2,8}, {100,100,0,7}, {4,100,100,0} }; graph_res= { {0,5,7,13}, {12,0,2,8}, {11,16,0,7}, {4,9,11,0} }; Graph my_graph(4,graph); my_graph.Floyd(); for (int i = 0; i < nVertex; ++i) for (int j = 0; j < nVertex; ++j) ASSERT_EQ(my_graph.graph[i][j], graph_res[i][j]); } TEST(Floyd_Test, Ckeck_Floyd_2){ int nVertex(4); std::vector <std::vector<int>> graph, graph_res; graph = { {0,-5,-9,100}, {100,0,2,8}, {100,100,0,7}, {4,100,100,0} }; graph_res= { {0,-5,-9,-2}, {12,0,2,8}, {11,6,0,7}, {4,-1,-5,0} }; Graph my_graph(4,graph); my_graph.Floyd(); for (int i = 0; i < nVertex; ++i) for (int j = 0; j < nVertex; ++j) ASSERT_EQ(my_graph.graph[i][j], graph_res[i][j]); } TEST(Floyd_Test, Ckeck_Floyd_3){ int nVertex(6); std::vector <std::vector<int>> graph, graph_res; graph = { {0,100,1,100,100,100}, {1,0,100,4,2,100}, {100,100,0,1,100,100}, {100,4,100,0,100,6}, {100,1,100,100,0,4}, {1,100,100,100,100,0} }; graph_res= { {0,6,1,2,8,8}, {1,0,2,3,2,6}, {6,5,0,1,7,7}, {5,4,6,0,6,6}, {2,1,3,4,0,4}, {1,7,2,3,9,0} }; Graph my_graph(6,graph); my_graph.Floyd(); for (int i = 0; i < nVertex; ++i) for (int j = 0; j < nVertex; ++j) ASSERT_EQ(my_graph.graph[i][j], graph_res[i][j]); } #endif //FLOYD_FLOUD_TEST_H
a92275a4798a6c361d1a3522ac0721973be29d34
1de1d34a097a62faf8aa7cdc2aaf0325adf597f3
/src/gateway/GatewayServer.cpp
2c42fdec104fbcd2d8572e939fba6a40d010ff0f
[]
no_license
mmason930/kinslayer-mud
9fb0d57b6b404b024429f884a4c94cc60623b299
6473ec8bf9eb3e43742e825099de747ad315b0c2
refs/heads/master
2023-08-03T05:03:27.332311
2023-08-01T22:45:35
2023-08-01T22:45:35
56,131,481
4
1
null
2023-03-06T01:55:21
2016-04-13T07:42:54
C++
UTF-8
C++
false
false
28,399
cpp
GatewayServer.cpp
#include <iostream> #include <thread> #include "../DateTime.h" #include "../MiscUtil.h" #include "../SystemUtil.h" #include "GatewayServer.h" #include "GatewayListener.h" #include "GatewayDescriptorStatus.h" #include "GatewayDescriptorType.h" #include "../StringUtil.h" #include "../websocket/WebSocketClientHeader.h" #include "../websocket/WebSocketException.h" #ifndef WIN32 #include <sys/types.h> #include <sys/wait.h> #endif bool debugBoolean = false; std::vector<std::string> crashReasonVector; std::string makeTimestamp() { return "[" + DateTime::parse("%Y-%m-%d %H:%M:%S", DateTime()) + "]"; } GatewayServer::GatewayServer() { this->lastPingResponseFromGameServer = DateTime(0); this->lastPingSentToGameServer = DateTime(0); this->serverPort = 0; this->motherConnectionToServer = NULL; this->restartOnShutdown = false; this->mudProcessId = 0; this->mudStatus = MudStatus::notRunning; this->statusLastModifiedDatetime = DateTime(); this->lastAttemptedMudStartDatetime = DateTime(0); this->lastMudProcessIdCheckDatetime = DateTime(0); this->shutdownOnReboot = false; } GatewayServer::~GatewayServer() { } std::string GatewayServer::getServerHost() { return serverHost; } int GatewayServer::getServerPort() { return serverPort; } GatewayListener *GatewayServer::getGatewayListener(kuListener *listener) { for(auto iter = listeners.begin();iter != listeners.end();++iter) { GatewayListener *gatewayListener = (*iter); if(gatewayListener->getListener() == listener) return gatewayListener; } return NULL; } void closeDescriptorCallback(void *data, kuListener *listener, kuDescriptor *descriptor) { GatewayServer *gatewayServer = static_cast<GatewayServer*>(data); gatewayServer->removeDescriptor(descriptor); std::cout << makeTimestamp() << " Descriptor closed [" << descriptor->getIp() << "]" << std::endl; } //descriptor is the connection from the player to the gateway server. void openDescriptorCallback(void *data, kuListener *listener, kuDescriptor *descriptor) { GatewayServer *gatewayServer = static_cast<GatewayServer*>(data); GatewayDescriptor *gatewayDescriptor = new GatewayDescriptor(); GatewayListener *gatewayListener = gatewayServer->getGatewayListener(listener); gatewayDescriptor->setClientConnection(descriptor); gatewayDescriptor->setRandomId(StringUtil::getRandomString(40)); gatewayDescriptor->setGatewayListener(gatewayListener); if(gatewayListener->getType() == GATEWAY_LISTENER_TYPE_WEBSOCKET) { gatewayDescriptor->setStatus(GatewayDescriptorStatus::handshaking); gatewayDescriptor->setType(GatewayDescriptorType::websocket); } else { gatewayDescriptor->setStatus(GatewayDescriptorStatus::awaitingConnection); gatewayDescriptor->setType(GatewayDescriptorType::rawTCP); } gatewayServer->getDescriptors().push_back(gatewayDescriptor); std::cout << makeTimestamp() << " Descriptor opened [" << descriptor->getIp() << "]" << std::endl; } kuClient *GatewayServer::getMotherConnectionToServer() { return motherConnectionToServer; } bool GatewayServer::loadConfiguration() { std::string configFilePath = BASIC_CONFIG_PATH; std::cout << "Loading configuration from " << configFilePath << std::endl; std::map<std::string, std::string> resources = MiscUtil::loadResourcesFromFile(configFilePath); if(resources.find("Gateway Port") == resources.end()) { std::cout << "No Gateway Port specified in configuration file." << std::endl; return false; } if(resources.find("MUD Host") == resources.end()) { std::cout << "No MUD Host specified in configuration file." << std::endl; return false; } if(resources.find("MUD Port") == resources.end()) { std::cout << "No MUD Port specified in configuration file." << std::endl; return false; } if(resources.find("MUD Root Directory") == resources.end()) { std::cout << "No MUD Root Directory specified in confuration file." << std::endl; return false; } if(resources.find("Restart On Shutdown") == resources.end()) { std::cout << "No `Restart On Shutdown` specified in confuration file." << std::endl; return false; } if(resources.find("MUD Executable Path") == resources.end()) { std::cout << "No `MUD Executable Path` specified in confuration file." << std::endl; return false; } /*** this->secondaryPort = 0; if(resources.find("Secondary Gateway Port") != resources.end()) { this->secondaryPort = atoi(resources["Secondary Gateway Port"].c_str()); } ***/ if(resources.find("Websocket Ports") != resources.end()) { std::list<std::string> websocketPortsStringList = StringUtil::splitToList(resources["Websocket Ports"], ','); for(auto iter = websocketPortsStringList.begin();iter != websocketPortsStringList.end();++iter) { std::string portString = (*iter); if(!MiscUtil::isInt(portString)) { std::cout << "Invalid Websocket Port specified: `" << portString << "`: Not a valid integer." << std::endl; } else { this->websocketPorts.push_back(atoi(portString.c_str())); } } } this->serverPort = atoi(resources["MUD Port"].c_str()); this->serverHost = resources["MUD Host"]; this->listeningPort = atoi(resources["Gateway Port"].c_str()); this->mudRootDirectoryPath = resources["MUD Root Directory"]; this->restartOnShutdown = atoi(resources["Restart On Shutdown"].c_str()); this->mudExecutablePath = resources["MUD Executable Path"]; return true; } void GatewayServer::setupAndRun() { setup(); run(); } void GatewayServer::setup() { crashReasonVector.clear(); crashReasonVector.push_back("Galnor's terrible coding"); crashReasonVector.push_back("Fogel's balance imbalance"); crashReasonVector.push_back("Norum's fury"); crashReasonVector.push_back("a spontaneous bunny raid"); crashReasonVector.push_back("a nargdoor"); crashReasonVector.push_back("divine intervention"); crashReasonVector.push_back("WoTMUD spies"); crashReasonVector.push_back("a tsunami"); crashReasonVector.push_back("Westboro Baptist Church"); crashReasonVector.push_back("Sarah Palin"); crashReasonVector.push_back("a divide by zero"); crashReasonVector.push_back("rampant roleplaying"); crashReasonVector.push_back("Rick Astley"); crashReasonVector.push_back("Norya's hacking"); crashReasonVector.push_back("Gristlyn's horrible typing"); crashReasonVector.push_back("Phantasm's idiocy"); crashReasonVector.push_back("Chase's brotacular scandal"); crashReasonVector.push_back("Lord Jack's allegience to the Darkside"); crashReasonVector.push_back("Rakkard's RAINBOW"); crashReasonVector.push_back("your mom"); crashReasonVector.push_back("Facebook's terrible chat interface"); crashReasonVector.push_back("Google's attempts to buy us out"); crashReasonVector.push_back("rampant abuse of loopholes"); crashReasonVector.push_back("Lamgwin's political aspirations"); crashReasonVector.push_back("Jonlin's unexpected return"); crashReasonVector.push_back("the long overdue meltdown of the Valon Guard"); crashReasonVector.push_back("Kno'mon clan leaders"); crashReasonVector.push_back("something Evilina did"); crashReasonVector.push_back("the MMORPG takeover"); crashReasonVector.push_back("you. Yes, you,"); } void GatewayServer::disconnectMotherConnectionFromGameServer() { if(motherConnectionToServer != NULL) { motherConnectionToServer->disconnect(); delete motherConnectionToServer; } motherConnectionToServer = NULL; } void GatewayServer::attemptConnectionWithGameServer() { //Setup mother connection to the game server. if(motherConnectionToServer != NULL) { delete motherConnectionToServer; } motherConnectionToServer = new kuClient(); motherConnectionToServer->connect(serverHost, serverPort); if(motherConnectionToServer->isConnected() == false) { delete motherConnectionToServer; motherConnectionToServer = NULL; } else { sendToDescriptors("The MUD has been restarted and is now booting...\r\n\r\n"); crashed = false; rebooting = false; setMudStatus( MudStatus::booting ); std::cout << makeTimestamp() << " Connection established. Sending validation token." << std::endl; this->mudProcessId = 0; motherConnectionToServer->send("Validate 78fd516c2825e7f463f045e609a8523e\r\n"); } } void GatewayServer::bindListener() { //Setup the listening server for incoming connections. std::list<int> portsToListenTo; portsToListenTo.push_back(listeningPort); // if(secondaryPort) // portsToListenTo.push_back(secondaryPort); for(auto iter = portsToListenTo.begin();iter != portsToListenTo.end();++iter) { int port = (*iter); std::cout << makeTimestamp() << " Setting up gateway listener(normal) on port " << port << "." << std::endl; kuListener * listener; GatewayListener *gatewayListener = new GatewayListener(); listener = new kuListener(port, TCP); gatewayListener->setListener(listener); gatewayListener->setType(GATEWAY_LISTENER_TYPE_NORMAL); listener->setDataForCloseDescriptorCallback( static_cast<void*>(this) ); listener->setCloseDescriptorCallback(closeDescriptorCallback); listener->setDataForOpenDescriptorCallback( static_cast<void*>(this) ); listener->setOpenDescriptorCallback(openDescriptorCallback); if (!listener->enableKeepAlive()) { std::cout << makeTimestamp() << " Failed to set keepalive on socket." << std::endl; } listeners.push_back(gatewayListener); } for(auto iter = websocketPorts.begin();iter != websocketPorts.end();++iter) { int port = (*iter); std::cout << makeTimestamp() << " Setting up gateway listener(websocket) on port " << port << "." << std::endl; kuListener * listener; GatewayListener *gatewayListener = new GatewayListener(); listener = new kuListener(port, TCP); gatewayListener->setListener(listener); gatewayListener->setType(GATEWAY_LISTENER_TYPE_WEBSOCKET); listener->setDataForCloseDescriptorCallback( static_cast<void*>(this) ); listener->setCloseDescriptorCallback(closeDescriptorCallback); listener->setDataForOpenDescriptorCallback( static_cast<void*>(this) ); listener->setOpenDescriptorCallback(openDescriptorCallback); if (!listener->enableKeepAlive()) { std::cout << makeTimestamp() << " Failed to set keepalive on socket." << std::endl; } listeners.push_back(gatewayListener); } } bool GatewayServer::isConnectedToGameServer() { if(motherConnectionToServer == NULL) { return false; } if(!motherConnectionToServer->isConnected()) { return false; } return true; } void GatewayServer::processInputFromMotherConnectionToServer() { std::list<GatewayDescriptor*>::iterator descriptorIter; std::stringstream inputBuffer; this->getMotherConnectionToServer()->receive(inputBuffer); inputBufferFromServer += inputBuffer.str(); while(hasCommand()) { std::string commandLine = getCommand(); try { std::vector<std::string> vArgs = StringUtil::getArgVector(commandLine); std::string command = vArgs.at(0); if(command == "Session") { std::string randomId = vArgs.at(1); std::string sessionKey = vArgs.at(2); std::cout << makeTimestamp() << " Session received: " << sessionKey << std::endl; descriptorIter = descriptors.begin(); while(descriptorIter != descriptors.end()) { GatewayDescriptor *descriptor = (*descriptorIter); if(descriptor->getRandomId() == randomId) { descriptor->setSession(sessionKey); descriptor->connect(serverHost, serverPort); descriptor->sendToServer( "Session " + sessionKey + "\r\n" ); descriptor->setStatus(GatewayDescriptorStatus::connected); break; } ++descriptorIter; } } else if(command == "Close") { std::string sessionKey = vArgs.at(1); descriptorIter = descriptors.begin(); std::cout << makeTimestamp() << " Close received: " << sessionKey << std::endl; while(descriptorIter != descriptors.end()) { GatewayDescriptor *descriptor = (*descriptorIter); if(descriptor->getSession() == sessionKey) { this->disconnectDescriptorFromGameAndGateway(descriptor); descriptors.erase(descriptorIter); break; } else { ++descriptorIter; } } } else if(command == "PingResponse") { //TODO: Read any actual data sent along with this packet. std::cout << makeTimestamp() << " Ping response received from game server." << std::endl; lastPingResponseFromGameServer = DateTime(); } else if(command == "FinishedBooting") { std::cout << makeTimestamp() << " The MUD has indicated that it has finished booting." << std::endl; setMudStatus( MudStatus::running ); } else if(command == "ShutdownOnReboot") { std::cout << makeTimestamp() << " The MUD has told the Gateway to shut down when the MUD next reboots." << std::endl; this->shutdownOnReboot = true; } else if(command == "RestartOnReboot") { std::cout << makeTimestamp() << " The MUD has told the Gateway to restart when the MUD next reboots." << std::endl; this->shutdownOnReboot = false; } else if(command == "Reboot") { std::cout << makeTimestamp() << " Reboot command received. Putting players into awaitingConnection mode." << std::endl; sendToDescriptors("The MUD is shutting down...\r\n\r\n"); crashed = false; rebooting = true; handleGameShutdown(); setMudStatus(MudStatus::shuttingDown); } else if(command == "ProcessID") { int processId = atoi(vArgs.at(1).c_str()); std::cout << makeTimestamp() << " The MUD has set its process ID to `" << processId << "`." << std::endl; this->mudProcessId = processId; } } catch(std::out_of_range &e) { //...Error... } } } void GatewayServer::disconnectDescriptorFromGameAndGateway(GatewayDescriptor *gatewayDescriptor) { gatewayDescriptor->getServerConnection()->disconnect(); delete gatewayDescriptor->getServerConnection(); debugBoolean = true; gatewayDescriptor->getClientConnection()->socketClose(); gatewayDescriptor->setServerConnection(NULL); gatewayDescriptor->setClientConnection(NULL); gatewayDescriptor->setStatus(GatewayDescriptorStatus::disconnected); } void GatewayServer::handleGameShutdown() { std::list<GatewayDescriptor*>::iterator iter; iter = descriptors.begin(); while(iter != descriptors.end()) { GatewayDescriptor *descriptor = (*iter); descriptor->setStatus(GatewayDescriptorStatus::awaitingConnection); kuClient *connectionToGame = descriptor->getServerConnection(); if(connectionToGame != NULL) { delete connectionToGame; descriptor->setServerConnection(NULL); } ++iter; } } void GatewayServer::sendToDescriptors(const std::string &message) { std::list<GatewayDescriptor*>::iterator iter; iter = descriptors.begin(); while(iter != descriptors.end()) { GatewayDescriptor *descriptor = (*iter); descriptor->sendOutputMessageToClient(message); ++iter; } } void GatewayServer::run() { std::list<GatewayDescriptor*>::iterator descriptorIter; bindListener(); bool isTerminated = false; while(!isTerminated) { for(auto gatewayListenerIter = listeners.begin();gatewayListenerIter != listeners.end();++gatewayListenerIter) { (*gatewayListenerIter)->getListener()->acceptNewHosts(); (*gatewayListenerIter)->getListener()->pulse(); } if(!isConnectedToGameServer()) { if(getMudStatus() == MudStatus::running || getMudStatus() == MudStatus::booting) { //We lost connection but think the MUD is up. This means the MUD has most likely crashed. crashed = true; rebooting = false; //Disconnect all players and set them in 'awaiting connection' mode. std::string reason = crashReasonVector[ MiscUtil::random(0,crashReasonVector.size()-1) ]; sendToDescriptors("The MUD has crashed! How terrible!\r\n\r\n" "We suspect " + reason + " may be responsible.\r\n\r\n" "Please standby while we reboot...\r\n\r\n"); std::cout << makeTimestamp() << " Game has crashed. Putting players into awaitingConnection mode." << std::endl; handleGameShutdown(); setMudStatus( MudStatus::notRunning ); lastAttemptedMudStartDatetime = DateTime(0);//Reset this to far in the past so we attempt a reboot immediately. } attemptConnectionWithGameServer(); } if(getMudStatus() == MudStatus::shuttingDown) { //Check to see if the MUD has shut down yet. if(SystemUtil::processExists( this->mudProcessId ) == false) { setMudStatus(MudStatus::notRunning); this->mudProcessId = 0; this->disconnectMotherConnectionFromGameServer(); sendToDescriptors("The MUD has finished shutting down.\r\n\r\n"); std::cout << makeTimestamp() << " The MUD process can no longer be found. Assuming MUD has completed with shutdown." << std::endl; if(shutdownOnReboot) { std::cout << makeTimestamp() << " The gateway is now preparing to shut down." << std::endl; isTerminated = true; } } else { // std::cout << makeTimestamp() << " MUD process ID `" << this->mudProcessId << "` still exists. Waiting for shutdown to complete..." << std::endl; //MUD is shutting down, but still running. } } //We need to reboot the MUD if configured to carry out the task. if(!isTerminated && getMudStatus() == MudStatus::notRunning) { long long secondsSinceLastAttemptedMudStart = (DateTime().getTime() - lastAttemptedMudStartDatetime.getTime()); if(this->restartOnShutdown && secondsSinceLastAttemptedMudStart >= 60) { sendToDescriptors("Attempting to start the MUD...\r\n\r\n"); this->attemptMudStart(); lastAttemptedMudStartDatetime = DateTime(); std::cout << makeTimestamp() << " Attempting to restart MUD. Current status is `" << getMudStatus()->getStandardName() << "`. Socket connection: " << (isConnectedToGameServer() == true ? "Yes" : "No") << std::endl; } } if(!isTerminated && getMudStatus() == MudStatus::booting) { if(this->mudProcessId != 0 && DateTime().getTime() - lastMudProcessIdCheckDatetime.getTime() > 5) { std::cout << makeTimestamp() << " Checking to see if MUD process is still alive..."; if(SystemUtil::processExists(this->mudProcessId)) std::cout << "yes" << std::endl; else { std::cout << "no. Treating as crash." << std::endl; this->crashed = true; } lastMudProcessIdCheckDatetime = DateTime(); } } if(!isTerminated && getMudStatus() == MudStatus::running) { __int64 ts = lastPingSentToGameServer.getTime(); __int64 tr = lastPingResponseFromGameServer.getTime(); __int64 tn = DateTime().getTime(); __int64 timeBetween = tn - ts; // if(lastPingSentToGameServer.getTime() == 0 || !lastPingSentToGameServer.after(lastPingResponseFromGameServer)) { if(ts == 0 || timeBetween >= 5) { pingGameServer(); } } if(isConnectedToGameServer() && getMudStatus() != MudStatus::notRunning) { processInputFromMotherConnectionToServer(); } for(descriptorIter = descriptors.begin();descriptorIter != descriptors.end();) { GatewayDescriptor *descriptor = (*descriptorIter); bool removedDescriptor = false; if(descriptor->getStatus() == GatewayDescriptorStatus::connected) { std::string inputFromClient, inputFromServer; try { inputFromClient = descriptor->pullFromClient(); } catch(WebSocketException &webSocketException) { if(webSocketException.what() == "Socket Closed") { this->disconnectDescriptorFromGameAndGateway(descriptor); descriptorIter = descriptors.erase(descriptorIter); removedDescriptor = true; } } if(!removedDescriptor) { inputFromServer = descriptor->pullFromServer(); if(inputFromServer.empty() == false) { descriptor->sendToClient(inputFromServer); } if(inputFromClient.empty() == false) { descriptor->sendToServer(inputFromClient); } } } else if(descriptor->getStatus() == GatewayDescriptorStatus::awaitingConnection && getMotherConnectionToServer() != NULL && !this->mudIsDown()) { kuClient *gameClient = getMotherConnectionToServer(); std::stringstream buffer; std::string clientIpAddress = descriptor->getClientConnection()->getIp(); if(descriptor->getProxyForwardedIpAddress().has_value()) { clientIpAddress = *(descriptor->getProxyForwardedIpAddress()); } buffer << "Host " << descriptor->getRandomId() << " " << clientIpAddress << " " << descriptor->getType()->getValue() << "\r\n"; gameClient->send(buffer.str()); descriptor->setStatus(GatewayDescriptorStatus::retrievingSession); } // else if(descriptor->getStatus() == GatewayDescriptorStatus::handshaking) { else if(descriptor->getStatus() == GatewayDescriptorStatus::handshaking && getMotherConnectionToServer() != NULL && !this->mudIsDown()) { try { std::string dataFromWebSocketClient = descriptor->pullFromClient(); descriptor->appendToCurrentInputBuffer(dataFromWebSocketClient); if(WebSocketClientHeader::isComplete(descriptor->getCurrentInputBuffer())) { dataFromWebSocketClient = descriptor->getCurrentInputBuffer(); std::unique_ptr<WebSocketClientHeader> webSocketClientHeader(WebSocketClientHeader::allocateByInitialClientPacket(dataFromWebSocketClient)); webSocketClientHeader->read(dataFromWebSocketClient); std::string response = webSocketClientHeader->generateResponse(descriptor->getGatewayListener()->getListener()->getPort(), "mud-protocol"); // Get the X-Forwarded-For header value, if it exists, and set the client IP address to that. // Note that this is insecure unless we also check to see if we trust the client IP address, // such as validating that it's being forwarded from an internal IP. Otherwise, clients could // easily spoof their IP address. However, since we intend to shut off direct websocket access // once we begin forwarding, this shouldn't matter. std::optional<std::string> xForwardedFor = webSocketClientHeader->getFieldByName("X-Forwarded-For"); if(xForwardedFor.has_value()) { descriptor->setProxyForwardedIpAddress(xForwardedFor); } descriptor->sendToClient(response); descriptor->setStatus(GatewayDescriptorStatus::awaitingConnection); std::cout << makeTimestamp() << " Client `" << descriptor->getSession() << "` is being put into awaitingConnection status." << std::endl; } } catch(WebSocketException &webSocketException) { descriptor->setStatus(GatewayDescriptorStatus::disconnected); std::cout << "ERROR : WebSocketException caught while handshaking: " << webSocketException.what() << std::endl; } } if(!removedDescriptor) ++descriptorIter; } std::this_thread::sleep_for(std::chrono::milliseconds(10)); } } bool GatewayServer::hasCommand() { return (inputBufferFromServer.find("\n") != std::string::npos); } std::string GatewayServer::getCommand() { std::string::size_type endPos, i, size; size = inputBufferFromServer.size(); for(i = 0;i < size && inputBufferFromServer[i] != '\r' && inputBufferFromServer[i] != '\n';++i); if( (size == 0) || (i == size && inputBufferFromServer[i] != '\r' && inputBufferFromServer[i] != '\n') ) return std::string(""); endPos = i; if( (size > i+1) && ((inputBufferFromServer[i] == '\n' && inputBufferFromServer[i+1] == '\r') || (inputBufferFromServer[i] == '\r' && inputBufferFromServer[i+1] == '\n')) ) ++endPos; std::string Line = inputBufferFromServer.substr(0, i); inputBufferFromServer.erase(0, endPos+1); return Line; } void GatewayServer::shutdown() { while(listeners.empty() == false) { delete listeners.front(); listeners.pop_front(); } } std::list<GatewayDescriptor*> &GatewayServer::getDescriptors() { return descriptors; } void GatewayServer::removeDescriptor(kuDescriptor *descriptor) { for(std::list<GatewayDescriptor*>::iterator iter = descriptors.begin();iter != descriptors.end();++iter) { if( (*iter)->getClientConnection() == descriptor ) { if( (*iter)->getServerConnection() != NULL ) { (*iter)->getServerConnection()->disconnect(); } delete (*iter); descriptors.erase(iter); return; } } } void GatewayServer::pingGameServer() { if(motherConnectionToServer != NULL && (lastPingSentToGameServer.getTime() == 0 || lastPingSentToGameServer.compareTo(lastPingResponseFromGameServer) <= 0)) { std::cout << makeTimestamp() << " Pinging game server." << std::endl; motherConnectionToServer->send("Ping " + DateTime::parse("%Y-%m-%d %H:%M:%S", DateTime()) + "\n"); this->lastPingSentToGameServer = DateTime(); } } DateTime GatewayServer::getLastPingSentToServerDatetime() { return lastPingSentToGameServer; } DateTime GatewayServer::getLastPingResponseFromGameServerDatetime() { return lastPingResponseFromGameServer; } bool GatewayServer::mudIsCrashed() { return crashed; } bool GatewayServer::mudIsRebooting() { return rebooting; } bool GatewayServer::mudIsDown() { return crashed || rebooting; } std::string GatewayServer::getMudRootDirectoryPath() { return mudRootDirectoryPath; } bool GatewayServer::getRestartOnShutdown() { return restartOnShutdown; } bool GatewayServer::isMudProcessRunning() { return (SystemUtil::processExists(this->mudProcessId)); } MudStatus *GatewayServer::getMudStatus() { return mudStatus; } void GatewayServer::setMudStatus(MudStatus *mudStatus) { this->mudStatus = mudStatus; this->statusLastModifiedDatetime = DateTime(); } void GatewayServer::attemptMudStart() { std::cout << makeTimestamp() << " Attempting to start the MUD." << std::endl; std::stringstream commandBuffer; #ifdef WIN32 commandBuffer << "START CMD /C CALL \"" << this->getMudRootDirectoryPath() << mudExecutablePath << "\""; system(commandBuffer.str().c_str()); #else commandBuffer << this->getMudRootDirectoryPath() << mudExecutablePath; pid_t temporaryProcessId, childProcessId; temporaryProcessId = fork(); if(temporaryProcessId == 0) {//This is the child childProcessId = fork(); if(childProcessId == 0) {//This is the actual child, which we will use to spawn the MUD process. // std::cout << "**MUD PROCESS** Child process starting MUD..." << std::endl; int retval = execlp(commandBuffer.str().c_str(), commandBuffer.str().c_str(), 0); // std::cout << "**MUD PROCESS** Child process finished starting MUD..." << std::endl; // std::cout << "**MUD PROCESS** Return Value: " << retval << std::endl; // std::cout << "**MUD PROCESS** Errno: " << strerror(errno) << std::endl; exit(1); } else if(childProcessId > 0) {//This is the parent process, which we will terminate to assign the MUD process's parent to the "init" process. //The gateway process which we will keep alive will spawn on the second fork call. // std::cout << "**TEMPORARY PROCESS** Exiting immediately..." << std::endl; exit(0); } else {//Error, could not fork. std::cout << makeTimestamp() << " ERROR: Could not fork!" << std::endl; } } else if(temporaryProcessId > 0) {//Here we have the actual gateway process, which will safely exit out of this function and proceed functioning. //First we will wait for the temporary process to terminate so that we can reap it, eliminating the dangling zombie process. int status; waitpid(childProcessId, &status, 0); } else {//Error, could not fork. std::cout << makeTimestamp() << " ERROR: Could not fork!" << std::endl; } // std::cout << "**GATEWAY PROCESS** Proceeding..." << std::endl; #endif }
017cb4e6852f7c29968ffaaf063729dc17f8a889
611f71279101e6cd0d59ce295e098c59c20b6562
/TrafficLight.cpp
c90dcaabf4b93993e981d01778fb7ce39f078f05
[]
no_license
Medanya/pps_project
d6a80d8a2d028b507bd4117aa1ed67f78e49f808
d0348e6b47379fd1ab4e1355369d65669397550d
refs/heads/master
2020-07-03T22:09:05.426609
2016-12-05T19:52:03
2016-12-05T19:52:03
74,228,688
0
2
null
2016-12-02T13:04:33
2016-11-19T18:57:18
C++
UTF-8
C++
false
false
108
cpp
TrafficLight.cpp
#include "TrafficLight.hpp" void TrafficLight::setColor(TrafficLightColor color) { this->color = color; }
1896f11e6a4df7e7276de079a79e45d16c41d161
7278aeaa0f4a6b314c50dafce278806be0246d0a
/emscripten/bullet/src/demo/states/State_AbstractSimulation.cpp
eced5e403c3fd104fff855af0dbf791f6d2b5e4c
[]
no_license
GuillaumeBouchetEpitech/geneticAlgorithm_experiment
95cc5a00d6c9ce2402ca0fb7091b9310e9ded5c1
8521b37af6bcd7d7056e67fb7297439781396617
refs/heads/master
2023-02-26T03:09:23.347300
2023-02-11T16:12:45
2023-02-11T16:12:45
58,233,523
18
6
null
null
null
null
UTF-8
C++
false
false
6,275
cpp
State_AbstractSimulation.cpp
#include "demo/defines.hpp" #include "StateManager.hpp" #include "State_AbstractSimulation.hpp" #include "demo/logic/Context.hpp" #include "demo/logic/graphic/Scene.hpp" #include "framework/helpers/GLMath.hpp" #include "framework/system/math/GenericEasing.hpp" #include "framework/system/math/easingFunctions.hpp" #include <cmath> // std::ceil #include <limits> // std::numeric_limits<T>::max(); void State_AbstractSimulation::enter() { // D_MYLOG("step"); } void State_AbstractSimulation::leave() { // D_MYLOG("step"); } // void State_AbstractSimulation::handleEvent(const SDL_Event& event) { auto& context = Context::get(); auto& keys = context.inputs.keys; auto& mouse = context.inputs.mouse; switch (event.type) { case SDL_KEYDOWN: { keys[event.key.keysym.sym] = true; break; } case SDL_KEYUP: { keys[event.key.keysym.sym] = false; break; } case SDL_MOUSEBUTTONDOWN: { mouse.position = {event.motion.x, event.motion.y}; mouse.delta = {0, 0}; mouse.tracking = true; break; } case SDL_MOUSEBUTTONUP: { mouse.tracking = false; break; } case SDL_MOUSEMOTION: { if (mouse.tracking) { // mouse/touch events are 4 times more sentitive in web build // this bit ensure the mouse/touch are even in native/web build #if defined D_WEB_BUILD constexpr float coef = 1; #else constexpr float coef = 4; #endif const glm::vec2 newPosition = {event.motion.x, event.motion.y}; mouse.delta = (newPosition - glm::vec2(mouse.position)) * coef; mouse.position = newPosition; } break; } default: break; } } void State_AbstractSimulation::update(float elapsedTime) { auto& context = Context::get(); auto& graphic = context.graphic; auto& camera = graphic.camera; { // events auto& rotations = camera.rotations; { // mouse/touch event(s) auto& mouse = context.inputs.mouse; if (mouse.tracking) { rotations.theta -= float(mouse.delta.x) * 1.0f * elapsedTime; rotations.phi += float(mouse.delta.y) * 1.0f * elapsedTime; mouse.delta = {0, 0}; } } // mouse/touch event(s) { // keyboard event(s) auto& keys = context.inputs.keys; bool rotateLeft = (keys[SDLK_LEFT] || // ARROW keys[SDLK_q] || // QWERTY (UK-US keyboard layout) keys[SDLK_a] // AZERTY (FR keyboard layout) ); bool rotateRight = (keys[SDLK_RIGHT] || // ARROW keys[SDLK_d]); bool rotateUp = (keys[SDLK_UP] || // ARROW keys[SDLK_w] || // QWERTY (UK-US keyboard layout) keys[SDLK_z] // AZERTY (FR keyboard layout) ); bool rotateDown = (keys[SDLK_DOWN] || // ARROW keys[SDLK_s]); if (rotateLeft) rotations.theta += 2.0f * elapsedTime; else if (rotateRight) rotations.theta -= 2.0f * elapsedTime; if (rotateUp) rotations.phi -= 1.0f * elapsedTime; else if (rotateDown) rotations.phi += 1.0f * elapsedTime; context.logic.isAccelerated = (keys[SDLK_SPACE]); // spacebar } // keyboard event(s) } // events } void State_AbstractSimulation::render(const SDL_Window& window) { static_cast<void>(window); // <= unused Scene::renderAll(); } void State_AbstractSimulation::resize(int width, int height) { auto& graphic = Context::get().graphic; graphic.camera.viewportSize = {width, height}; graphic.hud.postProcess.resize({width, height}); graphic.hud.postProcess.setGeometry( glm::vec2(0, 0), glm::vec2(width, height), -2.0f); graphic.hud.topologyRenderer.resize(); graphic.hud.thirdPersonCamera.resize(); graphic.hud.coreUsageRenderer.resize(); graphic.hud.fitnessDataRenderer.resize(); graphic.hud.leaderEyeRenderer.resize(); } void State_AbstractSimulation::visibility(bool visible) { #if 0 // disable pause state? static_cast<void>(visible); // unused #else auto* stateManager = StateManager::get(); StateManager::States currentState = stateManager->getState(); if (currentState != StateManager::States::Paused && !visible) stateManager->changeState(StateManager::States::Paused); #endif } void State_AbstractSimulation::_updateCommonLogic(float elapsedTime) { auto& graphic = Context::get().graphic; graphic.scene.particleManager.update(elapsedTime); graphic.scene.backGroundTorusRenderer.update(elapsedTime); graphic.scene.flockingManager.update(); graphic.hud.screenTitles.update(elapsedTime); graphic.hud.topologyRenderer.update(elapsedTime); graphic.hud.thirdPersonCamera.update(elapsedTime); graphic.hud.coreUsageRenderer.update(elapsedTime); graphic.hud.fitnessDataRenderer.update(elapsedTime); graphic.hud.informationTextRenderer.update(elapsedTime); graphic.hud.leaderEyeRenderer.update(elapsedTime); } void State_AbstractSimulation::_updateCameraTracking(float elapsedTime) { auto& context = Context::get(); auto& camera = context.graphic.camera; auto& logic = context.logic; glm::vec3 cameraNextCenter = logic.circuitDimension.center; float cameraNextDistance = 300.0f; // // auto& leaderCar = logic.leaderCar; auto& simulation = *logic.simulation; if (simulation.isGenerationComplete()) return; if (logic.isAccelerated) { leaderCar.reset(); cameraNextDistance = 200.0f; } else { leaderCar.update(elapsedTime); if (auto leaderPos = leaderCar.leaderPosition()) { cameraNextCenter = *leaderPos; cameraNextDistance = 40.0f; } else { cameraNextCenter = simulation.getStartPosition(); cameraNextDistance = 60.0f; } } // // { constexpr float k_maxDistance = 200.0f; const float distanceToTarget = glm::distance(cameraNextCenter, camera.center); const float moveLerpRatio = GenericEasing<2>() .push(0.0f, 3.0f, easing::easeInOutCubic) .push(1.0f, 1.0f) .get(distanceToTarget / k_maxDistance) * elapsedTime; camera.center += (cameraNextCenter - camera.center) * moveLerpRatio; camera.distance += (cameraNextDistance - camera.distance) * 1.0f * elapsedTime; } }
fdc4aa86128cb21890e05faa53b462a6d5c9da30
29427c0c69a9b147f91f335fb8f3665457cbd757
/ios/ios_src/ModalBackground/View/ModalBackgroundViewInterop.h
1aba02b06bc9f525a2e9e39b7f7c16f592dbd711
[ "BSD-2-Clause" ]
permissive
MusabAkram/wrld-example-app
d76129cfe33b248d6edea2926ddba258457d33f4
78d616922868b49772eb5b9d08e529af079859dd
refs/heads/master
2020-03-22T05:05:17.712724
2018-07-02T15:23:52
2018-07-02T15:23:52
139,541,364
1
0
null
2018-07-03T06:57:02
2018-07-03T06:57:02
null
UTF-8
C++
false
false
1,401
h
ModalBackgroundViewInterop.h
// Copyright eeGeo Ltd (2012-2015), All Rights Reserved #pragma once #include "IModalBackgroundView.h" #include "CallbackCollection.h" #include "ICallback.h" #include "ModalBackgroundViewIncludes.h" namespace ExampleApp { namespace ModalBackground { namespace View { class ModalBackgroundViewInterop : public Modality::View::IModalBackgroundView { public: ModalBackgroundViewInterop(ModalBackgroundView* pView) : m_pView(pView) { } void SetFullyActive(); void SetFullyInactive(); void SetActiveStateToIntermediateValue(float modality); void InsertTappedCallback(Eegeo::Helpers::ICallback0& callback); void RemoveTappedCallback(Eegeo::Helpers::ICallback0& callback); void InsertTouchCallback(Eegeo::Helpers::ICallback0& callback); void RemoveTouchCallback(Eegeo::Helpers::ICallback0& callback); void HandleViewTapped(); void HandleTouchOnView(); private: ModalBackgroundView* m_pView; Eegeo::Helpers::CallbackCollection0 m_tappedCallbacks; Eegeo::Helpers::CallbackCollection0 m_touchCallbacks; }; } } }
dab3a5a9c6751147b04d4757723cdb47f9ce7a45
e2181e9439866cbf1455fdff66e4e27879eb034e
/src_my/gm/scene_mgr_class.hpp
a78e92ad830bc6732ffa3e84161cd37c9fb504a6
[]
no_license
lineCode/game_server-1
3fb841d3a4973d47e9c2692bbf9b1e440c499e5d
d9178ee8a0a504e5873bee3616d323056c9c9764
refs/heads/master
2020-05-19T08:01:02.835874
2019-05-03T11:10:57
2019-05-03T11:10:57
null
0
0
null
null
null
null
UTF-8
C++
false
false
5,921
hpp
scene_mgr_class.hpp
#pragma once #include "proto/data_base.pb.h" #include "proto/data_player.pb.h" #include "proto/data_chat.pb.h" #include "proto/data_arena.pb.h" #include "proto/data_mail.pb.h" #include "proto/data_yunying.pb.h" #include "proto/data_log.pb.h" #include "proto/data_admin.pb.h" #include "net/conn.hpp" #include "net/server.hpp" #include "db/message.hpp" #include <map> #include <memory> #include <boost/core/noncopyable.hpp> using namespace std; namespace pd = proto::data; namespace nora { class service_thread; namespace gm { class scene; class scene_mgr_class : private boost::noncopyable { public: scene_mgr_class(); static scene_mgr_class& instance() { static scene_mgr_class inst; return inst; } void start(); void stop(); friend ostream& operator<<(ostream& os, const scene_mgr_class& sm); void manage_announcement(uint32_t sid, const pd::announcement& announcement); void server_images_announcement(uint32_t sid, uint32_t server_id, const map<string, uint32_t>& announcements); void gag_role_by_gid(uint32_t sid, int server_id, uint64_t gid, uint32_t gag_until_time, const string& reason); void remove_gag_role_by_gid(uint32_t sid, int server_id, uint64_t gid); void ban_role_by_gid(uint32_t sid, int server_id, uint64_t gid, uint32_t ban_until_time, const string& reason); void remove_ban_role_by_gid(uint32_t sid, int server_id, uint64_t gid); void kick_role_by_gid(uint32_t sid, int server_id, uint64_t gid, const string& reason); void fetch_world_chat(uint32_t sid, int server_id); void find_role_by_gid(uint32_t sid, int server_id, uint64_t gid); void find_role_by_rolename(uint32_t sid, int server_id, const string& rolename); void fetch_rank_list(uint32_t sid, int server_id, const string& rank_type, uint32_t page_size); void internal_recharge(uint32_t sid, int server_id, uint64_t role, uint32_t recharge_id); void reissue_recharge(uint32_t sid, int server_id, uint64_t role, uint64_t order); void recharge(uint32_t sid, uint64_t order, const string& yy_orderno, const string& currency, uint32_t price, uint32_t paytime, const string& product_name, const string& ext_info); void send_mail(uint32_t sid, int server_id, uint32_t channel_id, const pd::gid_array& roles, uint64_t mail_id, const string& title, const string& content, const pd::event_array& events); void fetch_log(uint32_t sid, int server_id, uint64_t role, uint32_t item_id, uint32_t start_time, uint32_t end_time, int page_idx, int page_size); void fetch_punished(uint32_t sid, int server_id, uint64_t role, uint32_t start_time, uint32_t end_time, int page_idx, int page_size); void fetch_sent_mail(uint32_t sid, int server_id, uint64_t role, uint32_t start_time, uint32_t end_time, int page_idx, int page_size); void fetch_login_record(uint32_t sid, int server_id, uint64_t role, int page_idx, int page_size); void fetch_recharge_record(uint32_t sid, int server_id, uint32_t channel_id, uint64_t order, uint64_t role, int start_time, int end_time, int page_idx, int page_size); void fetch_currency_record(uint32_t sid, int server_id, const string& type, uint64_t role, int start_time, int end_time, int page_idx, int page_size); void fetch_role_list(uint32_t sid, const string& username); void set_role_list(uint32_t sid, const pd::yunying_role_simple_info& rsi); bool has_sid(uint32_t sid) const; bool has_server_id(uint32_t sid, int server_id) const; bool has_role_simple_infos(uint32_t sid) const; void add_resource(uint32_t sid, uint64_t gid, uint32_t resource_type, uint32_t resource_count); void add_stuff_by_rolename(uint32_t sid, uint32_t server_id, const string& rolename, const pd::event_array& events); void add_stuff_by_gid(uint32_t sid, uint32_t server_id, uint64_t role, const pd::event_array& events); void dec_stuff_by_rolename(uint32_t sid, uint32_t server_id, const string& rolename, const pd::event_array& events); void dec_stuff_by_gid(uint32_t sid, uint32_t server_id, uint64_t role, const pd::event_array& events); void operates_activity(uint32_t sid, uint32_t activity, uint32_t start_time, uint32_t duration, pd::admin_activity_type type, const vector<string>& server_ids, bool open_activity); private: string name_; shared_ptr<service_thread> st_; shared_ptr<timer_type> timer_; pd::announcement announcement_; set<uint32_t> sids_; map<uint32_t, pd::yunying_role_simple_info_array> sid2role_infos_; uint32_t client_process_count_ = 0; }; inline bool scene_mgr_class::has_sid(uint32_t sid) const { return sids_.count(sid) > 0; } inline bool scene_mgr_class::has_role_simple_infos(uint32_t sid) const { return sid2role_infos_.count(sid) > 0; } } }
70ff2e414902f0e7d169b204046cf99cd6d37a63
6fdcb423d86e42f3d5b1695a5c0e4256c030b5a7
/include/layer/split.h
0baef3986eb6997774d2e0730119fa18893a9e9b
[]
no_license
qaz734913414/ZW_CNN
dffd349694eec3a57f24fadb5ca89e56208ce655
d0a1e2cbc3921780b71e510d107d62b07496a20e
refs/heads/master
2020-05-01T13:49:02.245943
2019-03-24T05:25:12
2019-03-24T05:25:12
null
0
0
null
null
null
null
UTF-8
C++
false
false
298
h
split.h
#pragma once #include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; class Split { private: vector <Mat> input; int copy_size = 1; public: Split(vector <Mat> input_, int copy_size_):input(input_), copy_size(copy_size_){} vector <vector<Mat>> Activation(); };
1810e98a59d84102bf924aef4deccae13d403169
a7acea5217a9b84212d14614acc5d11f79de360d
/Afanasyev/lab3/Sources/libs/MyException.h
1be39076a9007060f73c2a4878dbd989587132b7
[]
no_license
makometr/ADS-9304
f45309de83d11fa3ac8ee4edda54ffcd24906cd4
8bd69ab3726f15b1db3439876cc46985470d1a12
refs/heads/master
2023-02-15T21:05:50.387147
2021-01-06T13:46:42
2021-01-06T13:46:42
296,394,391
3
27
null
2021-01-07T21:16:59
2020-09-17T17:19:21
C++
UTF-8
C++
false
false
421
h
MyException.h
#ifndef MYEXS_H #define MYEXS_H #include <ostream> #include <string> #include <stdexcept> enum class ExceptionsNames { ex_logic_error, ex_syntax_error, }; class MyException : public std::runtime_error { std::string ex_message; public: MyException(const ExceptionsNames &inputed_ex_name, const std::string &str); friend std::ostream &operator<<(std::ostream &out, const MyException &obj); }; #endif
fb9e9c464e0e73b4445132978a458719d6f5b476
7af11ca1aaa169e046f892869da45cb57b89e37c
/server/model_header/user.h
5f01da5d9f6bad9144a34941556ef36738f26857
[]
no_license
ngocthoaia1admin/supermarket
588c02e26376f425089fd886a5344eb7fe8f11a4
52b8c38211b16a9689d532579005686ce56322ac
HEAD
2016-09-05T17:59:53.095245
2014-04-19T02:38:44
2014-04-19T02:38:44
null
0
0
null
null
null
null
UTF-8
C++
false
false
81
h
user.h
#ifndef USER_H #define USER_H class User { public: }; #endif
bd4a91479dc7b0c3efaf622a2b82e86167618f64
c08a3d64cb4cc6261c003c3eef48f7c1f54aed63
/player.cpp
4e82cccc4812b8ba10a1a308070a8102a6eb3465
[]
no_license
IvanYerkinov/WinterIntensive
88531cfaf81c5ea7d951d5c57f9177abd5141b7a
d585b67c4923b2d97f7a9bb53ec91d0d4b017964
refs/heads/master
2020-12-08T23:36:27.763643
2020-01-10T21:35:42
2020-01-10T21:35:42
233,125,623
0
0
null
null
null
null
UTF-8
C++
false
false
562
cpp
player.cpp
#include "player.h" Player::Player(QString name) : _name(name) { generateStats(); } Player::Player() { } void Player::generateStats() { QRandomGenerator *gen = QRandomGenerator::global(); _str = gen->generate() % 16 + 3; _dex = gen->generate() % 16 + 3; _con = gen->generate() % 16 + 3; _wis = gen->generate() % 16 + 3; _int = gen->generate() % 16 + 3; _cha = gen->generate() % 16 + 3; _maxhp = _con + 20; _hp = _maxhp; _maxmp = _wis + 10; _mp = _maxmp; delete gen; }
91a39d10612f360f88fbf934e31f12ff8a8c521b
17fe08a8e9fce9d0f71f1b6f28192cb7373ab88c
/zookeeper/server/quorum/LearnerInfo.hh
7c8d0bfd0453e76f3246c602472bf3a24d420345
[ "Apache-2.0" ]
permissive
cxxjava/CxxZookeeper
dcf31c6638afc37c1ebe1ba4351b31c10d991364
149677c785627aff839b2102ab265c745882fa52
refs/heads/master
2021-01-25T13:23:45.102771
2018-10-25T17:33:33
2018-10-25T17:33:33
123,562,911
19
10
null
null
null
null
UTF-8
C++
false
false
3,201
hh
LearnerInfo.hh
/* * LearnerInfo.hh * * Created on: 2017-11-22 * Author: cxxjava@163.com */ #ifndef LearnerInfo_HH_ #define LearnerInfo_HH_ #include "Efc.hh" #include "ELog.hh" #include "../../../jute/inc/ERecord.hh" #include "../../../jute/inc/EBinaryInputArchive.hh" #include "../../../jute/inc/EBinaryOutputArchive.hh" #include "../../../jute/inc/ECsvOutputArchive.hh" namespace efc { namespace ezk { class LearnerInfo : public ERecord { private: llong serverid; int protocolVersion; public: LearnerInfo() { } LearnerInfo(llong serverid, int protocolVersion) { this->serverid = serverid; this->protocolVersion = protocolVersion; } llong getServerid() { return serverid; } void setServerid(llong m_) { serverid = m_; } int getProtocolVersion() { return protocolVersion; } void setProtocolVersion(int m_) { protocolVersion = m_; } virtual void serialize(EOutputArchive* a_, const char* tag) THROWS(EIOException) { a_->startRecord(this, tag); a_->writeLLong(serverid, "serverid"); a_->writeInt(protocolVersion, "protocolVersion"); a_->endRecord(this, tag); } virtual void deserialize(EInputArchive* a_, const char* tag) THROWS(EIOException) { a_->startRecord(tag); serverid = a_->readLLong("serverid"); protocolVersion = a_->readInt("protocolVersion"); a_->endRecord(tag); } virtual EString toString() { try { EByteArrayOutputStream s; ECsvOutputArchive a_(&s); a_.startRecord(this, ""); a_.writeLLong(serverid, "serverid"); a_.writeInt(protocolVersion, "protocolVersion"); a_.endRecord(this, ""); s.write('\0'); return (char*) s.data(); } catch (EThrowable& ex) { ex.printStackTrace(); } return "ERROR"; } void write(EDataOutput* out) THROWS(EIOException) { EBinaryOutputArchive archive(out); serialize(&archive, ""); } void readFields(EDataInput* in) THROWS(EIOException) { EBinaryInputArchive archive(in); deserialize(&archive, ""); } virtual int compareTo(EObject* peer_) THROWS(EClassCastException) { LearnerInfo* peer = dynamic_cast<LearnerInfo*>(peer_); if (!peer) { throw EClassCastException(__FILE__, __LINE__, "Comparing different types of records."); } int ret = 0; ret = (serverid == peer->serverid) ? 0 : ((serverid < peer->serverid) ? -1 : 1); if (ret != 0) return ret; ret = (protocolVersion == peer->protocolVersion) ? 0 : ((protocolVersion < peer->protocolVersion) ? -1 : 1); if (ret != 0) return ret; return ret; } virtual boolean equals(EObject* peer_) { LearnerInfo* peer = dynamic_cast<LearnerInfo*>(peer_); if (!peer) { return false; } if (peer_ == this) { return true; } boolean ret = false; ret = (serverid == peer->serverid); if (!ret) return ret; ret = (protocolVersion == peer->protocolVersion); if (!ret) return ret; return ret; } virtual int hashCode() { int result = 17; int ret; ret = (int) (serverid ^ (((ullong) serverid) >> 32)); result = 37 * result + ret; ret = (int) protocolVersion; result = 37 * result + ret; return result; } static EString signature() { return "LLearnerInfo(li)"; } }; } /* namespace ezk */ } /* namespace efc */ #endif /* LearnerInfo_HH_ */
e93b6770a9d7e07de1ffde7a6eae7cef6c6a8615
0de9688de651ee81660dee187291bd97e5da1ee2
/tool/code/trunk/cxx/Common/Landmarks/include/ccipdLandmarksToMesh.h
14026d6cdf7a3c79c00c6f56c8eebeb7ec4ebf8e
[]
no_license
zengruizhao/Radiomics
2845cd7f17a46fae95be5d68b135ceda76ed4e44
34c1f1bff12fb994c904eaab0691f33819067003
refs/heads/master
2022-04-26T11:56:59.338297
2020-05-01T08:15:12
2020-05-01T08:15:12
257,222,358
3
0
null
null
null
null
UTF-8
C++
false
false
1,401
h
ccipdLandmarksToMesh.h
#ifndef __ccipdLandmarksToMesh_h #define __ccipdLandmarksToMesh_h ////////////////////////////////////////////////////////////////////////////////////////// #include "ccipdCore.h" #include "ccipdLandmarkTypes.h" #include "ccipdMeshTypes.h" // for mesh types #include "ccipdITKForwardDeclarations.h" #include "ccipdDisableWarningsMacro.h" #include <string> #include "ccipdEnableWarningsMacro.h" ////////////////////////////////////////////////////////////////////////////////////////// namespace ccipd { ////////////////////////////////////////////////////////////////////////////////////////// /** * \brief Convert landmarks to an itk mesh. * * \ingroup Common */ template< class PointSetType, unsigned int PointDimension, class MeshTraits > itk::SmartPointer< itk::Mesh< typename PointSetType::PixelType, PointDimension, MeshTraits > > LandmarksToMesh( const PointSetType * landmarks ); ////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////// /** * \brief Convert landmarks to an itk mesh in 3D. * * \ingroup Common */ VolumeMeshPointer ConvertLandmarksToMesh( const LandmarkSetType * landmarks ); ////////////////////////////////////////////////////////////////////////////////////////// } // namespace #endif // __ccipdLandmarksToMesh_h
71e8b5794e77425ee9f5238235a4473cdf4e1524
82e2f4288f270168b0e7788442fc0ec85dffc86d
/work/test-bench/test4/src/app/statemachine04a.cpp
f487eb2b17c18e7b8b4a74a1d40d53a27c1461b7
[]
no_license
LennyHEVS/XF
0d142048f453a02afbd6fecf173d342443b53950
071352fdb78dde07215973be3fe9f456aaa9292a
refs/heads/master
2023-01-06T21:06:41.999258
2020-11-04T13:30:41
2020-11-04T13:30:41
300,239,943
0
0
null
null
null
null
UTF-8
C++
false
false
1,719
cpp
statemachine04a.cpp
#include <cassert> #include "trace/trace.h" #include "events/evrestart.h" #include "statemachine04a.h" StateMachine04a::StateMachine04a() : _pNeighbour(nullptr) { _currentState = STATE_INITIAL; } StateMachine04a::~StateMachine04a() { } /** * Sets the association to the neighbour state machine. * Call this method prior the start the state machine. */ void StateMachine04a::setNeighbour(XFBehavior * pNeighbour) { _pNeighbour = pNeighbour; } /** * Returns reference to neighbour state machine. */ XFBehavior * StateMachine04a::getNeighbour() const { assert(_pNeighbour); return _pNeighbour; } /** * Implements state machine behavior. */ XFEventStatus StateMachine04a::processEvent() { eEventStatus eventStatus = XFEventStatus::Unknown; switch (_currentState) { case STATE_INITIAL: { if (getCurrentEvent()->getEventType() == XFEvent::Initial) { GEN(XFNullTransition()); _currentState = STATE_WAIT; eventStatus = XFEventStatus::Consumed; } } break; case STATE_WAIT: { if (getCurrentEvent()->getEventType() == XFEvent::NullTransition) { { Trace::out("SM04a: Wait"); } scheduleTimeout(Timeout_WAIT_id, 4500); _currentState = STATE_SEND_RESTART; eventStatus = XFEventStatus::Consumed; } } break; case STATE_SEND_RESTART: { if (getCurrentEvent()->getEventType() == XFEvent::Timeout && getCurrentTimeout()->getId() == Timeout_WAIT_id) { { Trace::out("SM04a: Send restart to SM04b"); getNeighbour()->GEN(evRestart()); } GEN(XFNullTransition()); _currentState = STATE_WAIT; eventStatus = XFEventStatus::Consumed; } } break; default: break; } return eventStatus; }
914fc175b8adfc34878cb24057be7676007eca03
ec4f25d978d26dc7b5c2a8143a18061d0fd9a6ef
/src/utils/vector_utils.cpp
a7e89de9d07ed251cacf31d050afd12f82255589
[]
no_license
tiagoraulp/map_transform
9257804a4c02b5ff1803a2e02c85b714d1382e6a
2eab2680d50744657bb3f9759d00926fc8ff01cf
refs/heads/master
2022-11-07T08:55:03.197243
2018-12-16T01:01:41
2018-12-16T01:01:41
276,139,775
0
0
null
null
null
null
UTF-8
C++
false
false
3,249
cpp
vector_utils.cpp
#include "vector_utils.hpp" #include <cmath> using namespace std; static const double PI = 3.141592653589793; vector<cv::Point> bf_hlx(int defl) { vector<cv::Point> hlx; for(int r=0; r<=defl; r++) { if(r==0) { hlx.push_back(cv::Point(0,0)); } else { for(int p=-r;p<r;p++) { int ii=0-r, jj=0+p; hlx.push_back(cv::Point(ii,jj)); ii=0+p, jj=0+r; hlx.push_back(cv::Point(ii,jj)); ii=0+r, jj=0-p; hlx.push_back(cv::Point(ii,jj)); ii=0-p, jj=0-r; hlx.push_back(cv::Point(ii,jj)); } } } return hlx; } int boundPos(int x, int max) { if(x>=max) x=max-1; if(x<0) x=0; return x; } int incAngle(int p, int num) { int u; if(p==(num-1)) u=0; else u=p+1; return u; } int decAngle(int p, int num) { int l; if(p==0) l=num-1; else l=p-1; return l; } double boundAngle(double x, double v) { if(x<0) { while(x<0) x+=v; } else { while(x>v) x-=v; } return x; } int boundValue(int x, int v) { if(x<0) { while(x<0) x+=v; } else { while(x>v) x-=v; } return x; } double boundAngleN(double x, double v) { if(x<-v) { while(x<-v) x+=2*v; } else { while(x>v) x-=2*v; } return x; } int boundValueN(int x, int v) { if(x<-v) { while(x<-v) x+=2*v; } else { while(x>v) x-=2*v; } return x; } double boundAngleR(double x) { return boundAngle(x, 2*PI); } double boundAngleD(double x) { return boundAngle(x, 360); } double boundAngleRN(double x) { return boundAngleN(x, PI); } double boundAngleDN(double x) { return boundAngleN(x, 180); } double angleDiff(double a, double b, int res) { return abs(boundAngleN( (a-b),((double)res)/2.0)); } int angleDiff(int a, int b, int res) { return (int)round(angleDiff((double) a,(double) b, res)); } int angleD2I(double rtrd, int angle_res) { rtrd=boundAngleD(rtrd); double min_err=0; int m_a=0; for(int i=0;i<angle_res;i++) { if(i==0) { m_a=i; min_err=abs(360.0/angle_res*i-rtrd); } else { if( abs(360.0/angle_res*i-rtrd)<min_err ) { m_a=i; min_err=abs(360.0/angle_res*i-rtrd); } } } if( abs(360.0/angle_res*angle_res-rtrd)<min_err ) { m_a=0; } return m_a; } int angleR2I(double rtrd, int angle_res) { return angleD2I(angleR2D(rtrd), angle_res); } double pi(void) { return PI; } cv::Point2f operator*(cv::Mat M, const cv::Point2f p){ cv::Mat src(3/*rows*/,1 /* cols */,CV_64F); src.at<double>(0,0)=p.x; src.at<double>(1,0)=p.y; src.at<double>(2,0)=1.0; cv::Mat dst = M*src; //USE MATRIX ALGEBRA return cv::Point2f(dst.at<double>(0,0),dst.at<double>(1,0)); }
8dc18fb9f9ac9b642ce7f20e69b107a690ebedd5
709c6925cc548484663a8a3d74bae84265ea5730
/zsum.cpp
8ee0de66f59cd2ff44cae56764195c221f2fa45e
[]
no_license
ashutosh1598/SPOJ
a75349226e0c489b97aa61c5a3bd84cc48057ad3
0f5fe433e9ada94a0d53373cad6dfa5017b1927a
refs/heads/master
2020-03-18T21:34:58.980948
2019-05-23T11:16:17
2019-05-23T11:16:17
135,287,927
0
1
null
null
null
null
UTF-8
C++
false
false
593
cpp
zsum.cpp
#include"iostream" #include"cmath" #include"vector" #include"algorithm" #include"set" #include"map" #include"string" using namespace std; typedef long long ll; ll mo=1e7+7; ll modexp(ll a,ll b) { if(b==0) return 1; ll ans=modexp((a*a)%mo,b/2); if(b%2==1) ans=(a*ans)%mo; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,k; cin>>n>>k; while(n!=0) { ll ans=modexp(n-1,k)*2+modexp(n,k)+modexp(n-1,n-1)*2+modexp(n,n); ans=(ans+mo)%mo; cout<<ans<<"\n"; cin>>n>>k; } }
3d8cf4ac728cccdcd62fb4f7e8c186b908310b0c
f7df42bd646b9a79057f0cf9443ad3f65c8bb5dc
/smacc_sm_examples/sm_radial_motion/include/sm_radial_motion/substates_behaviors/navigation/rotate.h
fd2727551f982d5ad8df5828f353a8887ed6acb4
[ "BSD-3-Clause" ]
permissive
NEU-ZJX/SMACC
ad1ebfe04d7bcfa37b680eec8eb276a179e2c59e
cac82a606a5456194e2ca1e404cf9fef66e78e6e
refs/heads/master
2020-09-07T23:41:45.973407
2019-11-08T07:13:31
2019-11-08T07:13:31
220,937,405
0
1
BSD-3-Clause
2019-11-11T08:44:01
2019-11-11T08:44:01
null
UTF-8
C++
false
false
2,149
h
rotate.h
#pragma once #include <smacc/smacc_substate_behavior.h> #include <smacc_navigation_plugin/move_base_to_goal.h> #include <boost/optional.hpp> #include <tf/transform_listener.h> #include <tf/tf.h> class Rotate : public smacc::SmaccSubStateBehavior { public: tf::TransformListener listener; smacc::SmaccMoveBaseActionClient *moveBaseClient_; boost::optional<float> rotateDegree; Rotate() { } Rotate(float rotate_degree) { rotateDegree = rotate_degree; } virtual void onEntry() override { double angle_increment_degree; if(!rotateDegree) { this->currentState->param("angle_increment_degree", angle_increment_degree, 90.0); } else { angle_increment_degree = *rotateDegree; } this->requiresClient(moveBaseClient_ ); //this->plannerSwitcher_->setDefaultPlanners(); moveBaseClient_->plannerSwitcher_->setForwardPlanner(); //this should work better with a coroutine and await ros::Rate rate(10.0); geometry_msgs::Pose currentPoseMsg; while (ros::ok()) { tf::StampedTransform currentPose; try{ listener.lookupTransform("/odom", "/base_link", ros::Time(0), currentPose); tf::poseTFToMsg (currentPose, currentPoseMsg); break; } catch (tf::TransformException ex){ ROS_ERROR("%s",ex.what()); ros::Duration(1.0).sleep(); } } smacc::SmaccMoveBaseActionClient::Goal goal; goal.target_pose.header.frame_id = "/odom"; goal.target_pose.header.stamp = ros::Time::now(); auto currentAngle = tf::getYaw(currentPoseMsg.orientation); auto targetAngle = currentAngle + angle_increment_degree *M_PI/180.0; goal.target_pose.pose.orientation =tf::createQuaternionMsgFromYaw(targetAngle); goal.target_pose.pose.position = currentPoseMsg.position; ROS_WARN_STREAM("rotate behavior current_state : " << currentPoseMsg); ROS_WARN_STREAM("rotate behavior target : " << goal.target_pose.pose); ROS_INFO("forward behavior: sending forward goal"); moveBaseClient_->sendGoal(goal); } };
4c5684c38ef1102b1c8afce145a5401200fc5570
d6b4bdf418ae6ab89b721a79f198de812311c783
/cdb/include/tencentcloud/cdb/v20170320/model/AuditLog.h
032d928b66091443230dd63765ac045d603f8e3f
[ "Apache-2.0" ]
permissive
TencentCloud/tencentcloud-sdk-cpp-intl-en
d0781d461e84eb81775c2145bacae13084561c15
d403a6b1cf3456322bbdfb462b63e77b1e71f3dc
refs/heads/master
2023-08-21T12:29:54.125071
2023-08-21T01:12:39
2023-08-21T01:12:39
277,769,407
2
0
null
null
null
null
UTF-8
C++
false
false
20,701
h
AuditLog.h
/* * Copyright (c) 2017-2019 THL A29 Limited, a Tencent company. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef TENCENTCLOUD_CDB_V20170320_MODEL_AUDITLOG_H_ #define TENCENTCLOUD_CDB_V20170320_MODEL_AUDITLOG_H_ #include <string> #include <vector> #include <map> #include <tencentcloud/core/utils/rapidjson/document.h> #include <tencentcloud/core/utils/rapidjson/writer.h> #include <tencentcloud/core/utils/rapidjson/stringbuffer.h> #include <tencentcloud/core/AbstractModel.h> namespace TencentCloud { namespace Cdb { namespace V20170320 { namespace Model { /** * Audit log details */ class AuditLog : public AbstractModel { public: AuditLog(); ~AuditLog() = default; void ToJsonObject(rapidjson::Value &value, rapidjson::Document::AllocatorType& allocator) const; CoreInternalOutcome Deserialize(const rapidjson::Value &value); /** * 获取Number of affected rows * @return AffectRows Number of affected rows * */ int64_t GetAffectRows() const; /** * 设置Number of affected rows * @param _affectRows Number of affected rows * */ void SetAffectRows(const int64_t& _affectRows); /** * 判断参数 AffectRows 是否已赋值 * @return AffectRows 是否已赋值 * */ bool AffectRowsHasBeenSet() const; /** * 获取The error code * @return ErrCode The error code * */ int64_t GetErrCode() const; /** * 设置The error code * @param _errCode The error code * */ void SetErrCode(const int64_t& _errCode); /** * 判断参数 ErrCode 是否已赋值 * @return ErrCode 是否已赋值 * */ bool ErrCodeHasBeenSet() const; /** * 获取 * @return SqlType * */ std::string GetSqlType() const; /** * 设置 * @param _sqlType * */ void SetSqlType(const std::string& _sqlType); /** * 判断参数 SqlType 是否已赋值 * @return SqlType 是否已赋值 * */ bool SqlTypeHasBeenSet() const; /** * 获取Audit policy name, which will be unavailable soon. * @return PolicyName Audit policy name, which will be unavailable soon. * */ std::string GetPolicyName() const; /** * 设置Audit policy name, which will be unavailable soon. * @param _policyName Audit policy name, which will be unavailable soon. * */ void SetPolicyName(const std::string& _policyName); /** * 判断参数 PolicyName 是否已赋值 * @return PolicyName 是否已赋值 * */ bool PolicyNameHasBeenSet() const; /** * 获取 * @return DBName * */ std::string GetDBName() const; /** * 设置 * @param _dBName * */ void SetDBName(const std::string& _dBName); /** * 判断参数 DBName 是否已赋值 * @return DBName 是否已赋值 * */ bool DBNameHasBeenSet() const; /** * 获取 * @return Sql * */ std::string GetSql() const; /** * 设置 * @param _sql * */ void SetSql(const std::string& _sql); /** * 判断参数 Sql 是否已赋值 * @return Sql 是否已赋值 * */ bool SqlHasBeenSet() const; /** * 获取Client address * @return Host Client address * */ std::string GetHost() const; /** * 设置Client address * @param _host Client address * */ void SetHost(const std::string& _host); /** * 判断参数 Host 是否已赋值 * @return Host 是否已赋值 * */ bool HostHasBeenSet() const; /** * 获取Username * @return User Username * */ std::string GetUser() const; /** * 设置Username * @param _user Username * */ void SetUser(const std::string& _user); /** * 判断参数 User 是否已赋值 * @return User 是否已赋值 * */ bool UserHasBeenSet() const; /** * 获取Execution time (μs) * @return ExecTime Execution time (μs) * */ int64_t GetExecTime() const; /** * 设置Execution time (μs) * @param _execTime Execution time (μs) * */ void SetExecTime(const int64_t& _execTime); /** * 判断参数 ExecTime 是否已赋值 * @return ExecTime 是否已赋值 * */ bool ExecTimeHasBeenSet() const; /** * 获取Time * @return Timestamp Time * */ std::string GetTimestamp() const; /** * 设置Time * @param _timestamp Time * */ void SetTimestamp(const std::string& _timestamp); /** * 判断参数 Timestamp 是否已赋值 * @return Timestamp 是否已赋值 * */ bool TimestampHasBeenSet() const; /** * 获取Number of returned rows * @return SentRows Number of returned rows * */ int64_t GetSentRows() const; /** * 设置Number of returned rows * @param _sentRows Number of returned rows * */ void SetSentRows(const int64_t& _sentRows); /** * 判断参数 SentRows 是否已赋值 * @return SentRows 是否已赋值 * */ bool SentRowsHasBeenSet() const; /** * 获取Thread ID * @return ThreadId Thread ID * */ int64_t GetThreadId() const; /** * 设置Thread ID * @param _threadId Thread ID * */ void SetThreadId(const int64_t& _threadId); /** * 判断参数 ThreadId 是否已赋值 * @return ThreadId 是否已赋值 * */ bool ThreadIdHasBeenSet() const; /** * 获取Number of scanned rows Note: u200dThis field may return null, indicating that no valid values can be obtained. * @return CheckRows Number of scanned rows Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ int64_t GetCheckRows() const; /** * 设置Number of scanned rows Note: u200dThis field may return null, indicating that no valid values can be obtained. * @param _checkRows Number of scanned rows Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ void SetCheckRows(const int64_t& _checkRows); /** * 判断参数 CheckRows 是否已赋值 * @return CheckRows 是否已赋值 * */ bool CheckRowsHasBeenSet() const; /** * 获取CPU u200dexecution time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @return CpuTime CPU u200dexecution time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ double GetCpuTime() const; /** * 设置CPU u200dexecution time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @param _cpuTime CPU u200dexecution time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ void SetCpuTime(const double& _cpuTime); /** * 判断参数 CpuTime 是否已赋值 * @return CpuTime 是否已赋值 * */ bool CpuTimeHasBeenSet() const; /** * 获取IO wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @return IoWaitTime IO wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ uint64_t GetIoWaitTime() const; /** * 设置IO wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @param _ioWaitTime IO wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ void SetIoWaitTime(const uint64_t& _ioWaitTime); /** * 判断参数 IoWaitTime 是否已赋值 * @return IoWaitTime 是否已赋值 * */ bool IoWaitTimeHasBeenSet() const; /** * 获取Lock wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @return LockWaitTime Lock wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ uint64_t GetLockWaitTime() const; /** * 设置Lock wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @param _lockWaitTime Lock wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ void SetLockWaitTime(const uint64_t& _lockWaitTime); /** * 判断参数 LockWaitTime 是否已赋值 * @return LockWaitTime 是否已赋值 * */ bool LockWaitTimeHasBeenSet() const; /** * 获取Start time, which forms a time accurate to nanoseconds with·`timestamp`. Note: u200dThis field may return null, indicating that no valid values can be obtained. * @return NsTime Start time, which forms a time accurate to nanoseconds with·`timestamp`. Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ uint64_t GetNsTime() const; /** * 设置Start time, which forms a time accurate to nanoseconds with·`timestamp`. Note: u200dThis field may return null, indicating that no valid values can be obtained. * @param _nsTime Start time, which forms a time accurate to nanoseconds with·`timestamp`. Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ void SetNsTime(const uint64_t& _nsTime); /** * 判断参数 NsTime 是否已赋值 * @return NsTime 是否已赋值 * */ bool NsTimeHasBeenSet() const; /** * 获取Transaction u200dduration (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @return TrxLivingTime Transaction u200dduration (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ uint64_t GetTrxLivingTime() const; /** * 设置Transaction u200dduration (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * @param _trxLivingTime Transaction u200dduration (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. * */ void SetTrxLivingTime(const uint64_t& _trxLivingTime); /** * 判断参数 TrxLivingTime 是否已赋值 * @return TrxLivingTime 是否已赋值 * */ bool TrxLivingTimeHasBeenSet() const; private: /** * Number of affected rows */ int64_t m_affectRows; bool m_affectRowsHasBeenSet; /** * The error code */ int64_t m_errCode; bool m_errCodeHasBeenSet; /** * */ std::string m_sqlType; bool m_sqlTypeHasBeenSet; /** * Audit policy name, which will be unavailable soon. */ std::string m_policyName; bool m_policyNameHasBeenSet; /** * */ std::string m_dBName; bool m_dBNameHasBeenSet; /** * */ std::string m_sql; bool m_sqlHasBeenSet; /** * Client address */ std::string m_host; bool m_hostHasBeenSet; /** * Username */ std::string m_user; bool m_userHasBeenSet; /** * Execution time (μs) */ int64_t m_execTime; bool m_execTimeHasBeenSet; /** * Time */ std::string m_timestamp; bool m_timestampHasBeenSet; /** * Number of returned rows */ int64_t m_sentRows; bool m_sentRowsHasBeenSet; /** * Thread ID */ int64_t m_threadId; bool m_threadIdHasBeenSet; /** * Number of scanned rows Note: u200dThis field may return null, indicating that no valid values can be obtained. */ int64_t m_checkRows; bool m_checkRowsHasBeenSet; /** * CPU u200dexecution time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. */ double m_cpuTime; bool m_cpuTimeHasBeenSet; /** * IO wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. */ uint64_t m_ioWaitTime; bool m_ioWaitTimeHasBeenSet; /** * Lock wait time (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. */ uint64_t m_lockWaitTime; bool m_lockWaitTimeHasBeenSet; /** * Start time, which forms a time accurate to nanoseconds with·`timestamp`. Note: u200dThis field may return null, indicating that no valid values can be obtained. */ uint64_t m_nsTime; bool m_nsTimeHasBeenSet; /** * Transaction u200dduration (μs) Note: u200dThis field may return null, indicating that no valid values can be obtained. */ uint64_t m_trxLivingTime; bool m_trxLivingTimeHasBeenSet; }; } } } } #endif // !TENCENTCLOUD_CDB_V20170320_MODEL_AUDITLOG_H_
fc92cd37dee67d1007d66caa3108605e47057bad
ee95a57ec6b101e35a2cf2ba72d46c4c2f1ae359
/aulas-praticas/laboratorio03/letra-a/agenda.h
ae0d23c7d7defec130787df5cc03e4567d4ff086
[]
no_license
diego-r93/lig-prog
fdcd177dc044cfca465582a0fc9897d1ee6bc1fb
cb3a5a6d5afe2874545a7d3a2fca03f50b31cb1e
refs/heads/main
2023-08-19T11:57:11.236557
2021-10-12T09:47:05
2021-10-12T09:47:05
415,494,971
0
0
null
null
null
null
UTF-8
C++
false
false
340
h
agenda.h
#ifndef AGENDA_H #define AGENDA_H #include <iostream> #include <vector> #include <string> using namespace std; class Agenda { public: Agenda(int = 3); void insereNome(string); void mostraNomes(); private: vector <string> contatos; string checkName(string); unsigned long maxNomes; }; #endif
b70f3fb9494a6c5863ff4336c7861d6a34d2c07c
59c47e1f8b2738fc2b824462e31c1c713b0bdcd7
/007-其他/BST_Codes/Glari_510.1A_V/BST_IDE/effect/widgetbutton.cpp
145e64600eae958b66bf2696273b25e01345a053
[]
no_license
casterbn/Qt_project
8efcc46e75e2bbe03dc4aeaafeb9e175fb7b04ab
03115674eb3612e9dc65d4fd7bcbca9ba27f691c
refs/heads/master
2021-10-19T07:27:24.550519
2019-02-19T05:26:22
2019-02-19T05:26:22
null
0
0
null
null
null
null
UTF-8
C++
false
false
3,952
cpp
widgetbutton.cpp
#include "widgetbutton.h" WidgetButton::WidgetButton(QWidget *parent) : WidgetBase(parent) { m_Checked = false; mOperate = OPERATE_NONE; mValidFlag = true; mIsPressed = false; mStatues = 0; m_BtnType = 0; mPressDelay = 100; connect(&mPressDelayTimer, SIGNAL(timeout()), this, SLOT(slot_PressDelay())); mPressDelayTimer.setSingleShot(true); mPressDelayTimer.setInterval(mPressDelay); } WidgetButton::~WidgetButton() { } void WidgetButton::SetValidRect(QRect pRect) { mValidRect = pRect; } void WidgetButton::InitButton(QString pDark, QString pLight) { load(PIC_DARK, pDark); load(PIC_LIGHT, pLight); m_ImgPointer.mLastPointer = m_ImgPointer.mCurPointer; m_ImgPointer.mCurPointer = GetPixmap(PIC_DARK); StartRender(); } void WidgetButton::mousePressEvent(QMouseEvent *e) { if (e && e->button() == Qt::LeftButton) { mValidFlag = true; if(!mValidRect.isEmpty()) { if(!mValidRect.contains(e->pos())) mValidFlag = false; } if(mValidFlag) { mIsPressed = true; if(m_BtnType == 0) { //mPressDelayTimer.start(); slot_ExecOperate(OPERATE_KEYPRESS, QVariant()); } emit sPressed(); } } QWidget::mousePressEvent(e); } void WidgetButton::slot_PressDelay() { mIsPressed = true; slot_ExecOperate(OPERATE_KEYPRESS, QVariant()); emit sPressed(); } void WidgetButton::ReleaseButton() { if(m_Checked) { m_Checked = false; slot_ExecOperate(OPERATE_KEYRELEASE, QVariant()); emit sReleased(); } } void WidgetButton::mouseMoveEvent(QMouseEvent *e) { QWidget::mouseMoveEvent(e); } void WidgetButton::mouseReleaseEvent(QMouseEvent *e) { if (e && e->button() == Qt::LeftButton) { if(mValidFlag) { mIsPressed = false; if(m_BtnType == 0) { slot_ExecOperate(OPERATE_KEYRELEASE, QVariant()); } emit sReleased(); } else { mValidFlag = true; } } QWidget::mouseReleaseEvent(e); } void WidgetButton::slot_ExecOperate(AREA_OPERATE pOperate, QVariant pPara) { m_EffectRender = m_EffectRenders.value(pOperate); switch(pOperate) { case OPERATE_KEYPRESS: { if(mOperate == pOperate) return; mOperate = pOperate; m_ImgPointer.mLastPointer = m_ImgPointer.mCurPointer; m_ImgPointer.mCurPointer = GetPixmap(PIC_LIGHT); StartRender(); break; } case OPERATE_KEYLIGHT: { if(mOperate == pOperate) return; mOperate = pOperate; m_ImgPointer.mLastPointer = m_ImgPointer.mCurPointer = GetPixmap(PIC_LIGHT); StartRender(); break; } case OPERATE_KEYCANCEL: { if(!mIsPressed) { if(mOperate == pOperate) return; mOperate = pOperate; m_ImgPointer.mLastPointer = m_ImgPointer.mCurPointer = GetPixmap(PIC_DARK); StartRender(); } break; } case OPERATE_KEYRELEASE: { if(mOperate == pOperate) return; if(mOperate != OPERATE_KEYLIGHT) { m_ImgPointer.mLastPointer = m_ImgPointer.mCurPointer; m_ImgPointer.mCurPointer = GetPixmap(PIC_DARK); StartRender(); } mOperate = pOperate; break; } default: break; } }
99800c1086c7df17ef7337e85958b1fdc9cabe1d
1333f2755b7146fe5f0165cd0f883bc5903ba279
/Microsolf Tag/Easy/204(Lint1324)Count Primes.cpp
f76543e6a2329a3824e9f6e0f97c121536357ff5
[]
no_license
Xuming8812/LeetcodeSolution
a80d3546b1ff4ce89ccff36be59f4659564fad4e
8c46bd346644f2ad080b31974dd070d49731503d
refs/heads/master
2020-04-09T05:47:11.459502
2019-09-01T19:39:17
2019-09-01T19:39:17
160,072,615
0
0
null
null
null
null
UTF-8
C++
false
false
650
cpp
204(Lint1324)Count Primes.cpp
#include<vector> #include<map> #include<string> #include<queue> #include<sstream> #include<stack> #include<set> #include<bitset> using namespace std; /* Count the number of prime numbers less than a non-negative number, n */ /** * @param n: a integer * @return: return a integer */ int countPrimes(int n) { // write your code here vector<bool> isPrime(n,true); int result{0}; for(int index = 2;index<n;index++){ if(isPrime[index]){ result++; for(int times = 0;times*index<n;times++){ isPrime[times*index] = false; } } } return result; }
cc69465159e92169b50a88fdec5c15639f4f0644
190a801aad45b16e10f542b9d99d8fa76c840add
/Framework/Sources/o2/Utils/Math/OBB.h
129d9b93e37c742eb1e57d124632dcb6b008a01c
[ "MIT" ]
permissive
zenkovich/o2
f232af2b50772d5dfcf73c6b00df395555b3542e
909a8a3f85bb9e1d430162b96c80863fe6b4ab00
refs/heads/master
2023-08-17T04:30:57.666271
2023-08-15T10:39:48
2023-08-15T10:39:48
14,099,848
226
19
null
2020-08-24T07:44:58
2013-11-04T03:38:48
C
UTF-8
C++
false
false
58
h
OBB.h
#pragma once namespace o2 { class OBB { public: }; }
b311c1ee3393bdf2431d39ea47b2c265e52e4d88
5ef608dedc72eb714b354f5c188b39a2a2e18556
/src/StateOutro.cpp
4627a026550652f1d45a3c6dc3b3ff5765135508
[]
no_license
Bezifabr/BoardGameProject
61740c44c6e29cba303a124c46ef78fc0d5f2377
2172ab561b25a0db6c217bf9fd8ab36222786b51
refs/heads/master
2021-09-18T14:33:51.008377
2018-07-15T21:33:32
2018-07-15T21:33:32
139,689,904
0
0
null
null
null
null
UTF-8
C++
false
false
115
cpp
StateOutro.cpp
#include "StateOutro.h" void StateOutro::Update() { } void StateOutro::Load() { } void StateOutro::Unload() { }
e35488d4afdb8f408dcc0e176f38f61865d8de1d
7e114a2e28abda0ae6104489e21a514a3aaed95b
/include/kT/Graphics/OGL3Device/Win/WinOGL3Context.hpp
9d25365b5c975b9fd527dae778ed53c6ec8fb028
[]
no_license
Ziple/kT
806347fcaad482e1431e2f2e3e5dab17fd106626
51d1a578feb2e9b1109491cc8de317c0d5810462
refs/heads/master
2020-06-05T00:19:09.598543
2014-08-28T19:31:01
2014-08-28T19:31:01
16,454,633
1
1
null
null
null
null
UTF-8
C++
false
false
2,475
hpp
WinOGL3Context.hpp
/** * \file OGL3Device/Win/WinOGL3Context.hpp * \author Damien Hilloulin (ziple) * \date 16/04/2009 */ #ifndef __KTWINOGL3CONTEXT_HPP__ #define __KTWINOGL3CONTEXT_HPP__ #include <kT/Core/Build.hpp> #include <kT/Core/Types.hpp> #include <kT/Graphics/OGL3Device/OGL.hpp> typedef struct HGLRC__ *HGLRC; typedef struct HDC__ *HDC; namespace kT { // forward declarations class Window; /** * \ingroup ktogl3device_module * \brief Implementation of the OGL3Context for Windows. */ class KT_API WinOGL3Context { public: /** * \brief Constructor. */ WinOGL3Context( Window* Window = 0, WinOGL3Context* sharedWith = 0, unsigned redBits = 8, unsigned greenBits = 8, unsigned blueBits = 8, unsigned alhaBits = 0, unsigned depth = 0, unsigned stencil = 0 ); /** * \brief Destructor. */ ~WinOGL3Context(); /** * \brief Returns the handle to the context (HGLRC). */ inline HGLRC GetHandle() const{return myOGLContext;} /** * \brief Returns a pointer to the fonction. * \return NULL if not successful. */ FunctionPointer GetProcAddress( const char* procName ); /** * \brief Enables/disables the framerate limitation. */ void LimitFramerate( bool limit = true ); /** * \brief Tells if the context is currently attached to this thread. */ bool IsCurrent() const; /** * \brief Attachs the context to the thread. */ void MakeCurrent(); /** * \brief Swaps the buffers of the window. */ void SwapBuffers(); /** * \brief Returns the attached window. */ inline Window* GetAttachedWindow() const{return myWindow;} private: HGLRC myOGLContext; ///< The OGL context. HDC myDC; ///< The DeviceContext for the window. Window* myWindow;///< The attached window. }; } #endif /* __KTWINOGL3CONTEXT_HPP__ */
8cdc5c21a5cdd6a4c1379c415b28b97ca8f7aabd
53360319eaf69ff75f34e1c2c45cbcdfd12842c9
/groups/bdl/bdlt/bdlt_iso8601util.00.t.cpp
76a27674ff2bec8d23ca72ee2857e0b93d2dca8e
[ "Apache-2.0" ]
permissive
bloomberg/bde
229de23237d9cc0937ec2d0b69ef7dfcb1fa2154
7cc8e30c7218eaffbc31f518bd40794cc79f7282
refs/heads/main
2023-09-01T08:52:24.600136
2023-08-31T17:43:40
2023-08-31T17:43:40
6,619,178
1,429
338
Apache-2.0
2023-05-20T13:33:26
2012-11-09T20:00:30
C++
UTF-8
C++
false
false
761,843
cpp
bdlt_iso8601util.00.t.cpp
// bdlt_iso8601util.00.t.cpp -*-C++-*- #include <bdlt_iso8601util.h> // This test driver is split into several executables to enable compilation on // platforms/compilers where the complete test code (with its many template // instantiations) ends up needing too much resources during compilation, // making it impossible to compile the code, or extremely slow. // // This test driver file contains all the 'bdlt_iso8601util' test code and it // is split into parts using conditional compilation. It is '#include'd in the // individual test parts (01-02) after defining the // 'BDLT_ISO8601UTIL_TEST_PART_NUMBER' macro to the part number of the // including file. When 'BDLT_ISO8601UTIL_TEST_PART_NUMBER' is defined and its // value is between 1-2 only the test code necessary for that part will be // compiled, including conditional compilation of some common code (to avoid // "unused" warnings) and of course the test cases in the 'main' function. // This method of splitting up a test driver to multiple test executables keeps // all the test code in one place (file), but still allows us to build (or to // build in reasonable time) the test driver. // // Note that to make sure that an IDE or smart editor does not gray out all the // code when editing if 'BDLT_ISO8601UTIL_TEST_PART_NUMBER' is undefined, *all* // code is enabled (like a non-split test driver). The code itself sets that // value if the '__INTELLISENSE__' (Microsoft IDE specific predefined) or // either one of the 'BDLT_ISO8601UTIL_TEST_ENABLE_ALL', or 'BDE_TARGET_EDITOR' // are defined. The 'BDE_TARGET_EDITOR' macro is meant to affect all split // test drivers, while 'BDLT_ISO8601UTIL_TEST_ENABLE_ALL' will only make all // effective test code active in this component test driver files. // // Set your smart editor or IDE to define 'BDLT_ISO8601UTIL_TEST_ENABLE_ALL' // when editing this file for the syntax highlighting to show all "interesting" // code active (not grayed out, or otherwise show inactive). If you prefer all // split test drivers to be shown that way (all test code active) just define // 'BDE_TARGET_EDITOR' for your syntax-highlighting tool. // // When no control macro is defined this file (conditionally) compiles into an // empty test driver that return success for test case 1, and -1 (no such test // case) for test case number 2. Test case number 1 returns success (and // prints when run 'verbose') so that pedantic test runners won't warn that "no // tests were run". #undef U_TEST_ENABLE_ALL #undef U_TEST_COMPILING_NO_CASES #undef U_TEST_NUMBER #undef U_TEST_COMPILING_A_PART #undef U_TEST_PART_01 #undef U_TEST_PART_02 #ifndef BDLT_ISO8601UTIL_TEST_PART_NUMBER // Test part number not defined means: editing or compiling part 00 # if defined(__INTELLISENSE__) || defined(BDE_TARGET_EDITOR) // Allow the IDE to see all code. # define U_TEST_ENABLE_ALL # define U_TEST_COMPILING_A_PART # else // not editing and no part number defined: we need a mock main # define U_TEST_COMPILING_NO_CASES # endif #elif BDLT_ISO8601UTIL_TEST_PART_NUMBER >= 1 \ && BDLT_ISO8601UTIL_TEST_PART_NUMBER <= 2 // Number is defined and in range # define U_TEST_NUMBER BDLT_ISO8601UTIL_TEST_PART_NUMBER # define U_TEST_COMPILING_A_PART #else // If a bad test number is defined # error 'BDLT_ISO8601UTIL_TEST_PART_NUMBER' must be 1-2, or not defined. Sun_Studio_only_gives_a_warning_for_pound_error; #endif // out-of-range BDLT_ISO8601UTIL_TEST_PART_NUMBER #if 1 == U_TEST_NUMBER || defined(U_TEST_ENABLE_ALL) # define U_TEST_PART_01 #endif #if 2 == U_TEST_NUMBER || defined(U_TEST_ENABLE_ALL) # define U_TEST_PART_02 #endif #define U_TEST_CASE_SKIPPED \ cout << "Test case " << test << " is skipped in this executable.\n"; #ifdef U_TEST_COMPILING_A_PART #include <bdlt_date.h> #include <bdlt_datetime.h> #include <bdlt_datetimetz.h> #include <bdlt_datetz.h> #include <bdlt_time.h> #include <bdlt_timetz.h> #include <bdlb_chartype.h> #include <bslim_testutil.h> #include <bsls_asserttest.h> #include <bsls_review.h> #include <bsl_climits.h> #include <bsl_cstdlib.h> #include <bsl_cstring.h> #include <bsl_sstream.h> #include <bsl_string.h> using namespace BloombergLP; using bsl::ptrdiff_t; #endif #include <bsl_iostream.h> using bsl::cout; using bsl::cerr; using bsl::endl; using bsl::ends; using bsl::flush; #undef SEC // used as a variable name sometimes //============================================================================= // TEST PLAN //----------------------------------------------------------------------------- // NOTICE: To reduce the compilation time and enable compiling by certain // compilers (that easily run out of resources), the test driver has been // split into parts. // // 'bdlt_iso8601util.00.t.cpp': (this file, does not execute code) // 'bdlt_iso8601util.01.t.cpp': 1: BREATHING TEST // 2: GENERATE 'Date' // 3: GENERATE 'Time' // 4: GENERATE 'Datetime' // 5: GENERATE 'DateTz' // 6: GENERATE 'TimeTz' // 7: GENERATE 'DatetimeTz' // 8: PARSE: DATE & DATETZ // 9: PARSE: bsls::TimeInterval // 10: PARSE: TIME & TIMETZ // 'bdlt_iso8601util.02.t.cpp': 11: PARSE: DATETIME & DATETIMETZ // 12: GENERATE 'DateOrDateTz' // 13: GENERATE 'TimeTz' // 14: GENERATE 'DatetimeTz' // 15: PARSE 'DateOrDateTz' // 16: PARSE 'TimeOrTimeTz' // 17: PARSE 'DatetimeOrDatetimeTz' // 18: PARSE 'Datetime's WITH TIME ZONES // 19: USAGE EXAMPLE //----------------------------------------------------------------------------- // // Overview // -------- // The component under test consists of a suite of static member functions // (pure functions) that perform conversions between the values of several // 'bdlt' vocabulary types and corresponding string representations, where the // latter are defined by the ISO 8601 standard. The general plan is that each // function is to be independently tested using the table-driven technique. A // set of test vectors is defined globally for use in testing all functions. // This global data is sufficient for thoroughly testing the string generating // functions, but additional test vectors are required to address concerns // specific to the string parsing functions. Hence, additional test data is // defined locally to the test cases that verify parsing. // // Global Concerns: //: o No memory is ever allocated from the global allocator. //: o Precondition violations are detected in appropriate build modes. //----------------------------------------------------------------------------- // CLASS METHODS // [ 1] int generate(char *, int, const TimeInterval&); // [ 1] int generate(char *, int, const TimeInterval&, const Config&); // [ 2] int generate(char *, int, const Date&); // [ 2] int generate(char *, int, const Date&, const Config&); // [ 3] int generate(char *, int, const Time&); // [ 3] int generate(char *, int, const Time&, const Config&); // [ 4] int generate(char *, int, const Datetime&); // [ 4] int generate(char *, int, const Datetime&, const Config&); // [ 5] int generate(char *, int, const DateTz&); // [ 5] int generate(char *, int, const DateTz&, const Config&); // [ 6] int generate(char *, int, const TimeTz&); // [ 6] int generate(char *, int, const TimeTz&, const Config&); // [ 7] int generate(char *, int, const DatetimeTz&); // [ 7] int generate(char *, int, const DatetimeTz&, const Config&); // [12] int generate(char *, int, const DateOrDateTz&); // [12] int generate(char *, int, const DateOrDateTz&, const Config&); // [13] int generate(char *, int, const TimeOrTimeTz&); // [13] int generate(char *, int, const TimeOrTimeTz&, const Config&); // [14] int generate(char *, int, const DatetimeOrDatetimeTz&); // [14] int generate(char*,int,const DatetimeOrDatetimeTz&,const Config&); // [ 1] int generate(string *, const TimeInterval&); // [ 1] int generate(string *, const TimeInterval&, const Config&); // [ 2] int generate(string *, const Date&); // [ 2] int generate(string *, const Date&, const Config&); // [ 3] int generate(string *, const Time&); // [ 3] int generate(string *, const Time&, const Config&); // [ 4] int generate(string *, const Datetime&); // [ 4] int generate(string *, const Datetime&, const Config&); // [ 5] int generate(string *, const DateTz&); // [ 5] int generate(string *, const DateTz&, const Config&); // [ 6] int generate(string *, const TimeTz&); // [ 6] int generate(string *, const TimeTz&, const Config&); // [ 7] int generate(string *, const DatetimeTz&); // [ 7] int generate(string *, const DatetimeTz&, const Config&); // [12] int generate(string *, const DateOrDateTz&); // [12] int generate(string *, const DateOrDateTz&, const Config&); // [13] int generate(string *, const TimeOrTimeTz&); // [13] int generate(string *, const TimeOrTimeTz&, const Config&); // [14] int generate(string *, const DatetimeOrDatetimeTz&); // [14] int generate(string*, const DatetimeOrDatetimeTz&, const Config&); // [ 1] ostream generate(ostream&, const TimeInterval&); // [ 1] ostream generate(ostream&, const TimeInterval&, const Config&); // [ 2] ostream generate(ostream&, const Date&); // [ 2] ostream generate(ostream&, const Date&, const Config&); // [ 3] ostream generate(ostream&, const Time&); // [ 3] ostream generate(ostream&, const Time&, const Config&); // [ 4] ostream generate(ostream&, const Datetime&); // [ 4] ostream generate(ostream&, const Datetime&, const Config&); // [ 5] ostream generate(ostream&, const DateTz&); // [ 5] ostream generate(ostream&, const DateTz&, const Config&); // [ 6] ostream generate(ostream&, const TimeTz&); // [ 6] ostream generate(ostream&, const TimeTz&, const Config&); // [ 7] ostream generate(ostream&, const DatetimeTz&); // [ 7] ostream generate(ostream&, const DatetimeTz&, const Config&); // [12] ostream generate(ostream&, const DateOrDateTz&); // [12] ostream generate(ostream&, const DateOrDateTz&, const Config&); // [13] ostream generate(ostream&, const TimeOrTimeTz&); // [13] ostream generate(ostream&, const TimeOrTimeTz&, const Config&); // [14] ostream generate(ostream&, const DatetimeOrDatetimeTz&); // [14] ostream generate(ostream&,const DatetimeOrDatetimeTz&,const Con&); // [ 1] int generateRaw(char *, const TimeInterval&); // [ 1] int generateRaw(char *, const TimeInterval&, const Config&); // [ 2] int generateRaw(char *, const Date&); // [ 2] int generateRaw(char *, const Date&, const Config&); // [ 3] int generateRaw(char *, const Time&); // [ 3] int generateRaw(char *, const Time&, const Config&); // [ 4] int generateRaw(char *, const Datetime&); // [ 4] int generateRaw(char *, const Datetime&, const Config&); // [ 5] int generateRaw(char *, const DateTz&); // [ 5] int generateRaw(char *, const DateTz&, const Config&); // [ 6] int generateRaw(char *, const TimeTz&); // [ 6] int generateRaw(char *, const TimeTz&, const Config&); // [ 7] int generateRaw(char *, const DatetimeTz&); // [ 7] int generateRaw(char *, const DatetimeTz&, const Config&); // [12] int generateRaw(char *, const DateOrDateTz&); // [12] int generateRaw(char *, const DateOrDateTz&, const Config&); // [13] int generateRaw(char *, const TimeOrTimeTz&); // [13] int generateRaw(char *, const TimeOrTimeTz&, const Config&); // [14] int generateRaw(char *, const DatetimeOrDatetimeTz&); // [14] int generateRaw(char*,const DatetimeOrDatetimeTz&, const Config&); // [ 8] int parse(TimeInterval *, const char *, int); // [ 9] int parse(Date *, const char *, int); // [10] int parse(Time *, const char *, int); // [ 9] int parse(DateTz *, const char *, int); // [10] int parse(TimeTz *, const char *, int); // [15] int parse(DateOrDateTz *, const char *, int); // [16] int parse(TimeOrTimeTz *, const char *, int); // [ 8] int parse(TimeInterval *result, const StringRef& string); // [ 9] int parse(Date *result, const StringRef& string); // [10] int parse(Time *result, const StringRef& string); // [ 9] int parse(DateTz *result, const StringRef& string); // [10] int parse(TimeTz *result, const StringRef& string); // [15] int parse(DateOrDateTz *result, const StringRef& string); // [15] int parse(TimeOrTimeTz *result, const StringRef& string); // [17] int parse(DatetimeOrDatetimeTz *, const char *, int); // [17] int parse(DatetimeOrDatetimeTz *result, const StringRef& string); // [17] int parseRelaxed(DatetimeOrDatetimeTz *, const char *, int); // [17] int parseRelaxed(DatetimeOrDatetimeTz *, const bsl::string_view&); // [11] int parse(Datetime *, const char *, int); // [11] int parse(DatetimeTz *, const char *, int); // [11] int parse(Datetime *result, const StringRef& string); // [11] int parse(DatetimeTz *result, const StringRef& string); // [11] int parseRelaxed(Datetime *, const char *, int); // [11] int parseRelaxed(DatetimeTz *, const char *, int); // [11] int parseRelaxed(Datetime *, const bsl::string_view&); // [11] int parseRelaxed(DatetimeTz *, const bsl::string_view&); #ifndef BDE_OMIT_INTERNAL_DEPRECATED // [ 2] int generate(char *, const Date&, int); // [ 3] int generate(char *, const Time&, int); // [ 4] int generate(char *, const Datetime&, int); // [ 5] int generate(char *, const DateTz&, int); // [ 6] int generate(char *, const TimeTz&, int); // [ 7] int generate(char *, const DatetimeTz&, int); // [ 5] int generate(char *, const DateTz&, int, bool useZ); // [ 6] int generate(char *, const TimeTz&, int, bool useZ); // [ 7] int generate(char *, const DatetimeTz&, int, bool useZ); // [ 5] ostream generate(ostream&, const DateTz&, bool useZ); // [ 6] ostream generate(ostream&, const TimeTz&, bool useZ); // [ 7] ostream generate(ostream&, const DatetimeTz&, bool useZ); // [ 5] int generateRaw(char *, const DateTz&, bool useZ); // [ 6] int generateRaw(char *, const TimeTz&, bool useZ); // [ 7] int generateRaw(char *, const DatetimeTz&, bool useZ); #endif // BDE_OMIT_INTERNAL_DEPRECATED //----------------------------------------------------------------------------- // [18] USAGE EXAMPLE //----------------------------------------------------------------------------- // ============================================================================ // STANDARD BDE ASSERT TEST FUNCTION // ---------------------------------------------------------------------------- namespace { int testStatus = 0; #ifdef U_TEST_COMPILING_A_PART void aSsErT(bool condition, const char *message, int line) { if (condition) { cout << "Error " __FILE__ "(" << line << "): " << message << " (failed)" << endl; if (0 <= testStatus && testStatus <= 100) { ++testStatus; } } } #endif // U_TEST_COMPILING_A_PART } // close unnamed namespace // ============================================================================ // STANDARD BDE TEST DRIVER MACRO ABBREVIATIONS // ---------------------------------------------------------------------------- #ifdef U_TEST_COMPILING_A_PART # define ASSERT BSLIM_TESTUTIL_ASSERT # define ASSERTV BSLIM_TESTUTIL_ASSERTV # define LOOP_ASSERT BSLIM_TESTUTIL_LOOP_ASSERT # define LOOP0_ASSERT BSLIM_TESTUTIL_LOOP0_ASSERT # define LOOP1_ASSERT BSLIM_TESTUTIL_LOOP1_ASSERT # define LOOP2_ASSERT BSLIM_TESTUTIL_LOOP2_ASSERT # define LOOP3_ASSERT BSLIM_TESTUTIL_LOOP3_ASSERT # define LOOP4_ASSERT BSLIM_TESTUTIL_LOOP4_ASSERT # define LOOP5_ASSERT BSLIM_TESTUTIL_LOOP5_ASSERT # define LOOP6_ASSERT BSLIM_TESTUTIL_LOOP6_ASSERT # define Q BSLIM_TESTUTIL_Q // Quote identifier literally. # define P BSLIM_TESTUTIL_P // Print identifier and value. # define P_ BSLIM_TESTUTIL_P_ // P(X) without '\n'. # define T_ BSLIM_TESTUTIL_T_ // Print a tab (w/o newline). # define L_ BSLIM_TESTUTIL_L_ // current Line number // ============================================================================ // NEGATIVE-TEST MACRO ABBREVIATIONS // ---------------------------------------------------------------------------- # define ASSERT_SAFE_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_PASS(EXPR) # define ASSERT_SAFE_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_SAFE_FAIL(EXPR) # define ASSERT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_PASS(EXPR) # define ASSERT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_FAIL(EXPR) # define ASSERT_OPT_PASS(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_PASS(EXPR) # define ASSERT_OPT_FAIL(EXPR) BSLS_ASSERTTEST_ASSERT_OPT_FAIL(EXPR) #endif // U_TEST_COMPILING_A_PART //============================================================================= // GLOBALS, TYPEDEFS, CONSTANTS FOR TESTING //----------------------------------------------------------------------------- #ifdef U_TEST_COMPILING_A_PART typedef bdlt::Iso8601Util Util; typedef bdlt::Iso8601UtilConfiguration Config; typedef bsl::string_view StrView; const int k_INTERVAL_MAX_PRECISION = 9; const int k_DATE_MAX_PRECISION = 3; const int k_DATETZ_MAX_PRECISION = 3; const int k_DATETIME_MAX_PRECISION = 6; const int k_DATETIMETZ_MAX_PRECISION = 6; const int k_TIME_MAX_PRECISION = 6; const int k_TIMETZ_MAX_PRECISION = 6; #endif // U_TEST_COMPILING_A_PART // ============================================================================ // GLOBAL TEST DATA // ---------------------------------------------------------------------------- #ifdef U_TEST_COMPILING_A_PART // Define DEFAULT DATA generally usable across 'generate' and 'parse' test // cases. // *** 'TimeInterval' Data *** struct DefaultIntervalDataRow { int d_line; // source line number bsls::Types::Int64 d_sec; // seconds int d_usec; // nanoseconds const char *d_iso8601; // ISO 8601 string bool d_canonical; // There are many strings which can be // parsed into the same TimeInterval, // but for each TimeInterval there is // only one canonical string // representation (the string returned // by the generate functions). }; static const DefaultIntervalDataRow DEFAULT_INTERVAL_DATA[] = { //LINE SECONDS NANOSECONDS //---- ------------------------------ ----------- // ISO8601 CANONICAL // ------------------------------------ --------- { L_, 0, 0, "P0W", false }, { L_, 0, 0, "P0D", false }, { L_, 0, 0, "PT0H", false }, { L_, 0, 0, "PT0M", false }, { L_, 0, 0, "PT0S", false }, { L_, 0, 0, "PT0.000000000S", true }, { L_, 0, 0, "P0DT0M", false }, { L_, 0, 0, "P0DT0S", false }, { L_, 0, 0, "P0W0DT0H0M0S", false }, { L_, 0, 0, "P0W0DT0H0M0.0S", false }, { L_, 0, 0, "P0W0DT0H0M0.000000000S", false }, { L_, 0, 0, "P0W0DT0H0M0.0000000000S", false }, { L_, 604800, 0, "P1W", false }, { L_, 604800, 0, "P1WT0.000000000S", true }, { L_, 86400, 0, "P1D", false }, { L_, 86400, 0, "P1DT0.000000000S", true }, { L_, 3600, 0, "PT1H", false }, { L_, 3600, 0, "PT1H0.000000000S", true }, { L_, 60, 0, "PT1M", false }, { L_, 60, 0, "PT1M0.000000000S", true }, { L_, 1, 0, "PT1S", false }, { L_, 1, 0, "PT1.000000000S", true }, { L_, 93600, 0, "P1DT2H0.000000000S", true }, { L_, 93600, 0, "PT26H", false }, { L_, 172800 + 300, 0, "P2DT5M0.000000000S", true }, { L_, 172800 + 300, 0, "P2DT5M", false }, { L_, 259200 + 7, 0, "P3DT7.000000000S", true }, { L_, 604800 + 86400 + 7200 + 240 + 5, 5497, "P1W1DT2H4M5.000005497S", true }, { L_, 0, 3000000, "PT0.003000000S", true }, { L_, 0, 3000000, "PT0.0030S", false }, { L_, 0, 3000000, "P0W0DT0H0M0.003S", false }, { L_, 0, 3000000, "P0W0DT0H0M0.0030S", false }, { L_, 0, 5, "PT0.0000000045S", false }, { L_, 0, 4, "PT0.00000000449S", false }, { L_, 9223372036854775807LL, 999999999, "PT9223372036854775807.999999999S", false }, { L_, 9223372036854775807LL, 999999999, "P15250284452471W3DT15H30M7.999999999S", true }, }; const int NUM_DEFAULT_INTERVAL_DATA = static_cast<int>(sizeof DEFAULT_INTERVAL_DATA / sizeof *DEFAULT_INTERVAL_DATA); // *** 'Date' Data *** struct DefaultDateDataRow { int d_line; // source line number int d_year; // year (of calendar date) int d_month; // month int d_day; // day const char *d_iso8601; // ISO 8601 string }; static const DefaultDateDataRow DEFAULT_DATE_DATA[] = { //LINE YEAR MONTH DAY ISO8601 //---- ---- ----- --- ------------ { L_, 1, 1, 1, "0001-01-01" }, { L_, 9, 9, 9, "0009-09-09" }, { L_, 30, 10, 20, "0030-10-20" }, { L_, 842, 12, 19, "0842-12-19" }, { L_, 1847, 5, 19, "1847-05-19" }, { L_, 2000, 2, 29, "2000-02-29" }, { L_, 9999, 12, 31, "9999-12-31" }, }; const int NUM_DEFAULT_DATE_DATA = static_cast<int>(sizeof DEFAULT_DATE_DATA / sizeof *DEFAULT_DATE_DATA); // *** 'Time' Data *** struct DefaultTimeDataRow { int d_line; // source line number int d_hour; // hour (of day) int d_min; // minute int d_sec; // second int d_msec; // millisecond int d_usec; // microsecond const char *d_iso8601; // ISO 8601 string }; static const DefaultTimeDataRow DEFAULT_TIME_DATA[] = { //LINE HOUR MIN SEC MSEC USEC ISO8601 //---- ---- --- --- ---- ---- ----------------- { L_, 0, 0, 0, 0, 0, "00:00:00.000000" }, { L_, 1, 2, 3, 4, 5, "01:02:03.004005" }, { L_, 10, 20, 30, 40, 50, "10:20:30.040050" }, { L_, 19, 43, 27, 805, 107, "19:43:27.805107" }, { L_, 23, 59, 59, 999, 999, "23:59:59.999999" }, { L_, 24, 0, 0, 0, 0, "24:00:00.000000" }, }; const int NUM_DEFAULT_TIME_DATA = static_cast<int>(sizeof DEFAULT_TIME_DATA / sizeof *DEFAULT_TIME_DATA); // *** Zone Data *** struct DefaultZoneDataRow { int d_line; // source line number int d_offset; // offset (in minutes) from UTC const char *d_iso8601; // ISO 8601 string }; static const DefaultZoneDataRow DEFAULT_ZONE_DATA[] = { //LINE OFFSET ISO8601 //---- ------ -------- { L_, -1439, "-23:59" }, { L_, -120, "-02:00" }, { L_, -30, "-00:30" }, { L_, 0, "+00:00" }, { L_, 90, "+01:30" }, { L_, 240, "+04:00" }, { L_, 1439, "+23:59" }, }; const int NUM_DEFAULT_ZONE_DATA = static_cast<int>(sizeof DEFAULT_ZONE_DATA / sizeof *DEFAULT_ZONE_DATA); // *** Configuration Data *** struct DefaultCnfgDataRow { int d_line; // source line number bool d_omitColon; // 'omitColonInZoneDesignator' attribute int d_precision; // 'precision' " bool d_useComma; // 'useCommaForDecimalSign' " bool d_useZ; // 'useZAbbreviationForUtc' " }; static const DefaultCnfgDataRow DEFAULT_CNFG_DATA[] = { //LINE omit ':' precision use ',' use 'Z' //---- -------- --------- ------- ------- { L_, false, 3, false, false }, { L_, false, 3, false, true }, { L_, false, 3, true, false }, { L_, false, 3, true, true }, { L_, false, 6, false, false }, { L_, false, 6, false, true }, { L_, false, 6, true, false }, { L_, false, 6, true, true }, { L_, true, 3, false, false }, { L_, true, 3, false, true }, { L_, true, 3, true, false }, { L_, true, 3, true, true }, { L_, true, 6, false, false }, { L_, true, 6, false, true }, { L_, true, 6, true, false }, { L_, true, 6, true, true }, // additional configurations { L_, false, 0, false, false }, { L_, false, 1, false, false }, { L_, false, 2, false, false }, { L_, false, 4, false, false }, { L_, false, 5, false, false } }; const int NUM_DEFAULT_CNFG_DATA = static_cast<int>(sizeof DEFAULT_CNFG_DATA / sizeof *DEFAULT_CNFG_DATA); // Define BAD (invalid) DATA generally usable across 'parse' test cases. // *** Bad 'Date' Data *** struct BadDateDataRow { int d_line; // source line number const char *d_invalid; // test string }; static const BadDateDataRow BAD_DATE_DATA[] = { //LINE INPUT STRING //---- ------------------------- { L_, "" }, // length = 0 { L_, "0" }, // length = 1 { L_, "-" }, { L_, "+" }, { L_, "T" }, { L_, "Z" }, { L_, ":" }, { L_, " " }, { L_, "12" }, // length = 2 { L_, "3T" }, { L_, "4-" }, { L_, "x1" }, { L_, "T:" }, { L_, "+:" }, { L_, "999" }, // length = 3 { L_, "9999" }, // length = 4 { L_, "1-9-" }, { L_, "4-5-6" }, // length = 5 { L_, "+0130" }, { L_, "1-01-1" }, // length = 6 { L_, "01-1-1" }, { L_, "1-1-01" }, { L_, "02-02-2" }, // length = 7 { L_, "03-3-03" }, { L_, "4-04-04" }, { L_, "05-05-05" }, // length = 8 { L_, "005-05-5" }, { L_, "006-6-06" }, { L_, "0006-6-6" }, { L_, "0007-07-7" }, // length = 9 { L_, "0008-8-08" }, { L_, "009-09-09" }, { L_, "0001 01-01" }, // length = 10 { L_, "0001-01:01" }, { L_, "0000-01-01" }, { L_, "0001-00-01" }, { L_, "0001-13-01" }, { L_, "0001-01-00" }, { L_, "0001-01-32" }, { L_, "0001-04-31" }, { L_, "1900-02-29" }, { L_, "2000-02-30" }, { L_, "0001-01-010" }, // length = 11 { L_, "1970-12-310" }, }; const int NUM_BAD_DATE_DATA = static_cast<int>(sizeof BAD_DATE_DATA / sizeof *BAD_DATE_DATA); static const BadDateDataRow BASIC_BAD_DATE_DATA[] = { //LINE INPUT STRING //---- ------------------------- { L_, "" }, // length = 0 { L_, "0" }, // length = 1 { L_, "-" }, { L_, "+" }, { L_, "T" }, { L_, "Z" }, { L_, ":" }, { L_, " " }, { L_, "12" }, // length = 2 { L_, "3T" }, { L_, "4-" }, { L_, "x1" }, { L_, "T:" }, { L_, "+:" }, { L_, "456" }, // length = 5 { L_, "999" }, // length = 3 { L_, "9999" }, // length = 4 { L_, "1011" }, { L_, "0111" }, { L_, "1101" }, { L_, "02022" }, // length = 5 { L_, "03303" }, { L_, "40404" }, { L_, "+0130" }, { L_, "050505" }, // length = 6 { L_, "005055" }, { L_, "006606" }, { L_, "000666" }, { L_, "0007077" }, // length = 7 { L_, "0008808" }, { L_, "0090909" }, { L_, "000101010" }, // length = 9 { L_, "197012310" }, }; const int NUM_BASIC_BAD_DATE_DATA = static_cast<int>(sizeof BASIC_BAD_DATE_DATA / sizeof *BASIC_BAD_DATE_DATA); // *** Bad 'Time' Data *** struct BadTimeDataRow { int d_line; // source line number const char *d_invalid; // test string }; static const BadTimeDataRow BAD_TIME_DATA[] = { //LINE INPUT STRING //---- ------------------------- { L_, "" }, // length = 0 { L_, "0" }, // length = 1 { L_, "-" }, { L_, "+" }, { L_, "T" }, { L_, "Z" }, { L_, ":" }, { L_, "." }, { L_, "," }, { L_, " " }, { L_, "12" }, // length = 2 { L_, "3T" }, { L_, "4-" }, { L_, "x1" }, { L_, "T:" }, { L_, "+:" }, { L_, "222" }, // length = 3 { L_, "000" }, { L_, "1:2" }, { L_, "1234" }, // length = 4 { L_, "1:19" }, { L_, "11:9" }, { L_, "12:60" }, // length = 5 { L_, "2:001" }, { L_, "24:01" }, { L_, "25:00" }, { L_, "99:00" }, { L_, "1:2:30" }, // length = 6 { L_, "1:20:3" }, { L_, "10:2:3" }, { L_, "1:2:3." }, { L_, "12:100" }, { L_, ":12:12" }, { L_, "12:00:1" }, // length = 7 { L_, "12:0:01" }, { L_, "2:10:01" }, { L_, "24:00.1" }, { L_, "12:2:001" }, // length = 8 { L_, "3:02:001" }, { L_, "3:2:0001" }, { L_, "20:20:61" }, { L_, "24:00:01" }, { L_, "04:05:06." }, // length = 9 { L_, "04:05:006" }, { L_, "12:59:100" }, { L_, "03:02:001." }, // length = 10 { L_, "03:02:001," }, { L_, "03:2:001.1" }, { L_, "24:00:00.1" }, { L_, "24:00:00.01" }, // length = 11 { L_, "24:00:00.001" }, // length = 12 { L_, "24:00:00.999" }, { L_, "25:00:00.000" }, { L_, "24:00:00.000001" }, // length = 15 }; const int NUM_BAD_TIME_DATA = static_cast<int>(sizeof BAD_TIME_DATA / sizeof *BAD_TIME_DATA); static const BadTimeDataRow BASIC_BAD_TIME_DATA[] = { //LINE INPUT STRING //---- ------------------------- { L_, "" }, // length = 0 { L_, "0" }, // length = 1 { L_, "-" }, { L_, "+" }, { L_, "T" }, { L_, "Z" }, { L_, ":" }, { L_, "." }, { L_, "," }, { L_, " " }, { L_, "12" }, // length = 2 { L_, "3T" }, { L_, "4-" }, { L_, "x1" }, { L_, "T:" }, { L_, "+:" }, { L_, "222" }, // length = 3 { L_, "000" }, { L_, "119" }, { L_, "1234" }, // length = 4 { L_, "123." }, { L_, "1260" }, { L_, "2001" }, { L_, "2401" }, { L_, "2500" }, { L_, "9900" }, { L_, "1230" }, { L_, "1203" }, { L_, "1023" }, { L_, "1212" }, { L_, "12100" }, // length = 5 { L_, "12001" }, { L_, "12001" }, { L_, "21001" }, { L_, "2400.1" }, // length = 6 { L_, "040506." }, // length = 7 { L_, "0405006" }, { L_, "1259100" }, { L_, "0302001." }, // length = 8 { L_, "0302001," }, { L_, "240000.1" }, { L_, "240000.01" }, // length = 9 { L_, "240000.001" }, // length = 10 { L_, "240000.999" }, { L_, "250000.000" }, { L_, "240000.0001" }, // length = 11 { L_, "240000.00001" }, // length = 12 { L_, "240000.000001" }, // length = 13 }; const int NUM_BASIC_BAD_TIME_DATA = static_cast<int>(sizeof BASIC_BAD_TIME_DATA / sizeof *BASIC_BAD_TIME_DATA); // *** Bad Zone Data *** struct BadZoneDataRow { int d_line; // source line number const char *d_invalid; // test string }; static const BadZoneDataRow BAD_ZONE_DATA[] = { //LINE INPUT STRING //---- ------------------------- { L_, "0" }, // length = 1 { L_, "+" }, { L_, "-" }, { L_, "T" }, { L_, "+0" }, // length = 2 { L_, "-0" }, { L_, "Z0" }, { L_, "+01" }, // length = 3 { L_, "-01" }, { L_, "+10:" }, // length = 4 { L_, "-10:" }, { L_, "+120" }, { L_, "-030" }, { L_, "+01:1" }, // length = 5 { L_, "-01:1" }, { L_, "+1:12" }, { L_, "+12:1" }, { L_, "+2360" }, { L_, "-2360" }, { L_, "+2400" }, { L_, "-2400" }, { L_, "+12:1x" }, // length = 6 { L_, "+12:1 " }, { L_, "+1200x" }, { L_, "+23:60" }, { L_, "-23:60" }, { L_, "+24:00" }, { L_, "-24:00" }, { L_, "+123:23" }, // length = 7 { L_, "+12:123" }, { L_, "+011:23" }, { L_, "+12:011" }, { L_, "+123:123" }, // length = 8 }; const int NUM_BAD_ZONE_DATA = static_cast<int>(sizeof BAD_ZONE_DATA / sizeof *BAD_ZONE_DATA); //============================================================================= // GLOBAL HELPER FUNCTIONS FOR TESTING //----------------------------------------------------------------------------- static Config& gg(Config *object, int fractionalSecondPrecision, bool omitColonInZoneDesignatorFlag, bool useCommaForDecimalSignFlag, bool useZAbbreviationForUtcFlag) // Return, by reference, the specified '*object' with its value adjusted // according to the specified 'omitColonInZoneDesignatorFlag', // 'useCommaForDecimalSignFlag', and 'useZAbbreviationForUtcFlag'. { if (fractionalSecondPrecision > 6) { fractionalSecondPrecision = 6; } object->setFractionalSecondPrecision(fractionalSecondPrecision); object->setOmitColonInZoneDesignator(omitColonInZoneDesignatorFlag); object->setUseCommaForDecimalSign(useCommaForDecimalSignFlag); object->setUseZAbbreviationForUtc(useZAbbreviationForUtcFlag); return *object; } static void updateExpectedPerConfig(bsl::string *expected, const Config& configuration, int maxPrecision) // Update the specified 'expected' ISO 8601 string as if it were generated // using the specified 'configuration'. The behavior is undefined unless // the zone designator within 'expected' (if any) is of the form // "(+|-)dd:dd". { ASSERT(expected); const bsl::string::size_type index = expected->find('.'); if (configuration.useCommaForDecimalSign()) { if (index != bsl::string::npos) { (*expected)[index] = ','; } } if (index != bsl::string::npos) { ptrdiff_t length = 0; while (bdlb::CharType::isDigit((*expected)[index + length + 1])) { ++length; } int precision = configuration.fractionalSecondPrecision(); if (precision > maxPrecision) { precision = maxPrecision; } if (0 == precision) { expected->erase(index, length + 1); } else if (precision < length) { expected->erase(index + precision + 1, length - precision); } } // If there aren't enough characters in 'expected', don't bother with the // other configuration options. const ptrdiff_t ZONELEN = sizeof "+dd:dd" - 1; if (expected->length() < ZONELEN || (!configuration.useZAbbreviationForUtc() && !configuration.omitColonInZoneDesignator())) { return; // RETURN } // See if the tail of 'expected' has the pattern of a zone designator. const bsl::string::size_type zdx = expected->length() - ZONELEN; if (('+' != (*expected)[zdx] && '-' != (*expected)[zdx]) || !bdlb::CharType::isDigit((*expected)[zdx + 1]) || !bdlb::CharType::isDigit((*expected)[zdx + 2]) || ':' != (*expected)[zdx + 3] || !bdlb::CharType::isDigit((*expected)[zdx + 4]) || !bdlb::CharType::isDigit((*expected)[zdx + 5])) { return; // RETURN } if (configuration.useZAbbreviationForUtc()) { const bsl::string zone = expected->substr( expected->length() - ZONELEN); if (0 == zone.compare("+00:00")) { expected->erase(expected->length() - ZONELEN); expected->push_back('Z'); return; // RETURN } } if (configuration.omitColonInZoneDesignator()) { const bsl::string::size_type index = expected->find_last_of(':'); if (index != bsl::string::npos) { expected->erase(index, 1); } } } static bool containsOnlyDigits(const char *string) // Return 'true' if the specified 'string' contains nothing but digits, and // 'false' otherwise. { while (*string) { if (!bdlb::CharType::isDigit(*string)) { return false; // RETURN } ++string; } return true; } #ifdef U_TEST_PART_02 static bsl::string replaceTWithSpace(const char *buffer, ptrdiff_t length) // Return copy of the specified string with all 'T' & 't' characters // replaced with a SPACE character. { bsl::string s(buffer, length); for (bsl::string::iterator it = s.begin(); it != s.end(); ++it) { if (*it == 'T' || *it == 't') *it = ' '; } return s; } #endif namespace { namespace u { const Util::ParseConfiguration& BASIC = Util::ParseConfiguration().setBasic(); const Util::ParseConfiguration& RELAXED_BASIC = Util::ParseConfiguration().setBasic().setRelaxed(); void removeCharFromString(bsl::string *str, char chr, int limit = INT_MAX) { for (int ii = 0; ii < limit; ++ii) { bsl::size_t offset = str->find(chr); if (bsl::string::npos == offset) { break; } str->erase(offset, 1); } } } // close namespace u } // close unnamed namespace #endif // U_TEST_COMPILING_A_PART //============================================================================= // OUT-OF-LINE TEST CASES //----------------------------------------------------------------------------- // This section includes test cases that have been moved out of the 'switch' // block in 'main' in order to alleviate compiler crash and/or performance // issues. #ifdef U_TEST_PART_02 void testCase18(bool verbose, bool veryVerbose, bool veryVeryVerbose, bool veryVeryVeryVerbose) { (void) veryVeryVeryVerbose; (void) veryVeryVerbose; (void) veryVerbose; if (verbose) cout << "PARSE 'Datetime's FROM STRINGS WITH TIME ZONES\n" "==============================================\n"; static const struct { int d_line; // source line number const char *d_input_p; // input int d_year; // year under test int d_month; // month under test int d_day; // day under test int d_hour; // hour under test int d_minutes; // minutes under test int d_seconds; // seconds under test int d_milliSecs; // milli seconds under test int d_microSecs; // micro seconds under test bool d_isValid; // isValid flag } DATA[] = { //line input year month day hour min sec ms us isValid //---- ----- ---- ----- --- ---- --- --- -- -- ------- { L_, "0000-01-01T00:00:00.000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000Z", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000z", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000-00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, // DRQS 130122587: datetime parsing should accept offsets { L_, "0001-01-01T00:00:00.000Z", 1, 1, 1, 0, 0, 0, 0, 0, true }, { L_, "0001-01-01T00:00:00.000+00:00", 1, 1, 1, 0, 0, 0, 0, 0, true }, { L_, "0001-01-01T00:00:00.000+00:45", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:00.000-23:59", 1, 1, 1, 23, 59, 0, 0, 0, true }, { L_, "0001-01-01T00:00:00.000000Z", 1, 1, 1, 0, 0, 0, 0, 0, true }, { L_, "0001-01-01T00:00:00.000000+00:00", 1, 1, 1, 0, 0, 0, 0, 0, true }, { L_, "0001-01-01T00:00:00.000000+00:45", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:00.000000-23:59", 1, 1, 1, 23, 59, 0, 0, 0, true }, { L_, "0001-01-01T01:01:01.001z", 1, 1, 1, 1, 1, 1, 1, 0, true }, { L_, "0001-01-01T01:01:01.001+00:00", 1, 1, 1, 1, 1, 1, 1, 0, true }, { L_, "0001-01-01T01:01:01.001+08:20", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T01:01:01.001000z", 1, 1, 1, 1, 1, 1, 1, 0, true }, { L_, "0001-01-01T01:01:01.001000+00:00", 1, 1, 1, 1, 1, 1, 1, 0, true }, { L_, "0001-01-01T01:01:01.001000+08:20", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:00.000000-23:59", 1, 1, 1, 23, 59, 0, 0, 0, true }, { L_, "0001-01-01T01:23:59.059059+00:00", 1, 1, 1, 1, 23, 59, 59, 59, true }, { L_, "0001-01-01T01:23:59.059059+23:59", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T01:23:59.059059-23:59", 1, 1, 2, 1, 22, 59, 59, 59, true }, { L_, "0001-01-02T00:00:00.000000+00:00", 1, 1, 2, 0, 0, 0, 0, 0, true }, { L_, "0001-01-02T00:00:00.000000+23:59", 1, 1, 1, 0, 1, 0, 0, 0, true }, { L_, "0001-01-02T00:00:00.000000-23:59", 1, 1, 2, 23, 59, 0, 0, 0, true }, { L_, "0001-01-02T01:01:01.000001+00:00", 1, 1, 2, 1, 1, 1, 0, 1, true }, { L_, "0001-01-02T01:01:01.000001+08:20", 1, 1, 1, 16, 41, 1, 0, 1, true }, { L_, "0001-01-02T01:23:59.059168Z", 1, 1, 2, 1, 23, 59, 59, 168, true }, { L_, "0001-01-02T01:23:59.059168+00:00", 1, 1, 2, 1, 23, 59, 59, 168, true }, { L_, "0001-01-02T01:23:59.059168+08:20", 1, 1, 1, 17, 3, 59, 59, 168, true }, { L_, "0001-01-02T01:23:59.059168-08:20", 1, 1, 2, 9, 43, 59, 59, 168, true }, { L_, "0001-01-10T00:00:00.000000z", 1, 1, 10, 0, 0, 0, 0, 0, true }, { L_, "0001-01-10T00:00:00.000000+00:00", 1, 1, 10, 0, 0, 0, 0, 0, true }, { L_, "0001-01-10T01:01:01.001+01:39", 1, 1, 9, 23, 22, 1, 1, 0, true }, { L_, "0001-01-10T01:01:01.000001+01:39", 1, 1, 9, 23, 22, 1, 0, 1, true }, { L_, "0001-01-30T00:00:00.000000Z", 1, 1, 30, 0, 0, 0, 0, 0, true }, { L_, "0001-01-30T00:00:00.000000+00:00", 1, 1, 30, 0, 0, 0, 0, 0, true }, { L_, "0001-01-31T00:00:00.000000+23:59", 1, 1, 30, 0, 1, 0, 0, 0, true }, { L_, "0001-01-31T00:00:00.000000-23:59", 1, 1, 31, 23, 59, 0, 0, 0, true }, { L_, "0001-02-01T00:00:00.000000z", 1, 2, 1, 0, 0, 0, 0, 0, true }, { L_, "0001-02-01T00:00:00.000000+00:00", 1, 2, 1, 0, 0, 0, 0, 0, true }, { L_, "0001-02-01T23:59:59.000000+23:59", 1, 2, 1, 0, 0, 59, 0, 0, true }, { L_, "0001-12-31T00:00:00.000000Z", 1, 12, 31, 0, 0, 0, 0, 0, true }, { L_, "0001-12-31T00:00:00.000000+00:00", 1, 12, 31, 0, 0, 0, 0, 0, true }, { L_, "0001-12-31T23:59:59.000000+23:59", 1, 12, 31, 0, 0, 59, 0, 0, true }, { L_, "0002-01-01T00:00:00.000000+00:00", 2, 1, 1, 0, 0, 0, 0, 0, true }, { L_, "0002-01-01T23:59:59.000000+23:59", 2, 1, 1, 0, 0, 59, 0, 0, true }, { L_, "0004-01-01T00:00:00.000000+00:00", 4, 1, 1, 0, 0, 0, 0, 0, true }, { L_, "0004-01-01T23:59:59.000000+23:59", 4, 1, 1, 0, 0, 59, 0, 0, true }, { L_, "0004-02-28T00:00:00.000000+00:00", 4, 2, 28, 0, 0, 0, 0, 0, true }, { L_, "0004-02-28T23:59:59.000000+23:59", 4, 2, 28, 0, 0, 59, 0, 0, true }, { L_, "0004-02-28T23:59:59.000000-23:59", 4, 2, 29, 23, 58, 59, 0, 0, true }, { L_, "0004-02-29T00:00:00.000000+00:00", 4, 2, 29, 0, 0, 0, 0, 0, true }, { L_, "0004-02-29T23:59:59.000000+23:59", 4, 2, 29, 0, 0, 59, 0, 0, true }, { L_, "0004-02-29T23:59:59.000000-23:59", 4, 3, 1, 23, 58, 59, 0, 0, true }, { L_, "0004-03-01T00:00:00.000000+00:00", 4, 3, 1, 0, 0, 0, 0, 0, true }, { L_, "0004-03-01T23:59:59.000000+23:59", 4, 3, 1, 0, 0, 59, 0, 0, true }, { L_, "0004-03-01T23:59:59.000000-23:59", 4, 3, 2, 23, 58, 59, 0, 0, true }, { L_, "0008-02-28T00:00:00.000000+00:00", 8, 2, 28, 0, 0, 0, 0, 0, true }, { L_, "0008-02-28T23:59:59.000000+23:59", 8, 2, 28, 0, 0, 59, 0, 0, true }, { L_, "0008-02-29T00:00:00.000000+00:00", 8, 2, 29, 0, 0, 0, 0, 0, true }, { L_, "0008-02-29T23:59:59.000000+23:59", 8, 2, 29, 0, 0, 59, 0, 0, true }, { L_, "0008-03-01T00:00:00.000000+00:00", 8, 3, 1, 0, 0, 0, 0, 0, true }, { L_, "0008-03-01T23:59:59.000000+23:59", 8, 3, 1, 0, 0, 59, 0, 0, true }, { L_, "0100-02-28T00:00:00.000000+00:00", 100, 2, 28, 0, 0, 0, 0, 0, true }, { L_, "0100-02-28T23:59:59.000000+23:59", 100, 2, 28, 0, 0, 59, 0, 0, true }, { L_, "0100-02-28T23:59:59.000000-23:59", 100, 2, 29, 23, 58, 59, 0, 0, true }, { L_, "0100-03-01T00:00:00.000000+00:00", 100, 3, 1, 0, 0, 0, 0, 0, true }, { L_, "0100-03-01T23:59:59.000000+23:59", 100, 3, 1, 0, 0, 59, 0, 0, true }, { L_, "0100-03-01T23:59:59.000000-23:59", 100, 3, 2, 23, 58, 59, 0, 0, true }, { L_, "0400-02-28T00:00:00.000000+00:00", 400, 2, 28, 0, 0, 0, 0, 0, true }, { L_, "0400-02-28T23:59:59.000000+23:59", 400, 2, 28, 0, 0, 59, 0, 0, true }, { L_, "0400-02-28T23:59:59.000000-23:59", 400, 2, 29, 23, 58, 59, 0, 0, true }, { L_, "0400-02-29T00:00:00.000000+00:00", 400, 2, 29, 0, 0, 0, 0, 0, true }, { L_, "0400-02-29T23:59:59.000000+23:59", 400, 2, 29, 0, 0, 59, 0, 0, true }, { L_, "0400-02-29T23:59:59.000000-23:59", 400, 3, 1, 23, 58, 59, 0, 0, true }, { L_, "0400-03-01T00:00:00.000000+00:00", 400, 3, 1, 0, 0, 0, 0, 0, true }, { L_, "0400-03-01T23:59:59.000000+23:59", 400, 3, 1, 0, 0, 59, 0, 0, true }, { L_, "0400-03-01T23:59:59.000000-23:59", 400, 3, 2, 23, 58, 59, 0, 0, true }, { L_, "9999-12-31T00:00:00.000000+00:00", 9999, 12, 31, 0, 0, 0, 0, 0, true }, { L_, "9999-12-31T23:59:59.000000+23:59", 9999, 12, 31, 0, 0, 59, 0, 0, true }, { L_, "9999-12-31T23:59:59.000000-23:59", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-00-01T00:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-00T00:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-00-00T00:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-13-00T00:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-32T00:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T25:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:61:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:61.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:00.000000+24:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:00.000000+00:61", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:00.000000-24:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00:00.000000-00:61", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "GARBAGE", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, ".9999", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "23:59:59.9999", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "T23:59:59.9999", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "01T23:59:59.9999", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "01-01T23:59:59.9999", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00.000", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0001-01-01T00:00.000000", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "01-01-01T23:59:59.9999", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "01-01-01T23:59:59.9999999", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000000+00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000000Z", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000000z", 1, 1, 1, 24, 0, 0, 0, 0, false }, { L_, "0000-01-01T00:00:00.000000-00:00", 1, 1, 1, 24, 0, 0, 0, 0, false }, }; const int NUM_DATA = sizeof DATA / sizeof *DATA; for (int i = 0; i < NUM_DATA; ++i) { const int LINE = DATA[i].d_line; const char *INPUT = DATA[i].d_input_p; const int YEAR = DATA[i].d_year; const int MONTH = DATA[i].d_month; const int DAY = DATA[i].d_day; const int HOUR = DATA[i].d_hour; const int MINUTE = DATA[i].d_minutes; const int SECOND = DATA[i].d_seconds; const int MILLISECOND = DATA[i].d_milliSecs; const int MICROSECOND = DATA[i].d_microSecs; const bool IS_VALID = DATA[i].d_isValid; bdlt::Datetime exp(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, MILLISECOND, MICROSECOND); const bdlt::Datetime& EXP = exp; bdlt::Datetime value; const bsl::string_view isb(INPUT); const int rc = Util::parse(&value, isb); if (IS_VALID) { ASSERTV(LINE, rc, 0 == rc); } else { ASSERTV(LINE, rc, rc); } ASSERTV(LINE, EXP, INPUT, value, EXP == value); } } void testCase17(bool verbose, bool veryVerbose, bool /* veryVeryVerbose */, bool /* veryVeryVeryVerbose */) { if (verbose) cout << endl << "PARSE 'DatetimeOrDatetimeTz'" << endl << "============================" << endl; Util::DatetimeOrDatetimeTz mX; const Util::DatetimeOrDatetimeTz& X = mX; char buffer[Util::k_MAX_STRLEN]; const bdlt::Date DD(246, 8, 10); const bdlt::Time TT(2, 4, 6, 8); const bdlt::Datetime XX(DD, TT); // 'XX' and 'ZZ' are controls, const bdlt::DatetimeTz ZZ(XX, -7); // distinct from any test data const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; if (verbose) cout << "\nValid ISO 8601 strings." << endl; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const bdlt::Date DATE(YEAR, MONTH, DAY); for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int JLINE = TIME_DATA[tj].d_line; const int HOUR = TIME_DATA[tj].d_hour; const int MIN = TIME_DATA[tj].d_min; const int SEC = TIME_DATA[tj].d_sec; const int MSEC = TIME_DATA[tj].d_msec; const int USEC = TIME_DATA[tj].d_usec; for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int KLINE = ZONE_DATA[tk].d_line; const int OFFSET = ZONE_DATA[tk].d_offset; if ( bdlt::Time(HOUR, MIN, SEC, MSEC, USEC) == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; int expMsec = MSEC; int expUsec = USEC; { // adjust the expected milliseconds to account for // PRECISION truncating the value generated int precision = (PRECISION < 3 ? PRECISION : 3); for (int i = 3; i > precision; --i) { expMsec /= 10; } for (int i = 3; i > precision; --i) { expMsec *= 10; } // adjust the expected microseconds to account for // PRECISION truncating the value generated precision = (PRECISION > 3 ? PRECISION - 3: 0); for (int i = 3; i > precision; --i) { expUsec /= 10; } for (int i = 3; i > precision; --i) { expUsec *= 10; } } const bdlt::Datetime DATETIME(YEAR, MONTH, DAY, HOUR, MIN, SEC, expMsec, expUsec); const bdlt::DatetimeTz DATETIMETZ(DATETIME, OFFSET); if (veryVerbose) { if (0 == tc) { T_ P_(ILINE) P_(JLINE) P_(KLINE) P_(DATETIME) P(DATETIMETZ); } T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ); } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // without zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, DATETIME, C); bsl::string str(buffer, LENGTH); if (veryVerbose) { const bsl::string STRING(buffer, LENGTH); T_ T_ P(STRING) } mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(buffer, LENGTH); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed( &mX, relaxed.data(), static_cast<int>(relaxed.length()))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); } // without zone designator in parsed string -- basic { int LENGTH = Util::generateRaw(buffer, DATETIME, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, '-', 2); u::removeCharFromString(&str, ':', 2); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(str.c_str(), LENGTH); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, relaxed, 0 == Util::parse(&mX, relaxed.c_str(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X.the<bdlt::Datetime>()); } // with zone designator in parsed string { if ((DATE == bdlt::Date() && OFFSET > 0) || (DATE == bdlt::Date(9999, 12, 31) && OFFSET < 0)) { continue; // skip invalid compositions } const int LENGTH = Util::generateRaw(buffer, DATETIMETZ, C); bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(buffer, LENGTH); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); } // with zone designator in parsed string - basic for (int removeColons = 2; removeColons <= 3; ++removeColons) { if ((DATE == bdlt::Date() && OFFSET > 0) || (DATE == bdlt::Date(9999, 12, 31) && OFFSET < 0)) { continue; // skip invalid compositions } int LENGTH = Util::generateRaw(buffer, DATETIMETZ, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, '-', 2); u::removeCharFromString(&str, ':', removeColons); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(str.c_str(), LENGTH); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, XX == X.the<bdlt::Datetime>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, X.is<bdlt::DatetimeTz>()); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == X.the<bdlt::DatetimeTz>()); } } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' } // loop over 'DATE_DATA' { // verify 't' and 'z' are accepted const bdlt::DatetimeTz EXPECTED(bdlt::Datetime(1, 2, 3, 1, 2, 3), 0); bsl::string str = "0001-02-03t01:02:03z"; mX.reset(); ASSERTV(X.isUnset()); ASSERT(0 == Util::parse(&mX, str.c_str(), str.length())); ASSERTV( X.is<bdlt::DatetimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(X.isUnset()); ASSERT(0 == Util::parse(&mX, StrView(str))); ASSERTV( X.is<bdlt::DatetimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::DatetimeTz>()); str = "00010203t010203z"; mX.reset(); ASSERTV(X.isUnset()); ASSERT(0 == Util::parse(&mX, str.c_str(), str.length(), u::BASIC)); ASSERTV( X.is<bdlt::DatetimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(X.isUnset()); ASSERT(0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV( X.is<bdlt::DatetimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::DatetimeTz>()); } if (verbose) cout << "\nInvalid strings." << endl; { const int NUM_DATE_DATA = NUM_BAD_DATE_DATA; const BadDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = BAD_DATE_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; bsl::string bad(DATE_DATA[ti].d_invalid); // Append a valid time. bad.append("T12:26:52.726"); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad))); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed( &mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed( &mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed( &mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); } const int NUM_TIME_DATA = NUM_BAD_TIME_DATA; const BadTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = BAD_TIME_DATA; for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int LINE = TIME_DATA[tj].d_line; // Initialize with a *valid* date string, then append an // invalid time. bsl::string bad("2010-08-17"); // Ensure that 'bad' is initially valid, but only during the // first iteration. if (0 == tj) { const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Date mD(DD); const bdlt::Date& D = mD; ASSERT( 0 == Util::parse(&mD, STRING, LENGTH)); ASSERT(DD != D); mD = DD; ASSERT( 0 == Util::parse(&mD, StrView(bad))); ASSERT(DD != D); } bad.append("T"); bad.append(TIME_DATA[tj].d_invalid); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad))); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int LINE = ZONE_DATA[tk].d_line; // Initialize with a *valid* datetime string, then append an // invalid zone designator. bsl::string bad("2010-08-17T12:26:52.726"); // Ensure that 'bad' is initially valid, but only during the // first iteration. if (0 == tk) { const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); mX = XX; ASSERT( 0 == Util::parse(&mX, STRING, LENGTH)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(bad))); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, bad.c_str())); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); // parseRelaxed() on the same string mX = XX; ASSERT( 0 == Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); // parseRelaxed() on the string modified to have SPACE // instead of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX = XX; ASSERT( 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); } // If 'ZONE_DATA[tk].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(ZONE_DATA[tk].d_invalid)) { continue; } bad.append(ZONE_DATA[tk].d_invalid); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); } } if (verbose) cout << "\nInvalid strings - basic." << endl; { const int NUM_DATE_DATA = NUM_BASIC_BAD_DATE_DATA; const BadDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = BASIC_BAD_DATE_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; bsl::string bad(DATE_DATA[ti].d_invalid); // Append a valid time. bad.append("T122652.726"); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); } const int NUM_TIME_DATA = NUM_BASIC_BAD_TIME_DATA; const BadTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = BASIC_BAD_TIME_DATA; for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int LINE = TIME_DATA[tj].d_line; // Initialize with a *valid* date string, then append an // invalid time. bsl::string bad("20100817"); // Ensure that 'bad' is initially valid, but only during the // first iteration. if (0 == tj) { const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Date mD(DD); const bdlt::Date& D = mD; ASSERT( 0 == Util::parse(&mD, STRING, LENGTH, u::BASIC)); ASSERT(DD != D); mD = DD; ASSERT( 0 == Util::parse(&mD, StrView(STRING, LENGTH), u::BASIC)); ASSERT(DD != D); mD = DD; ASSERT( 0 == Util::parse(&mD, bad.c_str(), u::BASIC)); ASSERT(DD != D); } bad.append("T"); bad.append(TIME_DATA[tj].d_invalid); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int LINE = ZONE_DATA[tk].d_line; // Initialize with a *valid* datetime string, then append an // invalid zone designator. bsl::string bad("20100817T122652.726"); // Ensure that 'bad' is initially valid, but only during the // first iteration. if (0 == tk) { const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); mX = XX; ASSERT( 0 == Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); // parseRelaxed() on the same string mX = XX; ASSERT( 0 == Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); // parseRelaxed() on the string modified to have SPACE // instead of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX = XX; ASSERT( 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); mX = XX; ASSERT( 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERT(mX.is<bdlt::Datetime>()); ASSERT(XX != mX.the<bdlt::Datetime>()); } // If 'ZONE_DATA[tk].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(ZONE_DATA[tk].d_invalid)) { continue; } bsl::string zone(ZONE_DATA[tk].d_invalid); u::removeCharFromString(&zone, ':', 1); bad += zone; const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Datetime>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Datetime>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DatetimeTz>()); } } if (verbose) cout << "\nTesting leap seconds and fractional seconds." << endl; { const struct { int d_line; // source line number const char *d_input; // input int d_year; // year under test int d_month; // month under test int d_day; // day under test int d_hour; // hour under test int d_min; // minutes under test int d_sec; // seconds under test int d_msec; // milli seconds under test int d_usec; // micro seconds under test int d_offset; // UTC offset bool d_isDatetimeTz; // flag indicating whether the // result object is expected to // contain 'DatetimeTz' or // 'Datetime' object } DATA[] = { // leap seconds { L_, "0001-01-01T00:00:60.000", 0001, 01, 01, 00, 01, 00, 000, 000, 0, false }, { L_, "9998-12-31T23:59:60.999", 9999, 01, 01, 00, 00, 00, 999, 000, 0, false }, // fractional seconds { L_, "0001-01-01T00:00:00.0000001", 0001, 01, 01, 00, 00, 00, 000, 000, 0, false }, { L_, "0001-01-01T00:00:00.0000009", 0001, 01, 01, 00, 00, 00, 000, 1, 0, false }, { L_, "0001-01-01T00:00:00.00000001", 0001, 01, 01, 00, 00, 00, 000, 000, 0, false }, { L_, "0001-01-01T00:00:00.00000049", 0001, 01, 01, 00, 00, 00, 000, 000, 0, false }, { L_, "0001-01-01T00:00:00.00000050", 0001, 01, 01, 00, 00, 00, 000, 1, 0, false }, { L_, "0001-01-01T00:00:00.00000099", 0001, 01, 01, 00, 00, 00, 000, 1, 0, false }, { L_, "0001-01-01T00:00:00.0001", 0001, 01, 01, 00, 00, 00, 000, 100, 0, false }, { L_, "0001-01-01T00:00:00.0009", 0001, 01, 01, 00, 00, 00, 000, 900, 0, false }, { L_, "0001-01-01T00:00:00.00001", 0001, 01, 01, 00, 00, 00, 000, 10, 0, false }, { L_, "0001-01-01T00:00:00.00049", 0001, 01, 01, 00, 00, 00, 000, 490, 0, false }, { L_, "0001-01-01T00:00:00.00050", 0001, 01, 01, 00, 00, 00, 000, 500, 0, false }, { L_, "0001-01-01T00:00:00.00099", 0001, 01, 01, 00, 00, 00, 000, 990, 0, false }, { L_, "0001-01-01T00:00:00.9994" , 0001, 01, 01, 00, 00, 00, 999, 400, 0, false }, { L_, "0001-01-01T00:00:00.9995" , 0001, 01, 01, 00, 00, 00, 999, 500, 0, false }, { L_, "0001-01-01T00:00:00.9999" , 0001, 01, 01, 00, 00, 00, 999, 900, 0, false }, { L_, "9998-12-31T23:59:60.9999" , 9999, 01, 01, 00, 00, 00, 999, 900, 0, false }, { L_, "0001-01-01T00:00:00.9999994" , 0001, 01, 01, 00, 00, 00, 999, 999, 0, false }, { L_, "0001-01-01T00:00:00.9999995" , 0001, 01, 01, 00, 00, 01, 000, 000, 0, false }, { L_, "0001-01-01T00:00:00.9999999" , 0001, 01, 01, 00, 00, 01, 000, 000, 0, false }, { L_, "9998-12-31T23:59:60.9999999" , 9999, 01, 01, 00, 00, 01, 000, 000, 0, false }, // omit fractional seconds { L_, "2014-12-23T12:34:45", 2014, 12, 23, 12, 34, 45, 000, 000, 0, false }, { L_, "2014-12-23T12:34:45Z", 2014, 12, 23, 12, 34, 45, 000, 000, 0, true }, { L_, "2014-12-23T12:34:45+00:30", 2014, 12, 23, 12, 34, 45, 000, 000, 30, true }, { L_, "2014-12-23T12:34:45-01:30", 2014, 12, 23, 12, 34, 45, 000, 000, -90, true }, { L_, "2014-12-23T12:34:45.9999994Z", 2014, 12, 23, 12, 34, 45, 999, 999, 0, true }, { L_, "2014-12-23T12:34:45.9999994+00:30", 2014, 12, 23, 12, 34, 45, 999, 999, 30, true }, { L_, "2014-12-23T12:34:45.9999994-01:30", 2014, 12, 23, 12, 34, 45, 999, 999, -90, true }, { L_, "2014-12-23T12:34:45.9999995Z", 2014, 12, 23, 12, 34, 46, 000, 000, 0, true }, { L_, "2014-12-23T12:34:45.9999995+00:30", 2014, 12, 23, 12, 34, 46, 000, 000, 30, true }, { L_, "2014-12-23T12:34:45.9999995-01:30", 2014, 12, 23, 12, 34, 46, 000, 000, -90, true }, { L_, "0001-01-01T00:00:00.9999999Z", 0001, 01, 01, 00, 00, 01, 000, 000, 0, true }, { L_, "0001-01-01T00:00:00.9999999+00:30", 0001, 01, 01, 00, 00, 01, 000, 000, 30, true }, { L_, "0001-01-01T00:00:00.9999999-01:30", 0001, 01, 01, 00, 00, 01, 000, 000, -90, true }, { L_, "2014-12-23T12:34:60.9999994+00:30", 2014, 12, 23, 12, 35, 00, 999, 999, 30, true }, { L_, "2014-12-23T12:34:60.9999994-01:30", 2014, 12, 23, 12, 35, 00, 999, 999, -90, true }, { L_, "9998-12-31T23:59:60.9999999+00:30", 9999, 01, 01, 00, 00, 01, 000, 000, 30, true }, { L_, "9998-12-31T23:59:60.9999999-01:30", 9999, 01, 01, 00, 00, 01, 000, 000, -90, true }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int YEAR = DATA[ti].d_year; const int MONTH = DATA[ti].d_month; const int DAY = DATA[ti].d_day; const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int USEC = DATA[ti].d_usec; const int OFFSET = DATA[ti].d_offset; const bool IS_DATETIMETZ = DATA[ti].d_isDatetimeTz; if (veryVerbose) { T_ P_(LINE) P(INPUT) } bdlt::Datetime EXPECTED_DT(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC, USEC); bdlt::DatetimeTz EXPECTED_DTTZ(EXPECTED_DT, OFFSET); bsl::string str(INPUT, LENGTH); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH))); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, str.c_str())); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, INPUT, LENGTH)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, StrView(INPUT, LENGTH))); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(INPUT, LENGTH); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } } // basic for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int YEAR = DATA[ti].d_year; const int MONTH = DATA[ti].d_month; const int DAY = DATA[ti].d_day; const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int USEC = DATA[ti].d_usec; const int OFFSET = DATA[ti].d_offset; const bool IS_DATETIMETZ = DATA[ti].d_isDatetimeTz; if (veryVerbose) { T_ P_(LINE) P(INPUT) } bsl::string str(INPUT); u::removeCharFromString(&str, '-', 2); u::removeCharFromString(&str, ':'); INPUT = str.c_str(); const int LENGTH = static_cast<int>(str.length()); bdlt::Datetime EXPECTED_DT(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC, USEC); bdlt::DatetimeTz EXPECTED_DTTZ(EXPECTED_DT, OFFSET); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH, u::BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH), u::BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH, u::RELAXED_BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH), u::RELAXED_BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(INPUT, LENGTH); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); if (IS_DATETIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DTTZ == X.the<bdlt::DatetimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Datetime>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_DT == X.the<bdlt::Datetime>()); } } } if (verbose) cout << "\nTesting zone designators that overflow a 'Datetime'." << endl; { struct { int d_line; const char *d_input; int d_year; int d_month; int d_day; int d_hour; int d_min; int d_sec; int d_msec; int d_offset; } DATA[] = { { L_, "0001-01-01T00:00:00.000+00:00", 0001, 01, 01, 00, 00, 00, 000, 0 }, { L_, "0001-01-01T00:00:00.000+00:01", 0001, 01, 01, 00, 00, 00, 000, 1 }, { L_, "0001-01-01T23:58:59.000+23:59", 0001, 01, 01, 23, 58, 59, 000, 1439 }, { L_, "9999-12-31T23:59:59.999+00:00", 9999, 12, 31, 23, 59, 59, 999, 0 }, { L_, "9999-12-31T23:59:59.999-00:01", 9999, 12, 31, 23, 59, 59, 999, -1 }, { L_, "9999-12-31T00:01:00.000-23:59", 9999, 12, 31, 00, 01, 00, 000, -1439 }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int YEAR = DATA[ti].d_year; const int MONTH = DATA[ti].d_month; const int DAY = DATA[ti].d_day; const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int OFFSET = DATA[ti].d_offset; if (veryVerbose) { T_ P_(LINE) P(INPUT) } bdlt::DatetimeTz EXPECTED(bdlt::Datetime(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC), OFFSET); bsl::string str(INPUT, LENGTH); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV( LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH)); ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, str.c_str())); ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the same string mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV( LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, INPUT, LENGTH)); ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED == X.the<bdlt::DatetimeTz>()); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(INPUT, LENGTH); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed( &mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED == X.the<bdlt::DatetimeTz>()); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::DatetimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED == X.the<bdlt::DatetimeTz>()); } } if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const char *INPUT = "2013-10-23T01:23:45"; const char *INPUTB = "20131023T012345"; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int LENGTHB = static_cast<int>(bsl::strlen(INPUTB)); const StrView STRING_REF(INPUT, LENGTH); const StrView STRING_REFB(INPUTB, LENGTHB); bdlt::Datetime result; bdlt::DatetimeTz resultTz; if (veryVerbose) cout << "\t'Invalid result'" << endl; { Util::TimeOrTimeTz *NULL_PTR = 0; ASSERT_PASS(Util::parse( &mX, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( NULL_PTR, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &mX, STRING_REF)); ASSERT_FAIL(Util::parse(NULL_PTR, STRING_REF)); } if (veryVerbose) cout << "\t'Invalid input'" << endl; { const char *NULL_PTR = 0; const StrView NULL_REF; ASSERT_PASS(Util::parse(&mX, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(&mX, NULL_PTR, LENGTH)); ASSERT_PASS(Util::parse(&mX, STRING_REF)); ASSERT_FAIL(Util::parse(&mX, NULL_REF)); ASSERT_PASS(Util::parseRelaxed(&mX, INPUT, LENGTH)); ASSERT_FAIL(Util::parseRelaxed(&mX, NULL_PTR, LENGTH)); ASSERT_PASS(Util::parseRelaxed(&mX, STRING_REF)); ASSERT_FAIL(Util::parseRelaxed(&mX, NULL_REF)); } if (veryVerbose) cout << "\t'Invalid length'" << endl; { ASSERT_PASS(Util::parse(&mX, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&mX, INPUT, 0)); ASSERT_FAIL(Util::parse(&mX, INPUT, -1)); ASSERT_PASS(Util::parseRelaxed(&mX, INPUT, LENGTH)); ASSERT_PASS(Util::parseRelaxed(&mX, INPUT, 0)); ASSERT_FAIL(Util::parseRelaxed(&mX, INPUT, -1)); } } } void testCase16(bool verbose, bool veryVerbose, bool /* veryVeryVerbose */, bool /* veryVeryVeryVerbose */) { if (verbose) cout << endl << "PARSE 'TimeOrTimeTz'" << endl << "====================" << endl; Util::TimeOrTimeTz mX; const Util::TimeOrTimeTz& X = mX; char buffer[Util::k_MAX_STRLEN]; const bdlt::Time XX(2, 4, 6, 8); // 'XX' and 'ZZ' are controls, const bdlt::TimeTz ZZ(XX, -7); // distinct from any test data const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; if (verbose) cout << "\nValid ISO 8601 strings." << endl; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int ILINE = TIME_DATA[ti].d_line; const int HOUR = TIME_DATA[ti].d_hour; const int MIN = TIME_DATA[ti].d_min; const int SEC = TIME_DATA[ti].d_sec; const int MSEC = TIME_DATA[ti].d_msec; const int USEC = TIME_DATA[ti].d_usec; for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; if ( bdlt::Time(HOUR, MIN, SEC, MSEC, USEC) == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; int expMsec = MSEC; int expUsec = USEC; { // adjust the expected milliseconds to account for // PRECISION truncating the value generated int precision = (PRECISION < 3 ? PRECISION : 3); for (int i = 3; i > precision; --i) { expMsec /= 10; } for (int i = 3; i > precision; --i) { expMsec *= 10; } // adjust the expected microseconds to account for // PRECISION truncating the value generated precision = (PRECISION > 3 ? PRECISION - 3: 0); for (int i = 3; i > precision; --i) { expUsec /= 10; } for (int i = 3; i > precision; --i) { expUsec *= 10; } } const bdlt::Time TIME(HOUR, MIN, SEC, expMsec, expUsec); const bdlt::TimeTz TIMETZ(TIME, OFFSET); if (veryVerbose) { if (0 == tc) { T_ P_(ILINE) P_(JLINE) P_(TIME) P(TIMETZ); } T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ); } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // without zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, TIME, C); bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); } // without zone designator in parsed string - basic { int LENGTH = Util::generateRaw(buffer, TIME, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, ':'); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, TIME == X.the<bdlt::Time>()); } // with zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, TIMETZ, C); bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); } // with zone designator in parsed string for (int remove = 2; remove <= 3; ++remove) { int LENGTH = Util::generateRaw(buffer, TIMETZ, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, ':', remove); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Time>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::TimeTz>()); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == X.the<bdlt::TimeTz>()); } } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' { // verify 'z' is accepted const bdlt::TimeTz EXPECTED(bdlt::Time(1,2,3) , 0); bsl::string str = "01:02:03z"; mX.reset(); ASSERTV(X.isUnset()); ASSERTV(0 == Util::parse(&mX, str.c_str(), str.length())); ASSERTV( X.is<bdlt::TimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(X.isUnset()); ASSERTV(0 == Util::parse(&mX, str.c_str())); ASSERTV( X.is<bdlt::TimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(X.is<bdlt::Time>()); ASSERTV(XX == X.the<bdlt::Time>()); ASSERTV(0 == Util::parse(&mX, str.c_str(), str.length())); ASSERTV(X.is<bdlt::TimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(X.is<bdlt::Time>()); ASSERTV(XX == X.the<bdlt::Time>()); ASSERTV(0 == Util::parse(&mX, str.c_str())); ASSERTV(X.is<bdlt::TimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERT(X.is<bdlt::TimeTz>()); ASSERT(ZZ == X.the<bdlt::TimeTz>()); ASSERTV(0 == Util::parse(&mX, str.c_str(), str.length())); ASSERT(X.is<bdlt::TimeTz>()); ASSERT(EXPECTED == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERT(X.is<bdlt::TimeTz>()); ASSERT(ZZ == X.the<bdlt::TimeTz>()); ASSERTV(0 == Util::parse(&mX, str.c_str())); ASSERT(X.is<bdlt::TimeTz>()); ASSERT(EXPECTED == X.the<bdlt::TimeTz>()); // basic str = "010203z"; mX.reset(); ASSERTV(X.isUnset()); ASSERTV(0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV( X.is<bdlt::TimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::TimeTz>()); mX = XX; ASSERTV(X.is<bdlt::Time>()); ASSERTV(XX == X.the<bdlt::Time>()); ASSERTV(0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(X.is<bdlt::TimeTz>()); ASSERTV(EXPECTED == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERT(X.is<bdlt::TimeTz>()); ASSERT(ZZ == X.the<bdlt::TimeTz>()); ASSERTV(0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERT(X.is<bdlt::TimeTz>()); ASSERT(EXPECTED == X.the<bdlt::TimeTz>()); } if (verbose) cout << "\nInvalid strings." << endl; { const int NUM_TIME_DATA = NUM_BASIC_BAD_TIME_DATA; const BadTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = BASIC_BAD_TIME_DATA; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int LINE = TIME_DATA[ti].d_line; const char *STRING = TIME_DATA[ti].d_invalid; if (veryVerbose) { T_ P_(LINE) P(STRING) } const ptrdiff_t LENGTH = bsl::strlen(STRING); bsl::string bad(STRING, LENGTH); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int ti = 0; ti < NUM_ZONE_DATA; ++ti) { const int LINE = ZONE_DATA[ti].d_line; // Initialize with a *valid* time string, then append an // invalid zone designator. bsl::string bad("12:26:52.726"); // Ensure that 'bad' is initially valid, but only during the // first iteration. static bool firstTime = true; if (firstTime) { firstTime = false; const char *STRING = bad.data(); ptrdiff_t LENGTH = bad.length(); mX = XX; ASSERT( 0 == Util::parse(&mX, STRING, LENGTH)); ASSERT(mX.is<bdlt::Time>()); ASSERT(XX != mX.the<bdlt::Time>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(STRING, LENGTH))); ASSERT(mX.is<bdlt::Time>()); ASSERT(XX != mX.the<bdlt::Time>()); } // If 'ZONE_DATA[ti].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(ZONE_DATA[ti].d_invalid)) { continue; } bad.append(ZONE_DATA[ti].d_invalid); const char *STRING = bad.c_str(); const int LENGTH = static_cast<int>(bad.length()); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); } // again -- basic for (int ti = 0; ti < 2 * NUM_ZONE_DATA; ++ti) { const int zi = ti % NUM_ZONE_DATA; const int remove = ti / NUM_ZONE_DATA; const int LINE = ZONE_DATA[zi].d_line; const char *ZONE = ZONE_DATA[zi].d_invalid; // Initialize with a *valid* time string, then append an // invalid zone designator. bsl::string bad("122652.726"); // Ensure that 'bad' is initially valid, but only during the // first iteration. static bool firstTime = true; if (firstTime) { firstTime = false; const char *STRING = bad.data(); int LENGTH = static_cast<int>(bad.length()); mX = XX; ASSERT( 0 == Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERT(mX.is<bdlt::Time>()); ASSERT(XX != mX.the<bdlt::Time>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(bad), u::BASIC)); ASSERT(mX.is<bdlt::Time>()); ASSERT(XX != mX.the<bdlt::Time>()); mX = XX; ASSERT( 0 == Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERT(mX.is<bdlt::Time>()); ASSERT(XX != mX.the<bdlt::Time>()); } // If 'ZONE_DATA[ti].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(ZONE)) { continue; } bad.append(ZONE); u::removeCharFromString(&bad, ':', remove); const char *STRING = bad.c_str(); const int LENGTH = static_cast<int>(bad.length()); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Time>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Time>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::TimeTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::TimeTz>()); } } if (verbose) cout << "\nTesting leap seconds and fractional seconds." << endl; { const struct { int d_line; // source line number const char *d_input; // input int d_hour; // hour under test int d_min; // minutes under test int d_sec; // seconds under test int d_msec; // milli seconds under test int d_usec; // micro seconds under test int d_offset; // UTC offset bool d_isTimeTz; // flag indicating whether the result // object is expected to contain // 'TimeTz' or 'Time' object } DATA[] = { // leap seconds //LINE INPUT H M S MS US OFF DATETZ //---- ------------------------ -- -- -- --- --- --- ------ { L_, "00:00:60.000", 00, 01, 00, 000, 000, 0, false }, { L_, "22:59:60.999", 23, 00, 00, 999, 000, 0, false }, { L_, "23:59:60.999", 00, 00, 00, 999, 000, 0, false }, // fractional seconds { L_, "00:00:00.0001", 00, 00, 00, 000, 100, 0, false }, { L_, "00:00:00.0009", 00, 00, 00, 000, 900, 0, false }, { L_, "00:00:00.00001", 00, 00, 00, 000, 10, 0, false }, { L_, "00:00:00.00049", 00, 00, 00, 000, 490, 0, false }, { L_, "00:00:00.00050", 00, 00, 00, 000, 500, 0, false }, { L_, "00:00:00.00099", 00, 00, 00, 000, 990, 0, false }, { L_, "00:00:00.0000001", 00, 00, 00, 000, 000, 0, false }, { L_, "00:00:00.0000009", 00, 00, 00, 000, 001, 0, false }, { L_, "00:00:00.00000001", 00, 00, 00, 000, 000, 0, false }, { L_, "00:00:00.00000049", 00, 00, 00, 000, 000, 0, false }, { L_, "00:00:00.00000050", 00, 00, 00, 000, 001, 0, false }, { L_, "00:00:00.00000099", 00, 00, 00, 000, 001, 0, false }, { L_, "00:00:00.9994", 00, 00, 00, 999, 400, 0, false }, { L_, "00:00:00.9995", 00, 00, 00, 999, 500, 0, false }, { L_, "00:00:00.9999", 00, 00, 00, 999, 900, 0, false }, { L_, "00:00:59.9999", 00, 00, 59, 999, 900, 0, false }, { L_, "23:59:59.9999", 23, 59, 59, 999, 900, 0, false }, { L_, "00:00:00.9999994", 00, 00, 00, 999, 999, 0, false }, { L_, "00:00:00.9999995", 00, 00, 1, 000, 000, 0, false }, { L_, "00:00:00.9999999", 00, 00, 1, 000, 000, 0, false }, { L_, "00:00:59.9999999", 00, 1, 00, 000, 000, 0, false }, { L_, "23:59:59.9999999", 00, 00, 00, 000, 000, 0, false }, // omit fractional seconds { L_, "12:34:45", 12, 34, 45, 000, 000, 0, false }, { L_, "12:34:45Z", 12, 34, 45, 000, 000, 0, true }, { L_, "12:34:45+00:30", 12, 34, 45, 000, 000, 30, true }, { L_, "00:00:00+00:30", 00, 00, 00, 000, 000, 30, true }, { L_, "12:34:45-01:30", 12, 34, 45, 000, 000, -90, true }, { L_, "23:59:59-01:30", 23, 59, 59, 000, 000, -90, true }, { L_, "12:34:45.9999994Z", 12, 34, 45, 999, 999, 0, true }, { L_, "12:34:45.9999994+00:30", 12, 34, 45, 999, 999, 30, true }, { L_, "12:34:45.9999994-01:30", 12, 34, 45, 999, 999, -90, true }, { L_, "12:34:45.9999995Z", 12, 34, 46, 000, 000, 0, true }, { L_, "12:34:45.9999995+00:30", 12, 34, 46, 000, 000, 30, true }, { L_, "12:34:45.9999995-01:30", 12, 34, 46, 000, 000, -90, true }, { L_, "00:00:00.9999999Z", 00, 00, 01, 000, 000, 0, true }, { L_, "00:00:00.9999999+00:30", 00, 00, 01, 000, 000, 30, true }, { L_, "00:00:00.9999999-01:30", 00, 00, 01, 000, 000, -90, true }, { L_, "12:34:60.9999994+00:30", 12, 35, 00, 999, 999, 30, true }, { L_, "12:34:60.9999994-01:30", 12, 35, 00, 999, 999, -90, true }, { L_, "23:59:60.9999999+00:30", 00, 00, 01, 000, 000, 30, true }, { L_, "23:59:60.9999999-01:30", 00, 00, 01, 000, 000, -90, true }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int tti = 0; tti < 2 * NUM_DATA; ++tti) { const int ti = tti % NUM_DATA; const int remove = tti / NUM_DATA; const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int USEC = DATA[ti].d_usec; const int OFFSET = DATA[ti].d_offset; const bool IS_TIMETZ = DATA[ti].d_isTimeTz; if (veryVerbose) { T_ P_(LINE) P(INPUT) } const bdlt::Time EXPECTED_TIME(HOUR, MIN, SEC, MSEC, USEC); const bdlt::TimeTz EXPECTED_TIMETZ(EXPECTED_TIME, OFFSET); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH)); if (IS_TIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::TimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIMETZ == X.the<bdlt::TimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Time>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIME == X.the<bdlt::Time>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH))); if (IS_TIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::TimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIMETZ == X.the<bdlt::TimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Time>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIME == X.the<bdlt::Time>()); } // repeat - basic bsl::string str(INPUT, LENGTH); u::removeCharFromString(&str, ':', 2 + remove); INPUT = str.c_str(); LENGTH = static_cast<int>(str.length()); mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH, u::BASIC)); if (IS_TIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::TimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIMETZ == X.the<bdlt::TimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Time>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIME == X.the<bdlt::Time>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH), u::BASIC)); if (IS_TIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::TimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIMETZ == X.the<bdlt::TimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Time>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIME == X.the<bdlt::Time>()); } mX.reset(); ASSERTV(LINE, INPUT, LENGTH, X.isUnset()); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); if (IS_TIMETZ) { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::TimeTz>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIMETZ == X.the<bdlt::TimeTz>()); } else { ASSERTV(LINE, INPUT, LENGTH, X.is<bdlt::Time>()); ASSERTV(LINE, INPUT, LENGTH, EXPECTED_TIME == X.the<bdlt::Time>()); } } } if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const char *INPUT = "01:23:45"; const char *INPUTB = "012345"; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int LENGTHB = static_cast<int>(bsl::strlen(INPUTB)); const StrView STRING_REF( INPUT, LENGTH); const StrView STRING_REFB(INPUTB, LENGTHB); if (veryVerbose) cout << "\t'Invalid result'" << endl; { Util::TimeOrTimeTz *NULL_PTR = 0; ASSERT_PASS(Util::parse( &mX, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(NULL_PTR, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &mX, STRING_REF)); ASSERT_FAIL(Util::parse(NULL_PTR, STRING_REF)); } if (veryVerbose) cout << "\t'Invalid result' - basic" << endl; { Util::TimeOrTimeTz *NULL_PTR = 0; ASSERT_PASS(Util::parse( &mX, INPUTB, LENGTHB, u::BASIC)); ASSERT_FAIL(Util::parse(NULL_PTR, INPUTB, LENGTHB, u::BASIC)); ASSERT_PASS(Util::parse( &mX, STRING_REFB, u::BASIC)); ASSERT_FAIL(Util::parse(NULL_PTR, STRING_REFB, u::BASIC)); } if (veryVerbose) cout << "\t'Invalid input'" << endl; { const char *NULL_PTR = 0; const StrView NULL_REF; ASSERT_PASS(Util::parse(&mX, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(&mX, NULL_PTR, LENGTH)); ASSERT_PASS(Util::parse(&mX, STRING_REF)); ASSERT_FAIL(Util::parse(&mX, NULL_REF)); } if (veryVerbose) cout << "\t'Invalid input' - basic" << endl; { const char *NULL_PTR = 0; const StrView NULL_REF; ASSERT_PASS(Util::parse(&mX, INPUTB, LENGTHB, u::BASIC)); ASSERT_FAIL(Util::parse(&mX, NULL_PTR, LENGTHB, u::BASIC)); ASSERT_PASS(Util::parse(&mX, STRING_REFB, u::BASIC)); ASSERT_FAIL(Util::parse(&mX, NULL_REF, u::BASIC)); } if (veryVerbose) cout << "\t'Invalid length'" << endl; { ASSERT_PASS(Util::parse(&mX, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&mX, INPUT, 0)); ASSERT_FAIL(Util::parse(&mX, INPUT, -1)); } if (veryVerbose) cout << "\t'Invalid length' - basic" << endl; { ASSERT_PASS(Util::parse(&mX, INPUTB, LENGTHB, u::BASIC)); ASSERT_PASS(Util::parse(&mX, INPUTB, 0, u::BASIC)); ASSERT_FAIL(Util::parse(&mX, INPUTB, -1, u::BASIC)); } } } #endif // U_TEST_PART_02 //============================================================================= // MAIN PROGRAM //----------------------------------------------------------------------------- int main(int argc, char *argv[]) { const int test = argc > 1 ? atoi(argv[1]) : 0; const bool verbose = argc > 2; const bool veryVerbose = argc > 3; const bool veryVeryVerbose = argc > 4; const bool veryVeryVeryVerbose = argc > 5; // eliminate unused variable warning (void)verbose; (void)veryVerbose; (void)veryVeryVerbose; (void)veryVeryVeryVerbose; cout << "TEST " << __FILE__ << " CASE " << test << endl; #ifdef U_TEST_COMPILING_A_PART // CONCERN: 'BSLS_REVIEW' failures should lead to test failures. bsls::ReviewFailureHandlerGuard reviewGuard(&bsls::Review::failByAbort); #endif switch (test) { case 0: // Zero is always the leading case. case 19: { // -------------------------------------------------------------------- // USAGE EXAMPLE // Extracted from component header file. // // Concerns: //: 1 The usage example provided in the component header file compiles, //: links, and runs as shown. // // Plan: //: 1 Incorporate usage example from header into test driver, remove //: leading comment characters, and replace 'assert' with 'ASSERT'. //: (C-1) // // Testing: // USAGE EXAMPLE // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 if (verbose) cout << endl << "USAGE EXAMPLE" << endl << "=============" << endl; ///Usage ///----- // This section illustrates intended use of this component. // ///Example 1: Basic 'bdlt::Iso8601Util' Usage /// - - - - - - - - - - - - - - - - - - - - - // This example demonstrates basic use of one 'generate' function and two // 'parse' functions. // // First, we construct a few objects that are prerequisites for this and the // following example: //.. const bdlt::Date date(2005, 1, 31); // 2005/01/31 const bdlt::Time time(8, 59, 59, 123); // 08:59:59.123 const int tzOffset = 240; // +04:00 (four hours west of UTC) //.. // Then, we construct a 'bdlt::DatetimeTz' object for which a corresponding ISO // 8601-compliant string will be generated shortly: //.. const bdlt::DatetimeTz sourceDatetimeTz(bdlt::Datetime(date, time), tzOffset); //.. // For comparison with the ISO 8601 string generated below, note that streaming // the value of 'sourceDatetimeTz' to 'stdout': //.. if (veryVerbose) bsl::cout << sourceDatetimeTz << bsl::endl; //.. // produces: //.. // 31JAN2005_08:59:59.123000+0400 //.. // Next, we use a 'generate' function to produce an ISO 8601-compliant string // for 'sourceDatetimeTz', writing the output to a 'bsl::ostringstream', and // assert that both the return value and the string that is produced are as // expected: //.. bsl::ostringstream oss; const bsl::ostream& ret = bdlt::Iso8601Util::generate(oss, sourceDatetimeTz); ASSERT(&oss == &ret); const bsl::string iso8601 = oss.str(); ASSERT(iso8601 == "2005-01-31T08:59:59.123+04:00"); //.. // For comparison, see the output that was produced by the streaming operator // above. // // Now, we parse the string that was just produced, loading the result of the // parse into a second 'bdlt::DatetimeTz' object, and assert that the parse was // successful and that the target object has the same value as that of the // original (i.e., 'sourceDatetimeTz'): //.. bdlt::DatetimeTz targetDatetimeTz; int rc = bdlt::Iso8601Util::parse(&targetDatetimeTz, iso8601.c_str(), static_cast<int>(iso8601.length())); ASSERT( 0 == rc); ASSERT(sourceDatetimeTz == targetDatetimeTz); //.. // Finally, we parse the 'iso8601' string a second time, this time loading the // result into a 'bdlt::Datetime' object (instead of a 'bdlt::DatetimeTz'): //.. bdlt::Datetime targetDatetime; rc = bdlt::Iso8601Util::parse(&targetDatetime, iso8601.c_str(), static_cast<int>(iso8601.length())); ASSERT( 0 == rc); ASSERT(sourceDatetimeTz.utcDatetime() == targetDatetime); //.. // Note that this time the value of the target object has been converted to // UTC. // ///Example 2: Configuring ISO 8601 String Generation ///- - - - - - - - - - - - - - - - - - - - - - - - - // This example demonstrates use of a 'bdlt::Iso8601UtilConfiguration' object // to influence the format of the ISO 8601 strings that are generated by this // component by passing that configuration object to 'generate'. We also take // this opportunity to illustrate the flavor of the 'generate' functions that // outputs to a 'char *' buffer of a specified length. // // First, we construct a 'bdlt::TimeTz' object for which a corresponding ISO // 8601-compliant string will be generated shortly: //.. const bdlt::TimeTz sourceTimeTz(time, tzOffset); //.. // For comparison with the ISO 8601 string generated below, note that streaming // the value of 'sourceTimeTz' to 'stdout': //.. if (veryVerbose) bsl::cout << sourceTimeTz << bsl::endl; //.. // produces: //.. // 08:59:59.123+0400 //.. // Then, we construct the 'bdlt::Iso8601UtilConfiguration' object that // indicates how we would like to effect the generated output ISO 8601 string. // In this case, we want to use ',' as the decimal sign (in fractional seconds) // and omit the ':' in zone designators: //.. bdlt::Iso8601UtilConfiguration configuration; configuration.setOmitColonInZoneDesignator(true); configuration.setUseCommaForDecimalSign(true); //.. // Next, we define the 'char *' buffer that will be used to stored the // generated string. A buffer of size 'bdlt::Iso8601Util::k_TIMETZ_STRLEN + 1' // is large enough to hold any string generated by this component for a // 'bdlt::TimeTz' object, including a null terminator: //.. const int BUFLEN = bdlt::Iso8601Util::k_TIMETZ_STRLEN + 1; char buffer[BUFLEN]; //.. // Then, we use a 'generate' function that accepts our 'configuration' to // produce an ISO 8601-compliant string for 'sourceTimeTz', this time writing // the output to a 'char *' buffer, and assert that both the return value and // the string that is produced are as expected. Note that in comparing the // return value against 'BUFLEN - 5' we account for the omission of the ':' // from the zone designator, and also for the fact that, although a null // terminator was generated, it is not included in the character count returned // by 'generate'. Also note that we use 'bsl::strcmp' to compare the resulting // string knowing that we supplied a buffer having sufficient capacity to // accommodate a null terminator: //.. rc = bdlt::Iso8601Util::generate(buffer, BUFLEN, sourceTimeTz, configuration); ASSERT(BUFLEN - 5 == rc); ASSERT( 0 == bsl::strcmp(buffer, "08:59:59,123+0400")); //.. // For comparison, see the output that was produced by the streaming operator // above. // // Next, we parse the string that was just produced, loading the result of the // parse into a second 'bdlt::TimeTz' object, and assert that the parse was // successful and that the target object has the same value as that of the // original (i.e., 'sourceTimeTz'). Note that 'BUFLEN - 5' is passed and *not* // 'BUFLEN' because the former indicates the correct number of characters in // 'buffer' that we wish to parse: //.. bdlt::TimeTz targetTimeTz; rc = bdlt::Iso8601Util::parse(&targetTimeTz, buffer, BUFLEN - 5); ASSERT( 0 == rc); ASSERT(sourceTimeTz == targetTimeTz); //.. // Then, we parse the string in 'buffer' a second time, this time loading the // result into a 'bdlt::Time' object (instead of a 'bdlt::TimeTz'): //.. bdlt::Time targetTime; rc = bdlt::Iso8601Util::parse(&targetTime, buffer, BUFLEN - 5); ASSERT( 0 == rc); ASSERT(sourceTimeTz.utcTime() == targetTime); //.. // Note that this time the value of the target object has been converted to // UTC. // // Finally, we modify the 'configuration' to display the 'bdlt::TimeTz' without // fractional seconds: //.. configuration.setFractionalSecondPrecision(0); rc = bdlt::Iso8601Util::generate(buffer, BUFLEN, sourceTimeTz, configuration); ASSERT(BUFLEN - 9 == rc); ASSERT( 0 == bsl::strcmp(buffer, "08:59:59+0400")); //.. #else U_TEST_CASE_SKIPPED #endif } break; case 18: { // -------------------------------------------------------------------- // PARSE 'Datetime's FROM STRINGS WITH TIME ZONES // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 testCase18(verbose, veryVerbose, veryVeryVerbose, veryVeryVeryVerbose); #else U_TEST_CASE_SKIPPED #endif } break; case 17: { // -------------------------------------------------------------------- // PARSE 'DatetimeOrDatetimeTz' // // Concerns: //: 1 All ISO 8601 string representations supported by this component //: (as documented in the header file) for 'Datetime' and //: 'DatetimeTz' values are parsed successfully. //: //: 2 If parsing succeeds, the result 'Datetime' or 'DatetimeTz' object //: has the expected value of the expected type no matter what value //: of what type was stored there previously. //: //: 3 The result object contains 'DatetimeTz' value if the optional //: zone designator is present in the input string, and 'Datetime' //: value otherwise. //: //: 4 The result object contains 'DatetimeTz' value if 'Z' suffix is //: present in the input string, and it is assumed to be UTC. //: //: 5 If parsing succeeds, 0 is returned. //: //: 6 All strings that are not ISO 8601 representations supported by //: this component for 'Datetime' and 'DatetimeTz' values are //: rejected (i.e., parsing fails). //: //: 7 If parsing fails, the result object is unaffected and a non-zero //: value is returned. //: //: 8 The entire extent of the input string is parsed. //: //: 9 Leap seconds, fractional seconds containing more than three //: digits, and extremal values (those that can overflow a //: 'Datetime') are handled correctly. //: //:10 The 'parseRelaxed' functions do the same as the 'parse' functions //: and additionally allow to use a SPACE characters instead of 'T'. //: //:11 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values ('D'), 'Time' values ('T'), zone designators ('Z'), //: and configurations ('C'). //: //: 2 Apply the (fully-tested) 'generateRaw' functions to each element //: in the cross product, 'D x T x Z x C', of the test data from P-1. //: //: 3 Invoke the 'parse' functions on the strings generated in P-2 and //: verify that parsing succeeds, i.e., that 0 is returned and the //: result objects have the expected values. (C-1..5) //: //: 4 Using the table-driven technique, specify a set of distinct //: strings that are not ISO 8601 representations supported by this //: component for 'Datetime' and 'DatetimeTz' values. //: //: 5 Invoke the 'parse' functions on the strings from P-4 and verify //: that parsing fails, i.e., that a non-zero value is returned and //: the result objects are unchanged. (C-6..8) //: //: 6 Using the table-driven technique, specify a set of distinct ISO //: 8601 strings that specifically cover cases involving leap //: seconds, fractional seconds containing more than three digits, //: and extremal values. //: //: 7 Invoke the 'parse' functions on the strings from P-6 and verify //: the results are as expected. (C-9) //: //: 8 Invoke the 'parseRelaxed' functions on the same strings and on //: the strings with 'T' character replaced by ' '. (C-10) //: //: 9 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-11) // // Testing: // int parse(DatetimeOrDatetimeTz *, const char *, int); // int parse(DatetimeOrDatetimeTz *result, const StringRef& string); // int parseRelaxed(DatetimeOrDatetimeTz *, const char *, int); // int parseRelaxed(DatetimeOrDatetimeTz *, const bsl::string_view&); // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 testCase17(verbose, veryVerbose, veryVeryVerbose, veryVeryVeryVerbose); #else U_TEST_CASE_SKIPPED #endif } break; case 16: { // -------------------------------------------------------------------- // PARSE 'TimeOrTimeTz' // // Concerns: //: 1 All ISO 8601 string representations supported by this component //: (as documented in the header file) for 'Time' and 'TimeTz' values //: are parsed successfully. //: //: 2 If parsing succeeds, the result object contains the expected //: value of the expected type no matter what value of what type was //: stored there previously. //: //: 3 The result object contains 'TimeTz' value if the optional zone //: designator is present in the input string, and 'Time' value //: otherwise. //: //: 4 The result object contains 'TimeTz' value if 'Z' suffix is //: present in the input string, and it is assumed to be UTC. //: //: 5 If parsing succeeds, 0 is returned. //: //: 6 All strings that are not ISO 8601 representations supported by //: this component for 'Time' and 'TimeTz' values are rejected (i.e., //: parsing fails). //: //: 7 If parsing fails, the result object is unaffected and a non-zero //: value is returned. //: //: 8 The entire extent of the input string is parsed. //: //: 9 Leap seconds and fractional seconds containing more than three //: digits are handled correctly. //: //:10 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Time' values ('T'), zone designators ('Z'), and configurations //: ('C'). //: //: 2 Apply the (fully-tested) 'generateRaw' functions to each element //: in the cross product, 'T x Z x C', of the test data from P-1. //: //: 3 Invoke the 'parse' functions on the strings generated in P-2 and //: verify that parsing succeeds, i.e., that 0 is returned and the //: result objects have the expected values. (C-1..5) //: //: 4 Using the table-driven technique, specify a set of distinct //: strings that are not ISO 8601 representations supported by this //: component for 'Time' and 'TimeTz' values. //: //: 5 Invoke the 'parse' functions on the strings from P-4 and verify //: that parsing fails, i.e., that a non-zero value is returned and //: the result objects are unchanged. (C-6..8) //: //: 6 Using the table-driven technique, specify a set of distinct //: ISO 8601 strings that specifically cover cases involving leap //: seconds and fractional seconds containing more than three digits. //: //: 7 Invoke the 'parse' functions on the strings from P-6 and verify //: the results are as expected. (C-9) //: //: 8 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-10) // // Testing: // int parse(TimeOrTimeTz *, const char *, int); // int parse(TimeOrTimeTz *result, const StringRef& string); // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 testCase16(verbose, veryVerbose, veryVeryVerbose, veryVeryVeryVerbose); #else U_TEST_CASE_SKIPPED #endif } break; case 15: { // -------------------------------------------------------------------- // PARSE 'DateOrDateTz' // // Concerns: //: 1 All ISO 8601 string representations supported by this component //: (as documented in the header file) for 'Date' and 'DateTz' values //: are parsed successfully. //: //: 2 If parsing succeeds, the result object contains the expected //: value of the expected type no matter what value of what type was //: stored there previously. //: //: 3 The result object contains 'DateTz' value if the optional zone //: designator is present in the input string, and 'Date' value //: otherwise. //: //: 4 The result object contains 'DateTz' value if 'Z' suffix is //: present in the input string, and it is assumed to be UTC. //: //: 5 If parsing succeeds, 0 is returned. //: //: 6 All strings that are not ISO 8601 representations supported by //: this component for 'Date' and 'DateTz' values are rejected (i.e., //: parsing fails). //: //: 7 If parsing fails, the result object is unaffected and a non-zero //: value is returned. //: //: 8 The entire extent of the input string is parsed. //: //: 9 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values ('D'), zone designators ('Z'), and configurations //: ('C'). //: //: 2 Apply the (fully-tested) 'generateRaw' functions to each element //: in the cross product, 'D x Z x C', of the test data from P-1. //: //: 3 Invoke the 'parse' functions on the strings generated in P-2 and //: verify that parsing succeeds, i.e., that 0 is returned and the //: result objects have the expected values. (C-1..5) //: //: 4 Using the table-driven technique, specify a set of distinct //: strings that are not ISO 8601 representations supported by this //: component for 'Date' and 'DateTz' values. //: //: 5 Invoke the 'parse' functions on the strings from P-4 and verify //: that parsing fails, i.e., that a non-zero value is returned and //: the result objects are unchanged. (C-6..8) //: //: 6 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-9) // // Testing: // int parse(DateOrDateTz *, const char *, int); // int parse(DateOrDateTz *result, const StringRef& string); // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 if (verbose) cout << endl << "PARSE 'DateOrDateTz'" << endl << "====================" << endl; Util::DateOrDateTz mX; const Util::DateOrDateTz& X = mX; char buffer[Util::k_MAX_STRLEN]; const bdlt::Date XX(246, 8, 10); // 'XX' and 'ZZ' are controls, const bdlt::DateTz ZZ(XX, -7); // distinct from any test data const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; if (verbose) cout << "\nValid ISO 8601 strings." << endl; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const bdlt::Date DATE(YEAR, MONTH, DAY); for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; const bdlt::DateTz DATETZ(DATE, OFFSET); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(DATE) P(DATETZ) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // without zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, DATE, C); bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); } // without zone designator in parsed string - basic { int LENGTH = Util::generateRaw(buffer, DATE, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, '-', 2); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, str, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, str, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, DATE == X.the<bdlt::Date>()); } // with zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, DATETZ, C); bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); } // with zone designator in parsed string - basic { int LENGTH = Util::generateRaw(buffer, DATETZ, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, '-', 2); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(ILINE, JLINE, CLINE, X.isUnset()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, XX == X.the<bdlt::Date>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, ZZ == X.the<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, X.is<bdlt::DateTz>()); ASSERTV(ILINE, JLINE, CLINE, DATETZ == X.the<bdlt::DateTz>()); } } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'DATE_DATA' { // verify 'z' is accepted const bdlt::DateTz EXPECTED(bdlt::Date(1,2,3) , 0); bsl::string str("0001-02-03z", 11); mX.reset(); ASSERTV(X.isUnset()); ASSERTV(0 == Util::parse(&mX, str.c_str(), str.length())); ASSERTV( X.is<bdlt::DateTz>()); ASSERTV(EXPECTED == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(X.isUnset()); ASSERTV(0 == Util::parse(&mX, str.c_str())); ASSERTV( X.is<bdlt::DateTz>()); ASSERTV(EXPECTED == X.the<bdlt::DateTz>()); str = "00010203z"; mX.reset(); ASSERTV(X.isUnset()); ASSERTV(0 == Util::parse(&mX, str.c_str(), str.length(), u::BASIC)); ASSERTV( X.is<bdlt::DateTz>()); ASSERTV(EXPECTED == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(X.isUnset()); ASSERTV(0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV( X.is<bdlt::DateTz>()); ASSERTV(EXPECTED == X.the<bdlt::DateTz>()); } if (verbose) cout << "\nInvalid strings." << endl; { const int NUM_DATE_DATA = NUM_BAD_DATE_DATA; const BadDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = BAD_DATE_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; const char *STRING = DATE_DATA[ti].d_invalid; const int LENGTH = static_cast<int>(bsl::strlen(STRING)); bsl::string bad(STRING, LENGTH); if (veryVerbose) { T_ P_(LINE) P(bad) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int ti = 0; ti < NUM_ZONE_DATA; ++ti) { const int LINE = ZONE_DATA[ti].d_line; // Initialize with a *valid* date string, then append an // invalid zone designator. bsl::string bad("2010-08-17"); // Ensure that 'bad' is initially valid, but only during the // first iteration. if (0 == ti) { const char *STRING = bad.data(); const int LENGTH = static_cast<int>(bad.length()); bsl::string str(STRING, LENGTH); mX = XX; ASSERT( 0 == Util::parse(&mX, STRING, LENGTH)); ASSERT(mX.is<bdlt::Date>()); ASSERT(XX != mX.the<bdlt::Date>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(STRING, LENGTH))); ASSERT(mX.is<bdlt::Date>()); ASSERT(XX != mX.the<bdlt::Date>()); mX = XX; ASSERT( 0 == Util::parse(&mX, str.c_str())); ASSERT(mX.is<bdlt::Date>()); ASSERT(XX != mX.the<bdlt::Date>()); } bad.append(ZONE_DATA[ti].d_invalid); const char *STRING = bad.c_str(); const int LENGTH = static_cast<int>(bad.length()); bsl::string str(STRING, LENGTH); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); } } if (verbose) cout << "\nInvalid strings - basic." << endl; { const int NUM_DATE_DATA = NUM_BASIC_BAD_DATE_DATA; const BadDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = BASIC_BAD_DATE_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; const char *STRING = DATE_DATA[ti].d_invalid; const int LENGTH = static_cast<int>(bsl::strlen(STRING)); bsl::string str(STRING, LENGTH); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int ti = 0; ti < NUM_ZONE_DATA; ++ti) { const int LINE = ZONE_DATA[ti].d_line; // Initialize with a *valid* date string, then append an // invalid zone designator. bsl::string bad("20100817"); // Ensure that 'bad' is initially valid, but only during the // first iteration. static bool firstTime = true; if (firstTime) { firstTime = false; const char *STRING = bad.data(); const int LENGTH = static_cast<int>(bad.length()); mX = XX; ASSERT( 0 == Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERT(mX.is<bdlt::Date>()); ASSERT(XX != mX.the<bdlt::Date>()); mX = XX; ASSERT( 0 == Util::parse(&mX, StrView(STRING, LENGTH), u::BASIC)); ASSERT(mX.is<bdlt::Date>()); ASSERT(XX != mX.the<bdlt::Date>()); mX = XX; ASSERT( 0 == Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERT(mX.is<bdlt::Date>()); ASSERT(XX != mX.the<bdlt::Date>()); } bad.append(ZONE_DATA[ti].d_invalid); u::removeCharFromString(&bad, ':'); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX.reset(); ASSERTV(LINE, STRING, X.isUnset()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.isUnset()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = XX; ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::Date>()); ASSERTV(LINE, STRING, XX == X.the<bdlt::Date>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); mX = ZZ; ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, X.is<bdlt::DateTz>()); ASSERTV(LINE, STRING, ZZ == X.the<bdlt::DateTz>()); } } if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const char *INPUT = "2013-10-23"; const ptrdiff_t LENGTH = bsl::strlen(INPUT); const char *INPUTB = "20131023"; const ptrdiff_t LENGTHB = bsl::strlen(INPUT); const StrView stringRef( INPUT, LENGTH); const StrView stringRefB(INPUTB, LENGTHB); const StrView nullRef; if (veryVerbose) cout << "\t'Invalid result'" << endl; { Util::DateOrDateTz *nullPtr = 0; ASSERT_PASS(Util::parse(&mX, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(nullPtr, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&mX, stringRef)); ASSERT_FAIL(Util::parse(nullPtr, stringRef)); } if (veryVerbose) cout << "\t'Invalid result' -- basic" << endl; { Util::DateOrDateTz *nullPtr = 0; ASSERT_PASS(Util::parse(&mX, INPUTB, LENGTHB, u::BASIC)); ASSERT_FAIL(Util::parse(nullPtr, INPUTB, LENGTHB, u::BASIC)); ASSERT_PASS(Util::parse(&mX, stringRefB, u::BASIC)); ASSERT_FAIL(Util::parse(nullPtr, stringRefB, u::BASIC)); } if (veryVerbose) cout << "\t'Invalid input'" << endl; { ASSERT_PASS(Util::parse(&mX, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(&mX, 0, LENGTH)); ASSERT_PASS(Util::parse(&mX, stringRef)); ASSERT_FAIL(Util::parse(&mX, nullRef )); } if (veryVerbose) cout << "\t'Invalid input' -- basic" << endl; { ASSERT_PASS(Util::parse(&mX, INPUTB, LENGTHB, u::BASIC)); ASSERT_FAIL(Util::parse(&mX, 0, LENGTHB, u::BASIC)); ASSERT_PASS(Util::parse(&mX, stringRefB, u::BASIC)); ASSERT_FAIL(Util::parse(&mX, nullRef, u::BASIC)); } if (veryVerbose) cout << "\t'Invalid length'" << endl; { ASSERT_PASS(Util::parse(&mX, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&mX, INPUT, 0)); ASSERT_FAIL(Util::parse(&mX, INPUT, -1)); } if (veryVerbose) cout << "\t'Invalid length' -- basic" << endl; { ASSERT_PASS(Util::parse(&mX, INPUTB, LENGTHB, u::BASIC)); ASSERT_PASS(Util::parse(&mX, INPUTB, 0, u::BASIC)); ASSERT_FAIL(Util::parse(&mX, INPUTB, -1, u::BASIC)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 14: { // -------------------------------------------------------------------- // GENERATE 'DatetimeTz' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Create a 'Variant2<Datetime, DatetimeTz>' object, 'X'. //: //: 2 Using the table-driven technique, specify a set of distinct //: 'Date' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 3 In a second table, specify a set of distinct 'Time' values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 4 For each element 'R1' in the cross product of the tables from P-2 //: and P-3 create a 'const' 'Datetime' object, 'DT1', from 'R1'. //: //: 5 In a third table, specify a set of distinct timezone values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 6 For each element 'R2' in the cross product of the tables from //: P-2, P-3, and P-5: //: //: 1 Create a 'const' 'DatetimeTz' object, 'DT2', from 'R2'. //: //: 2 Assign 'DT1' to 'X'. //: //: 3 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R1' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. //: //: 4 Assign 'DT2' to 'X'. //: //: 5 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R2' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 7 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const DatetimeOrDatetimeTz&); // int generate(char*,int,const DatetimeOrDatetimeTz&,const Config&); // int generate(string *, const DatetimeOrDatetimeTz&); // int generate(string*, const DatetimeOrDatetimeTz&, const Config&); // ostream generate(ostream&, const DatetimeOrDatetimeTz&); // ostream generate(ostream&,const DatetimeOrDatetimeTz&,const Con&); // int generateRaw(char *, const DatetimeOrDatetimeTz&); // int generateRaw(char*,const DatetimeOrDatetimeTz&, const Config&); // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 if (verbose) cout << endl << "GENERATE 'DatetimeTz'" << endl << "=====================" << endl; typedef Util::DatetimeOrDatetimeTz TYPE; TYPE mX; const TYPE& X = mX; const int OBJLEN = Util::k_DATETIMETZ_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const char *ISO8601 = DATE_DATA[ti].d_iso8601; const bdlt::Date DATE(YEAR, MONTH, DAY); const bsl::string EXPECTED_DATE(ISO8601); for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int JLINE = TIME_DATA[tj].d_line; const int HOUR = TIME_DATA[tj].d_hour; const int MIN = TIME_DATA[tj].d_min; const int SEC = TIME_DATA[tj].d_sec; const int MSEC = TIME_DATA[tj].d_msec; const int USEC = TIME_DATA[tj].d_usec; const char *ISO8601 = TIME_DATA[tj].d_iso8601; const bdlt::Time TIME(HOUR, MIN, SEC, MSEC); const bsl::string EXPECTED_TIME(ISO8601); const bdlt::Datetime DATETIME(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC, USEC); const bsl::string DATETIME_BASE_EXPECTED( EXPECTED_DATE + 'T' + EXPECTED_TIME); for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int KLINE = ZONE_DATA[tk].d_line; const int OFFSET = ZONE_DATA[tk].d_offset; const char *ISO8601 = ZONE_DATA[tk].d_iso8601; const bsl::string EXPECTED_ZONE(ISO8601); if (TIME == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } const bdlt::DatetimeTz DATETIMETZ(DATETIME, OFFSET); const bsl::string DATETIMETZ_BASE_EXPECTED( DATETIME_BASE_EXPECTED + EXPECTED_ZONE); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(DATETIME) P_(DATETIMETZ) P_(DATETIME_BASE_EXPECTED) P(DATETIMETZ_BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED_DATETIME(DATETIME_BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED_DATETIME, C, k_DATETIME_MAX_PRECISION); bsl::string EXPECTED_DATETIMETZ( DATETIMETZ_BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED_DATETIMETZ, C, k_DATETIMETZ_MAX_PRECISION); for (int tt = 0; tt < 2; ++tt) { const int OBJ_TYPE = tt; if (OBJ_TYPE) { mX = DATETIMETZ; } else { mX = DATETIME; } const bsl::string& EXPECTED = OBJ_TYPE ? EXPECTED_DATETIMETZ : EXPECTED_DATETIME; const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, JLINE, KLINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV( ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, JLINE, KLINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, JLINE, KLINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'OBJ_TYPE' ('Datetime' or 'DatetimeTz') } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of // 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED_DATETIME(DATETIME_BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED_DATETIME, C, k_DATETIME_MAX_PRECISION); bsl::string EXPECTED_DATETIMETZ( DATETIMETZ_BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED_DATETIMETZ, C, k_DATETIMETZ_MAX_PRECISION); for (int tt = 0; tt < 2; ++tt) { const int OBJ_TYPE = tt; if (OBJ_TYPE) { mX = DATETIMETZ; } else { mX = DATETIME; } const bsl::string& EXPECTED = OBJ_TYPE ? EXPECTED_DATETIMETZ : EXPECTED_DATETIME; const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV( ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'OBJ_TYPE' ('Datetime' or 'DatetimeTz') } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' } // loop over 'DATE_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { TYPE mX; const TYPE& X = mX; char buffer[OBJLEN]; char *pc = 0; const bdlt::Datetime DATETIME; mX = DATETIME; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL( Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL( Util::generate(buffer, -1, X, C)); bsl::string mSB("qwerty"); bsl::string *pb = 0; ASSERT_PASS(Util::generate(&mSB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mSB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mSS("qwerty"); std::string *ps = 0; ASSERT_PASS(Util::generate(&mSS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mSS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mSP("qwerty"); std::pmr::string *pp = 0; ASSERT_PASS(Util::generate(&mSP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mSP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); # endif } if (verbose) cout << "\t'generateRaw'" << endl; { TYPE mX; const TYPE& X = mX; char buffer[OBJLEN]; char *pc = 0; const bdlt::Datetime DATETIME; mX = DATETIME; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( pc, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL( Util::generateRaw( pc, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 13: { // -------------------------------------------------------------------- // GENERATE 'TimeTz' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Create a 'Variant2<Time, TimeTz>' object, 'X'. //: //: 2 Using the table-driven technique, specify a set of distinct //: 'Time' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 3 For each row 'R1' in the table from P-2 create a 'const' 'Time' //: object, 'T1', from 'R1'. //: //: 4 In a second table, specify a set of distinct timezone values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 5 For each element 'R2' in the cross product of the tables from P-2 //: and P-4: //: //: 1 Create a 'const' 'TimeTz' object, 'T2', from 'R2'. //: //: 2 Assign 'T1' to 'X'. //: //: 3 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R1' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. //: //: 4 Assign 'T2' to 'X'. //: //: 5 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R2' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 6 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const TimeOrTimeTzTz&); // int generate(char *, int, const TimeOrTimeTzTz&, const Config&); // int generate(string *, const TimeOrTimeTzTz&); // int generate(string *, const TimeOrTimeTzTz&, const Config&); // ostream generate(ostream&, const TimeOrTimeTzTz&); // ostream generate(ostream&, const TimeOrTimeTzTz&, const Config&); // int generateRaw(char *, const TimeOrTimeTzTz&); // int generateRaw(char *, const TimeOrTimeTzTz&, const Config&); // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 if (verbose) cout << endl << "GENERATE 'TimeOrTimeTz'" << endl << "=======================" << endl; typedef Util::TimeOrTimeTz TYPE; TYPE mX; const TYPE& X = mX; const int OBJLEN = Util::k_TIMETZ_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int ILINE = TIME_DATA[ti].d_line; const int HOUR = TIME_DATA[ti].d_hour; const int MIN = TIME_DATA[ti].d_min; const int SEC = TIME_DATA[ti].d_sec; const int MSEC = TIME_DATA[ti].d_msec; const int USEC = TIME_DATA[ti].d_usec; const char *ISO8601 = TIME_DATA[ti].d_iso8601; const bdlt::Time TIME(HOUR, MIN, SEC, MSEC, USEC); const bsl::string EXPECTED_TIME_BASE(ISO8601); for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; const char *ISO8601 = ZONE_DATA[tj].d_iso8601; const bsl::string EXPECTED_ZONE(ISO8601); if (TIME == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } const bdlt::TimeTz TIMETZ(TIME, OFFSET); const bsl::string EXPECTED_TIMETZ_BASE(EXPECTED_TIME_BASE + EXPECTED_ZONE); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(TIME) P_(TIMETZ) P_(EXPECTED_TIME_BASE) P(EXPECTED_TIMETZ_BASE) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED_TIME(EXPECTED_TIME_BASE); updateExpectedPerConfig(&EXPECTED_TIME, C, k_TIME_MAX_PRECISION); bsl::string EXPECTED_TIMETZ(EXPECTED_TIMETZ_BASE); updateExpectedPerConfig(&EXPECTED_TIMETZ, C, k_TIMETZ_MAX_PRECISION); for (int tt = 0; tt < 2; ++tt) { const int OBJ_TYPE = tt; if (OBJ_TYPE) { mX = TIMETZ; } else { mX = TIME; } const bsl::string& EXPECTED = OBJ_TYPE ? EXPECTED_TIMETZ : EXPECTED_TIME; const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, JLINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, JLINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV( ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV( ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to a 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV( ILINE, JLINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, JLINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'OBJ_TYPE' ('Time' or 'TimeTz') } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED_TIME(EXPECTED_TIME_BASE); updateExpectedPerConfig(&EXPECTED_TIME, C, k_TIME_MAX_PRECISION); bsl::string EXPECTED_TIMETZ(EXPECTED_TIMETZ_BASE); updateExpectedPerConfig(&EXPECTED_TIMETZ, C, k_TIMETZ_MAX_PRECISION); for (int tt = 0; tt < 2; ++tt) { const int OBJ_TYPE = tt; if (OBJ_TYPE) { mX = TIMETZ; } else { mX = TIME; } const bsl::string& EXPECTED = OBJ_TYPE ? EXPECTED_TIMETZ : EXPECTED_TIME; const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV( ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'OBJ_TYPE' ('Time' or 'TimeTz') } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { TYPE mX; const TYPE& X = mX; char buffer[OBJLEN]; char *pc = 0; const bdlt::Time TIME; mX = TIME; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL( Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL( Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"); bsl::string *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mS("qwerty"); std::string *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"); std::pmr::string *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); # endif } if (verbose) cout << "\t'generateRaw'" << endl; { TYPE mX; const TYPE& X = mX; char buffer[OBJLEN]; char *pc = 0; const bdlt::Time TIME; mX = TIME; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( pc, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL( Util::generateRaw( pc, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 12: { // -------------------------------------------------------------------- // GENERATE 'DateOrDateTz' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Create a 'Variant2<Date, DateTz>' object, 'X'. //: //: 2 Using the table-driven technique, specify a set of distinct //: 'Date' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 3 For each row 'R1' in the table from P-2 create a 'const' 'Date' //: object, 'D1', from 'R1'. //: //: 4 In a second table, specify a set of distinct timezone values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 5 For each element 'R2' in the cross product of the tables from P-2 //: and P-4: //: //: 1 Create a 'const' 'DateTz' object, 'D2', from 'R2'. //: //: 2 Assign 'D1' to 'X'. //: //: 3 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R1' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. //: //: 4 Assign 'D2' to 'X'. //: //: 5 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R2' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 6 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const DateOrDateTz&); // int generate(char *, int, const DateOrDateTz&, const Config&); // int generate(string *, const DateOrDateTz&); // int generate(string *, const DateOrDateTz&, const Config&); // ostream generate(ostream&, const DateOrDateTz&); // ostream generate(ostream&, const DateOrDateTz&, const Config&); // int generateRaw(char *, const DateOrDateTz&); // int generateRaw(char *, const DateOrDateTz&, const Config&); // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 if (verbose) cout << endl << "GENERATE 'DateOrDateTz'" << endl << "=======================" << endl; typedef Util::DateOrDateTz TYPE; TYPE mX; const TYPE& X = mX; const int OBJLEN = Util::k_DATETZ_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const char *ISO8601 = DATE_DATA[ti].d_iso8601; const bdlt::Date DATE(YEAR, MONTH, DAY); const bsl::string EXPECTED_DATE_BASE(ISO8601); for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; const char *ISO8601 = ZONE_DATA[tj].d_iso8601; const bsl::string EXPECTED_ZONE(ISO8601); const bdlt::DateTz DATETZ(DATE, OFFSET); const bsl::string EXPECTED_DATETZ_BASE(EXPECTED_DATE_BASE + EXPECTED_ZONE); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(DATE) P_(DATETZ) P_(EXPECTED_DATE_BASE) P(EXPECTED_DATETZ_BASE) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED_DATE(EXPECTED_DATE_BASE); updateExpectedPerConfig(&EXPECTED_DATE, C, k_DATE_MAX_PRECISION); bsl::string EXPECTED_DATETZ(EXPECTED_DATETZ_BASE); updateExpectedPerConfig(&EXPECTED_DATETZ, C, k_DATETZ_MAX_PRECISION); for (int tt = 0; tt < 2; ++tt) { const int OBJ_TYPE = tt; if (OBJ_TYPE) { mX = DATETZ; } else { mX = DATE; } const bsl::string& EXPECTED = OBJ_TYPE ? EXPECTED_DATETZ : EXPECTED_DATE; const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, JLINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, JLINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV( ILINE, JLINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, JLINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'OBJ_TYPE' ('Date' or 'DateTz') } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED_DATE(EXPECTED_DATE_BASE); updateExpectedPerConfig(&EXPECTED_DATE, C, k_DATE_MAX_PRECISION); bsl::string EXPECTED_DATETZ(EXPECTED_DATETZ_BASE); updateExpectedPerConfig(&EXPECTED_DATETZ, C, k_DATETZ_MAX_PRECISION); for (int tt = 0; tt < 2; ++tt) { const int OBJ_TYPE = tt; if (OBJ_TYPE) { mX = DATETZ; } else { mX = DATE; } const bsl::string& EXPECTED = OBJ_TYPE ? EXPECTED_DATETZ : EXPECTED_DATE; const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV( ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } # endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'OBJ_TYPE' ('Date' or 'DateTz') } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'DATE_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { TYPE mX; const TYPE& X = mX; char buffer[OBJLEN]; char *pc = 0; const bdlt::Date DATE; mX = DATE; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL( Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL( Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"); bsl::string *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mS("qwerty"); std::string *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); # ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"); std::pmr::string *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); # endif } if (verbose) cout << "\t'generateRaw'" << endl; { TYPE mX; const TYPE& X = mX; char buffer[OBJLEN]; char *pc = 0; const bdlt::Date DATE; mX = DATE; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( pc, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL( Util::generateRaw( pc, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 11: { // -------------------------------------------------------------------- // PARSE: DATETIME & DATETIMETZ // // Concerns: //: 1 All ISO 8601 string representations supported by this component //: (as documented in the header file) for 'Datetime' and //: 'DatetimeTz' values are parsed successfully. //: //: 2 If parsing succeeds, the result 'Datetime' or 'DatetimeTz' object //: has the expected value. //: //: 3 If the optional zone designator is present in the input string //: when parsing into a 'Datetime' object, the resulting value is //: converted to the equivalent UTC datetime. //: //: 4 If the optional zone designator is *not* present in the input //: string when parsing into a 'DatetimeTz' object, it is assumed to //: be UTC. //: //: 5 If parsing succeeds, 0 is returned. //: //: 6 All strings that are not ISO 8601 representations supported by //: this component for 'Datetime' and 'DatetimeTz' values are //: rejected (i.e., parsing fails). //: //: 7 If parsing fails, the result object is unaffected and a non-zero //: value is returned. //: //: 8 The entire extent of the input string is parsed. //: //: 9 Leap seconds, fractional seconds containing more than three //: digits, and extremal values (those that can overflow a //: 'Datetime') are handled correctly. //: //:10 The 'parseRelaxed' functions do the same as the 'parse' functions //: and additionally allow to use a SPACE characters instead of 'T'. //: //:11 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values ('D'), 'Time' values ('T'), zone designators ('Z'), //: and configurations ('C'). //: //: 2 Apply the (fully-tested) 'generateRaw' functions to each element //: in the cross product, 'D x T x Z x C', of the test data from P-1. //: //: 3 Invoke the 'parse' functions on the strings generated in P-2 and //: verify that parsing succeeds, i.e., that 0 is returned and the //: result objects have the expected values. (C-1..5) //: //: 4 Using the table-driven technique, specify a set of distinct //: strings that are not ISO 8601 representations supported by this //: component for 'Datetime' and 'DatetimeTz' values. //: //: 5 Invoke the 'parse' functions on the strings from P-4 and verify //: that parsing fails, i.e., that a non-zero value is returned and //: the result objects are unchanged. (C-6..8) //: //: 6 Using the table-driven technique, specify a set of distinct ISO //: 8601 strings that specifically cover cases involving leap //: seconds, fractional seconds containing more than three digits, //: and extremal values. //: //: 7 Invoke the 'parse' functions on the strings from P-6 and verify //: the results are as expected. (C-9) //: //: 8 Invoke the 'parseRelaxed' functions on the same strings and on //: the strings with 'T' character replaced by ' '. (C-10) //: //: 9 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-11) // // Testing: // int parse(Datetime *, const char *, int); // int parse(DatetimeTz *, const char *, int); // int parse(Datetime *result, const StringRef& string); // int parse(DatetimeTz *result, const StringRef& string); // int parseRelaxed(Datetime *, const char *, int); // int parseRelaxed(DatetimeTz *, const char *, int); // int parseRelaxed(Datetime *, const bsl::string_view&); // int parseRelaxed(DatetimeTz *, const bsl::string_view&); // -------------------------------------------------------------------- #ifdef U_TEST_PART_02 if (verbose) cout << endl << "PARSE: DATETIME & DATETIMETZ" << endl << "============================" << endl; char buffer[Util::k_MAX_STRLEN]; const bdlt::Date DD(246, 8, 10); const bdlt::Time TT(2, 4, 6, 8); const bdlt::Datetime XX(DD, TT); // 'XX' and 'ZZ' are controls, const bdlt::DatetimeTz ZZ(XX, -7); // distinct from any test data const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; if (verbose) cout << "\nValid ISO 8601 strings." << endl; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const bdlt::Date DATE(YEAR, MONTH, DAY); for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int JLINE = TIME_DATA[tj].d_line; const int HOUR = TIME_DATA[tj].d_hour; const int MIN = TIME_DATA[tj].d_min; const int SEC = TIME_DATA[tj].d_sec; const int MSEC = TIME_DATA[tj].d_msec; const int USEC = TIME_DATA[tj].d_usec; for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int KLINE = ZONE_DATA[tk].d_line; const int OFFSET = ZONE_DATA[tk].d_offset; if ( bdlt::Time(HOUR, MIN, SEC, MSEC, USEC) == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; int expMsec = MSEC; int expUsec = USEC; { // adjust the expected milliseconds to account for // PRECISION truncating the value generated int precision = (PRECISION < 3 ? PRECISION : 3); for (int i = 3; i > precision; --i) { expMsec /= 10; } for (int i = 3; i > precision; --i) { expMsec *= 10; } // adjust the expected microseconds to account for // PRECISION truncating the value generated precision = (PRECISION > 3 ? PRECISION - 3: 0); for (int i = 3; i > precision; --i) { expUsec /= 10; } for (int i = 3; i > precision; --i) { expUsec *= 10; } } const bdlt::Datetime DATETIME(YEAR, MONTH, DAY, HOUR, MIN, SEC, expMsec, expUsec); const bdlt::DatetimeTz DATETIMETZ(DATETIME, OFFSET); if (veryVerbose) { if (0 == tc) { T_ P_(ILINE) P_(JLINE) P_(KLINE) P_(DATETIME) P(DATETIMETZ); } T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ); } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // without zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, DATETIME, C); if (veryVerbose) { const bsl::string STRING(buffer, LENGTH); T_ T_ P(STRING) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); // parseRelaxed() on the same string mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed( &mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed( &mZ, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(buffer, LENGTH); mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); } // without zone designator in parsed string - basic { int LENGTH = Util::generateRaw(buffer, DATETIME, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, ':'); u::removeCharFromString(&str, '-'); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, str, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(str, DATETIME, X, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, str, 0 == Util::parse(&mZ, str.c_str(), LENGTH, u::BASIC)); ASSERTV(str, DATETIME, Z, DATETIME == Z.localDatetime()); ASSERTV(str, Z, 0 == Z.offset()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); // parseRelaxed() on the same string mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(str), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(str.c_str(), LENGTH); mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse( &mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse( &mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIME == Z.localDatetime()); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Z.offset()); } // with zone designator in parsed string { if ((DATE == bdlt::Date() && OFFSET > 0) || (DATE == bdlt::Date(9999, 12, 31) && OFFSET < 0)) { continue; // skip invalid compositions } const int LENGTH = Util::generateRaw(buffer, DATETIMETZ, C); const bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); // parseRelaxed() on the same string mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, str.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(buffer, LENGTH); mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, relaxed.data(), relaxed.length())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mX, relaxed.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, StrView(relaxed))); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parseRelaxed(&mZ, relaxed.c_str())); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); } // with zone designator in parsed string - basic { if ((DATE == bdlt::Date() && OFFSET > 0) || (DATE == bdlt::Date(9999, 12, 31) && OFFSET < 0)) { continue; // skip invalid compositions } int LENGTH = Util::generateRaw(buffer, DATETIMETZ, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, '-', 2); u::removeCharFromString(&str, ':'); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(str, DATETIMETZ.utcDatetime(), X, DATETIMETZ.utcDatetime() == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); // parseRelaxed() on the same string mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), LENGTH, u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(str), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); // parseRelaxed() on the string modified to have // SPACE instead of 'T' const bsl::string relaxed = replaceTWithSpace(str.c_str(), LENGTH); mX = XX; mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mX = XX; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ.utcDatetime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, KLINE, CLINE, 0 == Util::parse(&mZ, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(ILINE, JLINE, KLINE, CLINE, DATETIMETZ == Z); } } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' } // loop over 'DATE_DATA' { // verify 't' and 'z' are accepted bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; ASSERT(0 == Util::parse(&mX, "0001-02-03t01:02:03z", 20)); ASSERT(X == bdlt::Datetime(1, 2, 3, 1, 2, 3)); ASSERT(0 == Util::parse(&mZ, "0001-02-03t01:02:03z", 20)); ASSERT(Z == bdlt::DatetimeTz(bdlt::Datetime(1, 2, 3, 1, 2, 3), 0)); } if (verbose) cout << "\nInvalid strings." << endl; { bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; const int NUM_DATE_DATA = NUM_BAD_DATE_DATA; const BadDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = BAD_DATE_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; bsl::string bad(DATE_DATA[ti].d_invalid); // Append a valid time. bad.append("T12:26:52.726"); const char *STRING = bad.c_str(); const int LENGTH = static_cast<int>(bad.length()); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str())); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the same string ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, StrView(relaxed))); ASSERTV(LINE, STRING, ZZ == Z); } } if (verbose) cout << "\nInvalid strings - basic." << endl; { bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; const int NUM_DATE_DATA = NUM_BASIC_BAD_DATE_DATA; const BadDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = BASIC_BAD_DATE_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; bsl::string bad(DATE_DATA[ti].d_invalid); // Append a valid time. bad.append("T12:26:52.726"); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the same string ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(STRING, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); } const int NUM_TIME_DATA = NUM_BASIC_BAD_TIME_DATA; const BadTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = BASIC_BAD_TIME_DATA; for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int LINE = TIME_DATA[tj].d_line; // Initialize with a *valid* date string, then append an // invalid time. bsl::string bad("20100817"); // Ensure that 'bad' is initially valid. static bool firstFlag = true; if (firstFlag) { firstFlag = false; const char *STRING = bad.data(); const int LENGTH = static_cast<int>(bad.length()); bdlt::Date mD(DD); const bdlt::Date& D = mD; ASSERT( 0 == Util::parse(&mD, STRING, LENGTH, u::BASIC)); ASSERT(DD != D); mD = DD; ASSERT( 0 == Util::parse(&mD, StrView(bad), u::BASIC)); ASSERT(DD != D); mD = DD; ASSERT( 0 == Util::parse(&mD, bad.c_str(), u::BASIC)); ASSERT(DD != D); } bad.append("T"); bad.append(TIME_DATA[tj].d_invalid); const char *STRING = bad.c_str(); const int LENGTH = static_cast<int>(bad.length()); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse( &mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the same string ASSERTV(LINE, STRING, 0 != Util::parse( &mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, StrView(STRING, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, StrView(STRING, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int LINE = ZONE_DATA[tk].d_line; // Initialize with a *valid* datetime string, then append an // invalid zone designator. bsl::string bad("2010-08-17T12:26:52.726"); // Ensure that 'bad' is initially valid. static bool firstFlag = true; if (firstFlag) { firstFlag = false; const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Datetime mD(XX); const bdlt::Datetime& D = mD; ASSERT( 0 == Util::parse(&mD, STRING, LENGTH)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse(&mD, StrView(STRING, LENGTH))); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse(&mD, bad.c_str())); ASSERT(XX != D); // parseRelaxed() on the same string mD = XX; ASSERT( 0 == Util::parseRelaxed(&mD, STRING, LENGTH)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parseRelaxed(&mD, StrView(STRING, LENGTH))); ASSERT(XX != D); // parseRelaxed() on the string modified to have SPACE // instead of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mD = XX; ASSERT( 0 == Util::parseRelaxed(&mD, relaxed.data(), relaxed.length())); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parseRelaxed(&mD, StrView(relaxed))); ASSERT(XX != D); } // If 'ZONE_DATA[tk].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(ZONE_DATA[tk].d_invalid)) { continue; } bad.append(ZONE_DATA[tk].d_invalid); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str())); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the same string ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, relaxed.data(), relaxed.length())); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parseRelaxed(&mZ, StrView(relaxed))); ASSERTV(LINE, STRING, ZZ == Z); } for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int LINE = ZONE_DATA[tk].d_line; // Initialize with a *valid* datetime string, then append an // invalid zone designator - basic. bsl::string bad("20100817T122652.726"); // Ensure that 'bad' is initially valid. static bool firstFlag = true; if (firstFlag) { firstFlag = false; const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Datetime mD(XX); const bdlt::Datetime& D = mD; ASSERT( 0 == Util::parse(&mD, STRING, LENGTH, u::BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse(&mD, StrView(bad), u::BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse(&mD, bad.c_str(), u::BASIC)); ASSERT(XX != D); // parseRelaxed() on the same string mD = XX; ASSERT( 0 == Util::parse( &mD, STRING, LENGTH, u::RELAXED_BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse( &mD, StrView(bad), u::RELAXED_BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse( &mD, bad.c_str(), u::RELAXED_BASIC)); ASSERT(XX != D); // parseRelaxed() on the string modified to have SPACE // instead of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); mD = XX; ASSERT( 0 == Util::parse(&mD, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse( &mD, StrView(relaxed), u::RELAXED_BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse( &mD, relaxed.c_str(), u::RELAXED_BASIC)); ASSERT(XX != D); } // If 'ZONE_DATA[tk].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(ZONE_DATA[tk].d_invalid)) { continue; } bad.append(ZONE_DATA[tk].d_invalid); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse( &mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, StrView(STRING, LENGTH), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the same string ASSERTV(LINE, STRING, 0 != Util::parse( &mX, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, STRING, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, StrView(bad), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, bad.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(STRING, LENGTH); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse( &mZ, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, STRING, ZZ == Z); } } if (verbose) cout << "\nTesting leap seconds and fractional seconds." << endl; { const struct { int d_line; const char *d_input; int d_year; int d_month; int d_day; int d_hour; int d_min; int d_sec; int d_msec; int d_usec; int d_offset; } DATA[] = { // leap seconds { L_, "0001-01-01T00:00:60.000", 0001, 01, 01, 00, 01, 00, 000, 000, 0 }, { L_, "9998-12-31T23:59:60.999", 9999, 01, 01, 00, 00, 00, 999, 000, 0 }, // fractional seconds { L_, "0001-01-01T00:00:00.0000001", 0001, 01, 01, 00, 00, 00, 000, 000, 0 }, { L_, "0001-01-01T00:00:00.0000009", 0001, 01, 01, 00, 00, 00, 000, 1, 0 }, { L_, "0001-01-01T00:00:00.00000001", 0001, 01, 01, 00, 00, 00, 000, 000, 0 }, { L_, "0001-01-01T00:00:00.00000049", 0001, 01, 01, 00, 00, 00, 000, 000, 0 }, { L_, "0001-01-01T00:00:00.00000050", 0001, 01, 01, 00, 00, 00, 000, 1, 0 }, { L_, "0001-01-01T00:00:00.00000099", 0001, 01, 01, 00, 00, 00, 000, 1, 0 }, { L_, "0001-01-01T00:00:00.0001", 0001, 01, 01, 00, 00, 00, 000, 100, 0 }, { L_, "0001-01-01T00:00:00.0009", 0001, 01, 01, 00, 00, 00, 000, 900, 0 }, { L_, "0001-01-01T00:00:00.00001", 0001, 01, 01, 00, 00, 00, 000, 10, 0 }, { L_, "0001-01-01T00:00:00.00049", 0001, 01, 01, 00, 00, 00, 000, 490, 0 }, { L_, "0001-01-01T00:00:00.00050", 0001, 01, 01, 00, 00, 00, 000, 500, 0 }, { L_, "0001-01-01T00:00:00.00099", 0001, 01, 01, 00, 00, 00, 000, 990, 0 }, { L_, "0001-01-01T00:00:00.9994" , 0001, 01, 01, 00, 00, 00, 999, 400, 0 }, { L_, "0001-01-01T00:00:00.9995" , 0001, 01, 01, 00, 00, 00, 999, 500, 0 }, { L_, "0001-01-01T00:00:00.9999" , 0001, 01, 01, 00, 00, 00, 999, 900, 0 }, { L_, "9998-12-31T23:59:60.9999" , 9999, 01, 01, 00, 00, 00, 999, 900, 0 }, { L_, "0001-01-01T00:00:00.9999994" , 0001, 01, 01, 00, 00, 00, 999, 999, 0 }, { L_, "0001-01-01T00:00:00.9999995" , 0001, 01, 01, 00, 00, 01, 000, 000, 0 }, { L_, "0001-01-01T00:00:00.9999999" , 0001, 01, 01, 00, 00, 01, 000, 000, 0 }, { L_, "9998-12-31T23:59:60.9999999" , 9999, 01, 01, 00, 00, 01, 000, 000, 0 }, // omit fractional seconds { L_, "2014-12-23T12:34:45", 2014, 12, 23, 12, 34, 45, 000, 000, 0 }, { L_, "2014-12-23T12:34:45Z", 2014, 12, 23, 12, 34, 45, 000, 000, 0 }, { L_, "2014-12-23T12:34:45+00:30", 2014, 12, 23, 12, 34, 45, 000, 000, 30 }, { L_, "2014-12-23T12:34:45-01:30", 2014, 12, 23, 12, 34, 45, 000, 000, -90 }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int YEAR = DATA[ti].d_year; const int MONTH = DATA[ti].d_month; const int DAY = DATA[ti].d_day; const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int USEC = DATA[ti].d_usec; const int OFFSET = DATA[ti].d_offset; const bsl::string str(INPUT, LENGTH); if (veryVerbose) { T_ P_(LINE) P(INPUT) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; bdlt::DatetimeTz EXPECTED(bdlt::Datetime(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC, USEC), OFFSET); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, INPUT, LENGTH)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, str.c_str())); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, StrView(INPUT, LENGTH))); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the same string mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, INPUT, LENGTH)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mZ, INPUT, LENGTH)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, str.c_str())); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mZ, StrView(INPUT, LENGTH))); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mZ, str.c_str())); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(INPUT, LENGTH); mX = XX; mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mZ, relaxed.data(), relaxed.length())); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mX, relaxed.c_str())); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mZ, StrView(relaxed))); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parseRelaxed(&mZ, relaxed.c_str())); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); } } if (verbose) cout << "\nTesting leap seconds and fractional seconds - basic.\n"; { const struct { int d_line; const char *d_input; int d_year; int d_month; int d_day; int d_hour; int d_min; int d_sec; int d_msec; int d_usec; int d_offset; } DATA[] = { // leap seconds { L_, "00010101T000060.000", 0001, 01, 01, 00, 01, 00, 000, 000, 0 }, { L_, "99981231T235960.999", 9999, 01, 01, 00, 00, 00, 999, 000, 0 }, // fractional seconds { L_, "00010101T000000.0000001", 0001, 01, 01, 00, 00, 00, 000, 000, 0 }, { L_, "00010101T000000.0000009", 0001, 01, 01, 00, 00, 00, 000, 1, 0 }, { L_, "00010101T000000.00000001", 0001, 01, 01, 00, 00, 00, 000, 000, 0 }, { L_, "00010101T000000.00000049", 0001, 01, 01, 00, 00, 00, 000, 000, 0 }, { L_, "00010101T000000.00000050", 0001, 01, 01, 00, 00, 00, 000, 1, 0 }, { L_, "00010101T000000.00000099", 0001, 01, 01, 00, 00, 00, 000, 1, 0 }, { L_, "00010101T000000.0001", 0001, 01, 01, 00, 00, 00, 000, 100, 0 }, { L_, "00010101T000000.0009", 0001, 01, 01, 00, 00, 00, 000, 900, 0 }, { L_, "00010101T000000.00001", 0001, 01, 01, 00, 00, 00, 000, 10, 0 }, { L_, "00010101T000000.00049", 0001, 01, 01, 00, 00, 00, 000, 490, 0 }, { L_, "00010101T000000.00050", 0001, 01, 01, 00, 00, 00, 000, 500, 0 }, { L_, "00010101T000000.00099", 0001, 01, 01, 00, 00, 00, 000, 990, 0 }, { L_, "00010101T000000.9994" , 0001, 01, 01, 00, 00, 00, 999, 400, 0 }, { L_, "00010101T000000.9995" , 0001, 01, 01, 00, 00, 00, 999, 500, 0 }, { L_, "00010101T000000.9999" , 0001, 01, 01, 00, 00, 00, 999, 900, 0 }, { L_, "99981231T235960.9999" , 9999, 01, 01, 00, 00, 00, 999, 900, 0 }, { L_, "00010101T000000.9999994" , 0001, 01, 01, 00, 00, 00, 999, 999, 0 }, { L_, "00010101T000000.9999995" , 0001, 01, 01, 00, 00, 01, 000, 000, 0 }, { L_, "00010101T000000.9999999" , 0001, 01, 01, 00, 00, 01, 000, 000, 0 }, { L_, "99981231T235960.9999999" , 9999, 01, 01, 00, 00, 01, 000, 000, 0 }, // omit fractional seconds { L_, "20141223T123445", 2014, 12, 23, 12, 34, 45, 000, 000, 0 }, { L_, "20141223T123445Z", 2014, 12, 23, 12, 34, 45, 000, 000, 0 }, { L_, "20141223T123445+0030", 2014, 12, 23, 12, 34, 45, 000, 000, 30 }, { L_, "20141223T123445-0130", 2014, 12, 23, 12, 34, 45, 000, 000, -90 }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int YEAR = DATA[ti].d_year; const int MONTH = DATA[ti].d_month; const int DAY = DATA[ti].d_day; const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int USEC = DATA[ti].d_usec; const int OFFSET = DATA[ti].d_offset; bsl::string str(INPUT); if (veryVerbose) { T_ P_(LINE) P(str) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; bdlt::DatetimeTz EXPECTED(bdlt::Datetime(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC, USEC), OFFSET); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH, u::BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, INPUT, LENGTH, u::BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mX, StrView(INPUT, LENGTH), u::BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mX, str.c_str(), u::BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mZ, StrView(INPUT, LENGTH), u::BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mZ, str.c_str(), u::BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the same string mX = XX; mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mX, INPUT, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mZ, INPUT, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mX, StrView(INPUT, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mZ, StrView(INPUT, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mZ, str.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(INPUT, LENGTH); mX = XX; mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcDatetime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mZ, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse( &mZ, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); } } if (verbose) cout << "\nTesting zone designators that overflow a 'Datetime'." << endl; { struct { int d_line; const char *d_input; int d_year; int d_month; int d_day; int d_hour; int d_min; int d_sec; int d_msec; int d_offset; } DATA[] = { { L_, "0001-01-01T00:00:00.000+00:00", 0001, 01, 01, 00, 00, 00, 000, 0 }, { L_, "0001-01-01T00:00:00.000+00:01", 0001, 01, 01, 00, 00, 00, 000, 1 }, { L_, "0001-01-01T23:58:59.000+23:59", 0001, 01, 01, 23, 58, 59, 000, 1439 }, { L_, "9999-12-31T23:59:59.999+00:00", 9999, 12, 31, 23, 59, 59, 999, 0 }, { L_, "9999-12-31T23:59:59.999-00:01", 9999, 12, 31, 23, 59, 59, 999, -1 }, { L_, "9999-12-31T00:01:00.000-23:59", 9999, 12, 31, 00, 01, 00, 000, -1439 }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int YEAR = DATA[ti].d_year; const int MONTH = DATA[ti].d_month; const int DAY = DATA[ti].d_day; const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int OFFSET = DATA[ti].d_offset; const bsl::string str(INPUT); if (veryVerbose) { T_ P_(LINE) P(str) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; bdlt::DatetimeTz EXPECTED(bdlt::Datetime(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC), OFFSET); if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parse(&mX, INPUT, LENGTH)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parse(&mX, INPUT, LENGTH)); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parse(&mZ, INPUT, LENGTH)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); if (0 == OFFSET) { mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse(&mX, str.c_str())); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, XX == X); mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, INPUT, XX == X); } mZ = ZZ; ASSERTV(LINE, INPUT, 0 == Util::parse(&mZ, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the same string mX = XX; mZ = ZZ; if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mX, INPUT, LENGTH)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parseRelaxed(&mX, INPUT, LENGTH)); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mZ, INPUT, LENGTH)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); mX = XX; mZ = ZZ; if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parseRelaxed(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mZ, StrView(INPUT, LENGTH))); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(INPUT, LENGTH); mX = XX; mZ = ZZ; if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parseRelaxed(&mX, relaxed.data(), relaxed.length())); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mZ, relaxed.data(), relaxed.length())); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); mX = XX; mZ = ZZ; if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parseRelaxed(&mX, StrView(relaxed))); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parseRelaxed(&mZ, StrView(relaxed))); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); } } if (verbose) cout << "\nTesting zone designators that overflow a 'Datetime' - basic.\n"; { struct { int d_line; const char *d_input; int d_year; int d_month; int d_day; int d_hour; int d_min; int d_sec; int d_msec; int d_offset; } DATA[] = { { L_, "00010101T000000.000+0000", 0001, 01, 01, 00, 00, 00, 000, 0 }, { L_, "00010101T000000.000+0001", 0001, 01, 01, 00, 00, 00, 000, 1 }, { L_, "00010101T235859.000+2359", 0001, 01, 01, 23, 58, 59, 000, 1439 }, { L_, "99991231T235959.999+0000", 9999, 12, 31, 23, 59, 59, 999, 0 }, { L_, "99991231T235959.999-0001", 9999, 12, 31, 23, 59, 59, 999, -1 }, { L_, "99991231T000100.000-2359", 9999, 12, 31, 00, 01, 00, 000, -1439 }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int YEAR = DATA[ti].d_year; const int MONTH = DATA[ti].d_month; const int DAY = DATA[ti].d_day; const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int OFFSET = DATA[ti].d_offset; bsl::string str(INPUT); if (veryVerbose) { T_ P_(LINE) P(INPUT) } bdlt::Datetime mX(XX); const bdlt::Datetime& X = mX; bdlt::DatetimeTz mZ(ZZ); const bdlt::DatetimeTz& Z = mZ; bdlt::DatetimeTz EXPECTED(bdlt::Datetime(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC), OFFSET); if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parse( &mX, INPUT, LENGTH, u::BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parse( &mX, INPUT, LENGTH, u::BASIC)); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parse( &mZ, INPUT, LENGTH, u::BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; if (0 == OFFSET) { mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse( &mX, StrView(INPUT, LENGTH), u::BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse( &mX, StrView(INPUT, LENGTH), u::BASIC)); ASSERTV(LINE, INPUT, XX == X); mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parse( &mZ, StrView(INPUT, LENGTH), u::BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the same string mX = XX; mZ = ZZ; if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parse( &mX, INPUT, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parse( &mX, INPUT, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parse( &mZ, INPUT, LENGTH, u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); if (0 == OFFSET) { mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse( &mX, StrView(INPUT, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse( &mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse( &mX, StrView(INPUT, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, XX == X); mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse( &mX, str.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, XX == X); } mZ = ZZ; ASSERTV(LINE, INPUT, 0 == Util::parse( &mZ, StrView(INPUT, LENGTH), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, 0 == Util::parse( &mZ, str.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); // parseRelaxed() on the string modified to have SPACE instead // of 'T' const bsl::string relaxed = replaceTWithSpace(INPUT, LENGTH); mX = XX; mZ = ZZ; if (0 == OFFSET) { ASSERTV(LINE, INPUT, 0 == Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { ASSERTV(LINE, INPUT, 0 != Util::parse(&mX, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, XX == X); } ASSERTV(LINE, INPUT, 0 == Util::parse(&mZ, relaxed.data(), relaxed.length(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); if (0 == OFFSET) { mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); mX = XX; ASSERTV(LINE, INPUT, 0 == Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED.utcDatetime() == X); } else { mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse(&mX, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, XX == X); mX = XX; ASSERTV(LINE, INPUT, 0 != Util::parse(&mX, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, XX == X); } mZ = ZZ; ASSERTV(LINE, INPUT, 0 == Util::parse(&mZ, StrView(relaxed), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, 0 == Util::parse(&mZ, relaxed.c_str(), u::RELAXED_BASIC)); ASSERTV(LINE, INPUT, EXPECTED, Z, EXPECTED == Z); } } if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const char *INPUT = "2013-10-23T01:23:45"; const ptrdiff_t LENGTH = bsl::strlen(INPUT); const StrView stringRef(INPUT, LENGTH); const StrView nullRef; bdlt::Datetime result; bdlt::DatetimeTz resultTz; if (veryVerbose) cout << "\t'Invalid result'" << endl; { bdlt::Datetime *bad = 0; bdlt::DatetimeTz *badTz = 0; ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( bad, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( badTz, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &result, stringRef)); ASSERT_FAIL(Util::parse( bad, stringRef)); ASSERT_PASS(Util::parse(&resultTz, stringRef)); ASSERT_FAIL(Util::parse( badTz, stringRef)); ASSERT_PASS(Util::parseRelaxed( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parseRelaxed( bad, INPUT, LENGTH)); ASSERT_PASS(Util::parseRelaxed(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parseRelaxed( badTz, INPUT, LENGTH)); ASSERT_PASS(Util::parseRelaxed( &result, stringRef)); ASSERT_FAIL(Util::parseRelaxed( bad, stringRef)); ASSERT_PASS(Util::parseRelaxed(&resultTz, stringRef)); ASSERT_FAIL(Util::parseRelaxed( badTz, stringRef)); } if (veryVerbose) cout << "\t'Invalid input'" << endl; { ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( &result, 0, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(&resultTz, 0, LENGTH)); ASSERT_PASS(Util::parse( &result, stringRef)); ASSERT_FAIL(Util::parse( &result, nullRef)); ASSERT_PASS(Util::parse(&resultTz, stringRef)); ASSERT_FAIL(Util::parse(&resultTz, nullRef)); ASSERT_PASS(Util::parseRelaxed( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parseRelaxed( &result, 0, LENGTH)); ASSERT_PASS(Util::parseRelaxed(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parseRelaxed(&resultTz, 0, LENGTH)); ASSERT_PASS(Util::parseRelaxed( &result, stringRef)); ASSERT_FAIL(Util::parseRelaxed( &result, nullRef)); ASSERT_PASS(Util::parseRelaxed(&resultTz, stringRef)); ASSERT_FAIL(Util::parseRelaxed(&resultTz, nullRef)); } if (veryVerbose) cout << "\t'Invalid length'" << endl; { ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &result, INPUT, 0)); ASSERT_FAIL(Util::parse( &result, INPUT, -1)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, 0)); ASSERT_FAIL(Util::parse(&resultTz, INPUT, -1)); ASSERT_PASS(Util::parseRelaxed( &result, INPUT, LENGTH)); ASSERT_PASS(Util::parseRelaxed( &result, INPUT, 0)); ASSERT_FAIL(Util::parseRelaxed( &result, INPUT, -1)); ASSERT_PASS(Util::parseRelaxed(&resultTz, INPUT, LENGTH)); ASSERT_PASS(Util::parseRelaxed(&resultTz, INPUT, 0)); ASSERT_FAIL(Util::parseRelaxed(&resultTz, INPUT, -1)); } } if (verbose) cout << "\nNegative Testing - basic." << endl; { bsls::AssertTestHandlerGuard hG; const char *INPUT = "20131023T012345"; const ptrdiff_t LENGTH = bsl::strlen(INPUT); const StrView stringRef(INPUT, LENGTH); const StrView nullRef; bdlt::Datetime result; bdlt::DatetimeTz resultTz; } #else U_TEST_CASE_SKIPPED #endif } break; case 10: { // -------------------------------------------------------------------- // PARSE: TIME & TIMETZ // // Concerns: //: 1 All ISO 8601 string representations supported by this component //: (as documented in the header file) for 'Time' and 'TimeTz' values //: are parsed successfully. //: //: 2 If parsing succeeds, the result 'Time' or 'TimeTz' object has the //: expected value. //: //: 3 If the optional zone designator is present in the input string //: when parsing into a 'Time' object, the resulting value is //: converted to the equivalent UTC time. //: //: 4 If the optional zone designator is *not* present in the input //: string when parsing into a 'TimeTz' object, it is assumed to be //: UTC. //: //: 5 If parsing succeeds, 0 is returned. //: //: 6 All strings that are not ISO 8601 representations supported by //: this component for 'Time' and 'TimeTz' values are rejected (i.e., //: parsing fails). //: //: 7 If parsing fails, the result object is unaffected and a non-zero //: value is returned. //: //: 8 The entire extent of the input string is parsed. //: //: 9 Leap seconds and fractional seconds containing more than three //: digits are handled correctly. //: //:10 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Time' values ('T'), zone designators ('Z'), and configurations //: ('C'). //: //: 2 Apply the (fully-tested) 'generateRaw' functions to each element //: in the cross product, 'T x Z x C', of the test data from P-1. //: //: 3 Invoke the 'parse' functions on the strings generated in P-2 and //: verify that parsing succeeds, i.e., that 0 is returned and the //: result objects have the expected values. (C-1..5) //: //: 4 Using the table-driven technique, specify a set of distinct //: strings that are not ISO 8601 representations supported by this //: component for 'Time' and 'TimeTz' values. //: //: 5 Invoke the 'parse' functions on the strings from P-4 and verify //: that parsing fails, i.e., that a non-zero value is returned and //: the result objects are unchanged. (C-6..8) //: //: 6 Using the table-driven technique, specify a set of distinct //: ISO 8601 strings that specifically cover cases involving leap //: seconds and fractional seconds containing more than three digits. //: //: 7 Invoke the 'parse' functions on the strings from P-6 and verify //: the results are as expected. (C-9) //: //: 8 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-10) // // Testing: // int parse(Time *, const char *, int); // int parse(TimeTz *, const char *, int); // int parse(Time *result, const StringRef& string); // int parse(TimeTz *result, const StringRef& string); // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "PARSE: TIME & TIMETZ" << endl << "====================" << endl; char buffer[Util::k_MAX_STRLEN]; const bdlt::Time XX(2, 4, 6, 8); // 'XX' and 'ZZ' are controls, const bdlt::TimeTz ZZ(XX, -7); // distinct from any test data const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; if (verbose) cout << "\nValid ISO 8601 strings." << endl; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int ILINE = TIME_DATA[ti].d_line; const int HOUR = TIME_DATA[ti].d_hour; const int MIN = TIME_DATA[ti].d_min; const int SEC = TIME_DATA[ti].d_sec; const int MSEC = TIME_DATA[ti].d_msec; const int USEC = TIME_DATA[ti].d_usec; for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; if ( bdlt::Time(HOUR, MIN, SEC, MSEC, USEC) == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; int expMsec = MSEC; int expUsec = USEC; { // adjust the expected milliseconds to account for // PRECISION truncating the value generated int precision = (PRECISION < 3 ? PRECISION : 3); for (int i = 3; i > precision; --i) { expMsec /= 10; } for (int i = 3; i > precision; --i) { expMsec *= 10; } // adjust the expected microseconds to account for // PRECISION truncating the value generated precision = (PRECISION > 3 ? PRECISION - 3: 0); for (int i = 3; i > precision; --i) { expUsec /= 10; } for (int i = 3; i > precision; --i) { expUsec *= 10; } } const bdlt::Time TIME(HOUR, MIN, SEC, expMsec, expUsec); const bdlt::TimeTz TIMETZ(TIME, OFFSET); if (veryVerbose) { if (0 == tc) { T_ P_(ILINE) P_(JLINE) P_(TIME) P(TIMETZ); } T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ); } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // without zone designator in parsed string if (0 == tj) { const int LENGTH = Util::generateRaw(buffer, TIME, C); const bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } bdlt::Time mX(XX); const bdlt::Time& X = mX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, TIME, X, TIME == X); bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, TIME == Z.localTime()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, TIME == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, TIME == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, TIME == Z.localTime()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, TIME == Z.localTime()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); } // without zone designator in parsed string - basic if (0 == tj) { const int LEN = Util::generateRaw(buffer, TIME, C); buffer[LEN] = 0; bsl::string str(buffer, LEN); u::removeCharFromString(&str, ':'); const ptrdiff_t LENGTH = str.length(); if (veryVerbose) { T_ T_ P(str) } bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, str, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, str, TIME, X, TIME == X); ASSERTV(ILINE, JLINE, CLINE, str, 0 == Util::parse(&mZ, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, str, TIME == Z.localTime()); ASSERTV(ILINE, JLINE, CLINE, str, 0 == Z.offset()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, str, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIME == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, str, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIME == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, str, 0 == Util::parse(&mZ, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, str, TIME == Z.localTime()); ASSERTV(ILINE, JLINE, CLINE, str, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, str, 0 == Util::parse(&mZ, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, str, TIME == Z.localTime()); ASSERTV(ILINE, JLINE, CLINE, str, 0 == Z.offset()); } // with zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, TIMETZ, C); const bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ.utcTime() == X); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, TIMETZ.utcTime() == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, TIMETZ.utcTime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == Z); } // with zone designator in parsed string - basic { int LENGTH = Util::generateRaw(buffer, TIMETZ, C); bsl::string str(buffer, LENGTH); u::removeCharFromString(&str, ':'); LENGTH = static_cast<int>(str.length()); if (veryVerbose) { T_ T_ P(str) } bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ.utcTime() == X); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ.utcTime() == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ.utcTime() == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, TIMETZ == Z); } } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' { // verify 'z' is accepted bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; ASSERT(0 == Util::parse(&mX, "01:02:03z", 9)); ASSERT(X == bdlt::Time(1, 2, 3)); ASSERT(0 == Util::parse(&mZ, "01:02:03z", 9)); ASSERT(Z == bdlt::TimeTz(bdlt::Time(1, 2, 3), 0)); } { // verify 'z' is accepted - basic bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; ASSERT(0 == Util::parse(&mX, "010203z", 7, u::BASIC)); ASSERT(X == bdlt::Time(1, 2, 3)); ASSERT(0 == Util::parse(&mZ, "010203z", 7, u::BASIC)); ASSERT(Z == bdlt::TimeTz(bdlt::Time(1, 2, 3), 0)); } if (verbose) cout << "\nInvalid strings." << endl; { bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; const int NUM_TIME_DATA = NUM_BAD_TIME_DATA; const BadTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = BAD_TIME_DATA; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int LINE = TIME_DATA[ti].d_line; const char *STRING = TIME_DATA[ti].d_invalid; const int LENGTH = static_cast<int>(bsl::strlen(STRING)); const bsl::string str(STRING, LENGTH); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, str.c_str())); ASSERTV(LINE, STRING, ZZ == Z); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int ti = 0; ti < NUM_ZONE_DATA; ++ti) { const int LINE = ZONE_DATA[ti].d_line; // Initialize with a *valid* time string, then append an // invalid zone designator. bsl::string bad("12:26:52.726"); // Ensure that 'bad' is initially valid. static bool firstFlag = true; if (firstFlag) { firstFlag = false; const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Time mT(XX); const bdlt::Time& T = mT; ASSERT( 0 == Util::parse(&mT, STRING, LENGTH)); ASSERT(XX != T); mT = XX; ASSERT( 0 == Util::parse(&mT, StrView(STRING, LENGTH))); ASSERT(XX != T); } // If 'ZONE_DATA[ti].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(ZONE_DATA[ti].d_invalid)) { continue; } bad.append(ZONE_DATA[ti].d_invalid); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str())); ASSERTV(LINE, STRING, ZZ == Z); } } if (verbose) cout << "\nInvalid strings -- basic." << endl; { bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; const int NUM_TIME_DATA = NUM_BASIC_BAD_TIME_DATA; const BadTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = BASIC_BAD_TIME_DATA; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int LINE = TIME_DATA[ti].d_line; const char *STRING = TIME_DATA[ti].d_invalid; bsl::string str(STRING); u::removeCharFromString(&str, ':'); STRING = str.c_str(); const ptrdiff_t LENGTH = str.length(); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(str))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(str))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, str.c_str())); ASSERTV(LINE, STRING, ZZ == Z); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int ti = 0; ti < NUM_ZONE_DATA; ++ti) { const int LINE = ZONE_DATA[ti].d_line; // Initialize with a *valid* time string, then append an // invalid zone designator. bsl::string bad("12:26:52.726"); // Ensure that 'bad' is initially valid. static bool firstFlag = true; if (firstFlag) { firstFlag = false; const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Time mT(XX); const bdlt::Time& T = mT; ASSERT( 0 == Util::parse(&mT, STRING, LENGTH)); ASSERT(XX != T); mT = XX; ASSERT( 0 == Util::parse(&mT, StrView(bad))); ASSERT(XX != T); } bsl::string invalid(ZONE_DATA[ti].d_invalid); u::removeCharFromString(&invalid, ':'); // If 'ZONE_DATA[ti].d_invalid' contains nothing but digits, // appending it to 'bad' simply extends the fractional second // (so 'bad' remains valid). if (containsOnlyDigits(invalid.c_str())) { continue; } bad += invalid; const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); } } if (verbose) cout << "\nTesting leap seconds and fractional seconds." << endl; { const struct { int d_line; const char *d_input; int d_hour; int d_min; int d_sec; int d_msec; int d_usec; int d_offset; } DATA[] = { // leap seconds { L_, "00:00:60.000", 00, 01, 00, 000, 000, 0 }, { L_, "22:59:60.999", 23, 00, 00, 999, 000, 0 }, { L_, "23:59:60.999", 00, 00, 00, 999, 000, 0 }, // fractional seconds { L_, "00:00:00.0001", 00, 00, 00, 000, 100, 0 }, { L_, "00:00:00.0009", 00, 00, 00, 000, 900, 0 }, { L_, "00:00:00.00001", 00, 00, 00, 000, 10, 0 }, { L_, "00:00:00.00049", 00, 00, 00, 000, 490, 0 }, { L_, "00:00:00.00050", 00, 00, 00, 000, 500, 0 }, { L_, "00:00:00.00099", 00, 00, 00, 000, 990, 0 }, { L_, "00:00:00.0000001", 00, 00, 00, 000, 000, 0 }, { L_, "00:00:00.0000009", 00, 00, 00, 000, 001, 0 }, { L_, "00:00:00.00000001", 00, 00, 00, 000, 000, 0 }, { L_, "00:00:00.00000049", 00, 00, 00, 000, 000, 0 }, { L_, "00:00:00.00000050", 00, 00, 00, 000, 001, 0 }, { L_, "00:00:00.00000099", 00, 00, 00, 000, 001, 0 }, { L_, "00:00:00.9994", 00, 00, 00, 999, 400, 0 }, { L_, "00:00:00.9995", 00, 00, 00, 999, 500, 0 }, { L_, "00:00:00.9999", 00, 00, 00, 999, 900, 0 }, { L_, "00:00:59.9999", 00, 00, 59, 999, 900, 0 }, { L_, "23:59:59.9999", 23, 59, 59, 999, 900, 0 }, { L_, "00:00:00.9999994", 00, 00, 00, 999, 999, 0 }, { L_, "00:00:00.9999995", 00, 00, 1, 000, 000, 0 }, { L_, "00:00:00.9999999", 00, 00, 1, 000, 000, 0 }, { L_, "00:00:59.9999999", 00, 1, 00, 000, 000, 0 }, { L_, "23:59:59.9999999", 00, 00, 00, 000, 000, 0 }, // omit fractional seconds { L_, "12:34:45", 12, 34, 45, 000, 000, 0 }, { L_, "12:34:45Z", 12, 34, 45, 000, 000, 0 }, { L_, "12:34:45+00:30", 12, 34, 45, 000, 000, 30 }, { L_, "00:00:00+00:30", 00, 00, 00, 000, 000, 30 }, { L_, "12:34:45-01:30", 12, 34, 45, 000, 000, -90 }, { L_, "23:59:59-01:30", 23, 59, 59, 000, 000, -90 }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); const int HOUR = DATA[ti].d_hour; const int MIN = DATA[ti].d_min; const int SEC = DATA[ti].d_sec; const int MSEC = DATA[ti].d_msec; const int USEC = DATA[ti].d_usec; const int OFFSET = DATA[ti].d_offset; if (veryVerbose) { T_ P_(LINE) P(INPUT) } // Test 'parse' { bsl::string str(INPUT, LENGTH); bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz EXPECTED(bdlt::Time(HOUR, MIN, SEC, MSEC, USEC), OFFSET); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcTime() == X); bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, INPUT, LENGTH)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcTime() == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, str.c_str())); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcTime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, StrView(INPUT, LENGTH))); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); } // Test 'parseBasic' { bdlt::Time mX(XX); const bdlt::Time& X = mX; bdlt::TimeTz mZ(ZZ); const bdlt::TimeTz& Z = mZ; bdlt::TimeTz EXPECTED(bdlt::Time(HOUR, MIN, SEC, MSEC, USEC), OFFSET); bsl::string str(INPUT, LENGTH); u::removeCharFromString(&str, ':'); INPUT = str.c_str(); const ptrdiff_t LEN = str.length(); ASSERTV(LINE, INPUT, LEN, 0 == Util::parse(&mX, INPUT, LEN, u::BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcTime() == X); ASSERTV(LINE, INPUT, LEN, 0 == Util::parse(&mZ, INPUT, LEN, u::BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mX = XX; ASSERTV(LINE, INPUT, LEN, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcTime() == X); mX = XX; ASSERTV(LINE, INPUT, LEN, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(LINE, EXPECTED, X, EXPECTED.utcTime() == X); mZ = ZZ; ASSERTV(LINE, INPUT, LEN, 0 == Util::parse(&mZ, StrView(str), u::BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); mZ = ZZ; ASSERTV(LINE, INPUT, LEN, 0 == Util::parse(&mZ, str.c_str(), u::BASIC)); ASSERTV(LINE, EXPECTED, Z, EXPECTED == Z); } } } if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const char *INPUT = "01:23:45"; const ptrdiff_t LENGTH = bsl::strlen(INPUT); const StrView stringRef(INPUT, LENGTH); const StrView nullRef; bdlt::Time result; bdlt::TimeTz resultTz; if (veryVerbose) cout << "\t'Invalid result'" << endl; { bdlt::Time *bad = 0; bdlt::TimeTz *badTz = 0; ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( bad, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( badTz, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &result, stringRef)); ASSERT_FAIL(Util::parse( bad, stringRef)); ASSERT_PASS(Util::parse(&resultTz, stringRef)); ASSERT_FAIL(Util::parse( badTz, stringRef)); } if (veryVerbose) cout << "\t'Invalid input'" << endl; { ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( &result, 0, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(&resultTz, 0, LENGTH)); ASSERT_PASS(Util::parse( &result, stringRef)); ASSERT_FAIL(Util::parse( &result, nullRef)); ASSERT_PASS(Util::parse(&resultTz, stringRef)); ASSERT_FAIL(Util::parse(&resultTz, nullRef)); } if (veryVerbose) cout << "\t'Invalid length'" << endl; { ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &result, INPUT, 0)); ASSERT_FAIL(Util::parse( &result, INPUT, -1)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, 0)); ASSERT_FAIL(Util::parse(&resultTz, INPUT, -1)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 9: { // -------------------------------------------------------------------- // PARSE: bsls::TimeInterval // // Concerns: //: 1 All ISO 8601 string representations supported by this component //: (as documented in the header file) for 'TimeInterval' values are //: parsed successfully. //: //: 2 If parsing succeeds, the result 'TimeInterval' object has the //: expected value. //: //: 3 If parsing succeeds, 0 is returned. //: //: 4 All strings that are not ISO 8601 representations supported by //: this component for 'TimeInterval' values are rejected (i.e., //: parsing fails). //: //: 5 If parsing fails, the result object is uneffected and a non-zero //: value is returned. //: //: 6 The entire extent of the input string is parsed. //: //: 7 Fractional seconds containing more than nine digits are handled //: correctly. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'TimeInterval' values. //: //: 2 Apply the (fully-tested) 'generateRaw' functions to each element //: in the cross product, 'T x Z x C', of the test data from P-1. //: //: 3 Invoke the 'parse' functions on the strings generated in P-2 and //: verify that parsing succeeds, i.e., that 0 is returned and the //: result objects have the expected values. (C-1..5) //: //: 4 Using the table-driven technique, specify a set of distinct //: strings that are not ISO 8601 representations supported by this //: component for 'Time' and 'TimeTz' values. //: //: 5 Invoke the 'parse' functions on the strings from P-4 and verify //: that parsing fails, i.e., that a non-zero value is returned and //: the result objects are unchanged. (C-6..8) //: //: 6 Using the table-driven technique, specify a set of distinct //: ISO 8601 strings that specifically cover cases involving leap //: seconds and fractional seconds containing more than three digits. //: //: 7 Invoke the 'parse' functions on the strings from P-6 and verify //: the results are as expected. (C-9) // // Testing: // int parse(Time *, const char *, int); // int parse(TimeTz *, const char *, int); // int parse(Time *result, const StringRef& string); // int parse(TimeTz *result, const StringRef& string); // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "PARSE: bsls::TimeInterval" << endl << "=========================" << endl; const bsls::TimeInterval XX(2, 4); // A control, distinct from any // test data. if (verbose) cout << "\nTesting bsls::TimeInterval." << endl; { const int NUM_INTERVAL_DATA = NUM_DEFAULT_INTERVAL_DATA; const DefaultIntervalDataRow (&INTERVAL_DATA)[NUM_INTERVAL_DATA] = DEFAULT_INTERVAL_DATA; for (int ti = 0; ti < NUM_INTERVAL_DATA; ++ti) { const int LINE = INTERVAL_DATA[ti].d_line; const char *INPUT = INTERVAL_DATA[ti].d_iso8601; const ptrdiff_t LENGTH = bsl::strlen(INPUT); const bsls::Types::Int64 SEC = INTERVAL_DATA[ti].d_sec; const int USEC = INTERVAL_DATA[ti].d_usec; if (veryVerbose) { T_ P_(LINE) P(INPUT) } bsls::TimeInterval mX(XX); const bsls::TimeInterval& X = mX; bsls::TimeInterval EXPECTED(SEC, USEC); ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, INPUT, LENGTH)); ASSERTV(LINE, EXPECTED, X, EXPECTED == X); mX = XX; ASSERTV(LINE, INPUT, LENGTH, 0 == Util::parse(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, EXPECTED, X, EXPECTED == X); } } if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const struct { int d_line; const char *d_input; } DATA[] = { { L_, "1D" }, { L_, "P" }, { L_, "P0" }, { L_, "P1" }, { L_, "PW" }, { L_, "PW1D" }, { L_, "P1D1W" }, { L_, "P1D1D" }, { L_, "P1H" }, { L_, "PT" }, { L_, "PT1" }, { L_, "P1.0W1D" }, { L_, "PT1.1H1M" }, { L_, "PT1.0H1.0S" }, }; const int NUM_DATA = static_cast<int>(sizeof DATA / sizeof *DATA); for (int ti = 0; ti < NUM_DATA; ++ti) { const int LINE = DATA[ti].d_line; const char *INPUT = DATA[ti].d_input; const int LENGTH = static_cast<int>(bsl::strlen(INPUT)); if (veryVerbose) { T_ P_(LINE) P(INPUT) } bsls::TimeInterval mX(XX); const bsls::TimeInterval& X = mX; ASSERTV(LINE, INPUT, LENGTH, 0 != Util::parse(&mX, INPUT, LENGTH)); ASSERTV(LINE, XX, X, XX == X); ASSERTV(LINE, INPUT, LENGTH, 0 != Util::parse(&mX, StrView(INPUT, LENGTH))); ASSERTV(LINE, XX, X, XX == X); } } #else U_TEST_CASE_SKIPPED #endif } break; case 8: { // -------------------------------------------------------------------- // PARSE: DATE & DATETZ // // Concerns: //: 1 All ISO 8601 string representations supported by this component //: (as documented in the header file) for 'Date' and 'DateTz' values //: are parsed successfully. //: //: 2 If parsing succeeds, the result 'Date' or 'DateTz' object has the //: expected value. //: //: 3 If the optional zone designator is present in the input string //: when parsing into a 'Date' object, it is parsed for validity but //: is otherwise ignored. //: //: 4 If the optional zone designator is *not* present in the input //: string when parsing into a 'DateTz' object, it is assumed to be //: UTC. //: //: 5 If parsing succeeds, 0 is returned. //: //: 6 All strings that are not ISO 8601 representations supported by //: this component for 'Date' and 'DateTz' values are rejected (i.e., //: parsing fails). //: //: 7 If parsing fails, the result object is unaffected and a non-zero //: value is returned. //: //: 8 The entire extent of the input string is parsed. //: //: 9 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values ('D'), zone designators ('Z'), and configurations //: ('C'). //: //: 2 Apply the (fully-tested) 'generateRaw' functions to each element //: in the cross product, 'D x Z x C', of the test data from P-1. //: //: 3 Invoke the 'parse' functions on the strings generated in P-2 and //: verify that parsing succeeds, i.e., that 0 is returned and the //: result objects have the expected values. (C-1..5) //: //: 4 Using the table-driven technique, specify a set of distinct //: strings that are not ISO 8601 representations supported by this //: component for 'Date' and 'DateTz' values. //: //: 5 Invoke the 'parse' functions on the strings from P-4 and verify //: that parsing fails, i.e., that a non-zero value is returned and //: the result objects are unchanged. (C-6..8) //: //: 6 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-9) // // Testing: // int parse(Date *, const char *, int); // int parse(DateTz *, const char *, int); // int parse(Date *result, const StringRef& string); // int parse(DateTz *result, const StringRef& string); // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "PARSE: DATE & DATETZ" << endl << "====================" << endl; char buffer[Util::k_MAX_STRLEN]; const bdlt::Date XX(246, 8, 10); // 'XX' and 'ZZ' are controls, const bdlt::DateTz ZZ(XX, -7); // distinct from any test data const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; if (verbose) cout << "\nValid ISO 8601 strings." << endl; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const char *DATE_ISO = DATE_DATA[ti].d_iso8601; const bdlt::Date DATE(YEAR, MONTH, DAY); for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; const char *ZONE_ISO = ZONE_DATA[tj].d_iso8601; const bdlt::DateTz DATETZ(DATE, OFFSET); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(DATE) P(DATETZ) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // without zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, DATE, C); const bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } bdlt::Date mX(XX); const bdlt::Date& X = mX; bdlt::DateTz mZ(ZZ); const bdlt::DateTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, DATE == Z.localDate()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, DATE == Z.localDate()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, DATE == Z.localDate()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); } // without zone designator in parsed string -- basic { bsl::string str(DATE_ISO); u::removeCharFromString(&str, '-'); char *buffer = str.data(); const ptrdiff_t LENGTH = str.length(); if (veryVerbose) { T_ T_ P(str) } bdlt::Date mX(XX); const bdlt::Date& X = mX; bdlt::DateTz mZ(ZZ); const bdlt::DateTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, buffer, LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == Z.localDate()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == Z.localDate()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == Z.localDate()); ASSERTV(ILINE, JLINE, CLINE, 0 == Z.offset()); } // with zone designator in parsed string { const int LENGTH = Util::generateRaw(buffer, DATETZ, C); const bsl::string str(buffer, LENGTH); if (veryVerbose) { T_ T_ P(str) } bdlt::Date mX(XX); const bdlt::Date& X = mX; bdlt::DateTz mZ(ZZ); const bdlt::DateTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, buffer, LENGTH)); ASSERTV(ILINE, JLINE, CLINE, DATETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mX, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, StrView(buffer, LENGTH))); ASSERTV(ILINE, JLINE, CLINE, DATETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str())); ASSERTV(ILINE, JLINE, CLINE, DATETZ == Z); } // with zone designator in parsed string -- basic { if (tc != 0) { continue; } bsl::string str(DATE_ISO); bsl::string tzStr(ZONE_ISO); u::removeCharFromString(&str, '-'); u::removeCharFromString(&tzStr, ':'); str += tzStr; char *buffer = str.data(); const ptrdiff_t LENGTH = str.length(); if (veryVerbose) { const bsl::string STRING(buffer, LENGTH); T_ T_ P(STRING) } bdlt::Date mX(XX); const bdlt::Date& X = mX; bdlt::DateTz mZ(ZZ); const bdlt::DateTz& Z = mZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse( &mX, buffer, LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse( &mZ, buffer, LENGTH, u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATETZ == Z); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse( &mX, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mX = XX; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse( &mX, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATE == X); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, StrView(str), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATETZ == Z); mZ = ZZ; ASSERTV(ILINE, JLINE, CLINE, 0 == Util::parse(&mZ, str.c_str(), u::BASIC)); ASSERTV(ILINE, JLINE, CLINE, DATETZ == Z); } } // loop over 'CNFG_DATA' } // loop over 'ZONE_DATA' } // loop over 'DATE_DATA' { // verify 'z' is accepted bdlt::Date mX(XX); const bdlt::Date& X = mX; bdlt::DateTz mZ(ZZ); const bdlt::DateTz& Z = mZ; ASSERT(0 == Util::parse(&mX, "0001-02-03z", 11)); ASSERT(X == bdlt::Date(1, 2, 3)); ASSERT(0 == Util::parse(&mZ, "0001-02-03z", 11)); ASSERT(Z == bdlt::DateTz(bdlt::Date(1, 2, 3), 0)); } if (verbose) cout << "\nInvalid strings." << endl; { bdlt::Date mX(XX); const bdlt::Date& X = mX; bdlt::DateTz mZ(ZZ); const bdlt::DateTz& Z = mZ; const int NUM_DATE_DATA = NUM_BAD_DATE_DATA; const BadDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = BAD_DATE_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; const char *STRING = DATE_DATA[ti].d_invalid; const int LENGTH = static_cast<int>(bsl::strlen(STRING)); const bsl::string str(STRING, LENGTH); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, str.c_str())); ASSERTV(LINE, STRING, ZZ == Z); } for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int LINE = DATE_DATA[ti].d_line; bsl::string str(DATE_DATA[ti].d_invalid); u::removeCharFromString(&str, '-'); const char *STRING = str.c_str(); const ptrdiff_t LENGTH = bsl::strlen(STRING); if (veryVerbose) { T_ P_(LINE) P(str) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(str))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, str.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(str))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, str.c_str())); ASSERTV(LINE, STRING, ZZ == Z); } const int NUM_ZONE_DATA = NUM_BAD_ZONE_DATA; const BadZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = BAD_ZONE_DATA; for (int ti = 0; ti < NUM_ZONE_DATA; ++ti) { const int LINE = ZONE_DATA[ti].d_line; // Initialize with a *valid* date string, then append an // invalid zone designator. bsl::string bad("2010-08-17"); // Ensure that 'bad' is initially valid. static bool firstFlag = true; if (firstFlag) { firstFlag = false; const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Date mD(XX); const bdlt::Date& D = mD; ASSERT( 0 == Util::parse(&mD, STRING, LENGTH)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse(&mD, StrView(STRING, LENGTH))); ASSERT(XX != D); } bad.append(ZONE_DATA[ti].d_invalid); const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str())); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(STRING, LENGTH))); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str())); ASSERTV(LINE, STRING, ZZ == Z); } // repeat above loop, only 'basic' for (int ti = 0; ti < NUM_ZONE_DATA; ++ti) { const int LINE = ZONE_DATA[ti].d_line; // Initialize with a *valid* date string, then append an // invalid zone designator. bsl::string bad("20100817"); // Ensure that 'bad' is initially valid. static bool firstFlag = true; if (firstFlag) { firstFlag = false; const char *STRING = bad.data(); const ptrdiff_t LENGTH = bad.length(); bdlt::Date mD(XX); const bdlt::Date& D = mD; ASSERT( 0 == Util::parse(&mD, STRING, LENGTH, u::BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse(&mD, StrView(STRING, LENGTH), u::BASIC)); ASSERT(XX != D); mD = XX; ASSERT( 0 == Util::parse(&mD, bad.c_str(), u::BASIC)); ASSERT(XX != D); } bsl::string tz(ZONE_DATA[ti].d_invalid); u::removeCharFromString(&tz, ':'); bad += tz; const char *STRING = bad.c_str(); const ptrdiff_t LENGTH = bad.length(); if (veryVerbose) { T_ P_(LINE) P(STRING) } ASSERTV(LINE, STRING, 0 != Util::parse(&mX, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, STRING, LENGTH, u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mX, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, XX == X); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, StrView(bad), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); ASSERTV(LINE, STRING, 0 != Util::parse(&mZ, bad.c_str(), u::BASIC)); ASSERTV(LINE, STRING, ZZ == Z); } } const char *INPUT = "2013-10-23"; const ptrdiff_t LENGTH = bsl::strlen(INPUT); const StrView stringRef(INPUT, LENGTH); const StrView nullRef; bdlt::Date result; bdlt::DateTz resultTz; if (verbose) cout << "Length too short." << endl; { ASSERT(0 != Util::parse(&result, INPUT, LENGTH-1)); ASSERT(0 != Util::parse(&result, StrView(INPUT, LENGTH-1))); } if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; if (veryVerbose) cout << "\t'Invalid result'" << endl; { bdlt::Date *bad = 0; bdlt::DateTz *badTz = 0; ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( bad, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( badTz, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &result, stringRef)); ASSERT_FAIL(Util::parse( bad, stringRef)); ASSERT_PASS(Util::parse(&resultTz, stringRef)); ASSERT_FAIL(Util::parse( badTz, stringRef)); } if (veryVerbose) cout << "\t'Invalid input'" << endl; { ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_FAIL(Util::parse( &result, 0, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_FAIL(Util::parse(&resultTz, 0, LENGTH)); ASSERT_PASS(Util::parse( &result, stringRef)); ASSERT_FAIL(Util::parse( &result, nullRef)); ASSERT_PASS(Util::parse(&resultTz, stringRef)); ASSERT_FAIL(Util::parse(&resultTz, nullRef)); } if (veryVerbose) cout << "\t'Invalid length'" << endl; { ASSERT_PASS(Util::parse( &result, INPUT, LENGTH)); ASSERT_PASS(Util::parse( &result, INPUT, 0)); ASSERT_FAIL(Util::parse( &result, INPUT, -1)); ASSERT_PASS(Util::parse(&resultTz, INPUT, LENGTH)); ASSERT_PASS(Util::parse(&resultTz, INPUT, 0)); ASSERT_FAIL(Util::parse(&resultTz, INPUT, -1)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 7: { // -------------------------------------------------------------------- // GENERATE 'DatetimeTz' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 2 In a second table, specify a set of distinct 'Time' values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 3 In a third table, specify a set of distinct timezone values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 4 For each element 'R' in the cross product of the tables from P-1, //: P-2, and P-3: (C-1..5) //: //: 1 Create a 'const' 'DatetimeTz' object, 'X', from 'R'. //: //: 2 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 3 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const DatetimeTz&); // int generate(char *, int, const DatetimeTz&, const Config&); // int generate(string *, const DatetimeTz&); // int generate(string *, const DatetimeTz&, const Config&); // ostream generate(ostream&, const DatetimeTz&); // ostream generate(ostream&, const DatetimeTz&, const Config&); // int generateRaw(char *, const DatetimeTz&); // int generateRaw(char *, const DatetimeTz&, const Config&); #ifndef BDE_OMIT_INTERNAL_DEPRECATED // int generate(char *, const DatetimeTz&, int); // int generate(char *, const DatetimeTz&, int, bool useZ); // ostream generate(ostream&, const DatetimeTz&, bool useZ); // int generateRaw(char *, const DatetimeTz&, bool useZ); #endif // BDE_OMIT_INTERNAL_DEPRECATED // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "GENERATE 'DatetimeTz'" << endl << "=====================" << endl; typedef bdlt::DatetimeTz TYPE; const int OBJLEN = Util::k_DATETIMETZ_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const char *ISO8601 = DATE_DATA[ti].d_iso8601; const bdlt::Date DATE(YEAR, MONTH, DAY); const bsl::string EXPECTED_DATE(ISO8601); for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int JLINE = TIME_DATA[tj].d_line; const int HOUR = TIME_DATA[tj].d_hour; const int MIN = TIME_DATA[tj].d_min; const int SEC = TIME_DATA[tj].d_sec; const int MSEC = TIME_DATA[tj].d_msec; const int USEC = TIME_DATA[tj].d_usec; const char *ISO8601 = TIME_DATA[tj].d_iso8601; const bdlt::Time TIME(HOUR, MIN, SEC, MSEC); const bsl::string EXPECTED_TIME(ISO8601); for (int tk = 0; tk < NUM_ZONE_DATA; ++tk) { const int KLINE = ZONE_DATA[tk].d_line; const int OFFSET = ZONE_DATA[tk].d_offset; const char *ISO8601 = ZONE_DATA[tk].d_iso8601; const bsl::string EXPECTED_ZONE(ISO8601); if (TIME == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } const TYPE X(bdlt::Datetime(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC, USEC), OFFSET); const bsl::string BASE_EXPECTED( EXPECTED_DATE + 'T' + EXPECTED_TIME + EXPECTED_ZONE); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(KLINE) P_(X) P(BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETIMETZ_MAX_PRECISION); const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, JLINE, KLINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, JLINE, KLINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Swap order of 'k' and 'X' in call to 'generate'. { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp( EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } #endif // BDE_OMIT_INTERNAL_DEPRECATED } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, JLINE, KLINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, JLINE, KLINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, JLINE, KLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of // 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETIMETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Test methods taking (legacy) // 'bool useZAbbreviationForUtc'. const bool USEZ_CNFG_DATA[] = { false, true }; for (int tc = 0; tc < 2; ++tc) { const bool OMITCOLON = true; const int PRECISION = 3; const bool USECOMMA = true; const bool USEZ = USEZ_CNFG_DATA[tc]; if (veryVerbose) { T_ P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to use the complement // of 'USEZ'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, PRECISION, OMITCOLON, USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETIMETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k, USEZ)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, USEZ)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, USEZ)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'USEZ_CNFG_DATA' #endif // BDE_OMIT_INTERNAL_DEPRECATED } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' } // loop over 'DATE_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL(Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL(Util::generate(buffer, -1, X, C)); bsl::string mSB("qwerty"); bsl::string *pb = 0; ASSERT_PASS(Util::generate(&mSB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mSB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mSS("qwerty"); std::string *ps = 0; ASSERT_PASS(Util::generate(&mSS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mSS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mSP("qwerty"); std::pmr::string *pp = 0; ASSERT_PASS(Util::generate(&mSP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mSP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); #endif } if (verbose) cout << "\t'generateRaw'" << endl; { const TYPE X; char buffer[OBJLEN]; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( 0, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL(Util::generateRaw( 0, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 6: { // -------------------------------------------------------------------- // GENERATE 'TimeTz' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Time' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 2 In a second table, specify a set of distinct timezone values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 3 For each element 'R' in the cross product of the tables from P-1 //: and P-2: (C-1..5) //: //: 1 Create a 'const' 'TimeTz' object, 'X', from 'R'. //: //: 2 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 3 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const TimeTz&); // int generate(char *, int, const TimeTz&, const Config&); // int generate(string *, const TimeTz&); // int generate(string *, const TimeTz&, const Config&); // ostream generate(ostream&, const TimeTz&); // ostream generate(ostream&, const TimeTz&, const Config&); // int generateRaw(char *, const TimeTz&); // int generateRaw(char *, const TimeTz&, const Config&); #ifndef BDE_OMIT_INTERNAL_DEPRECATED // int generate(char *, const TimeTz&, int); // int generate(char *, const TimeTz&, int, bool useZ); // ostream generate(ostream&, const TimeTz&, bool useZ); // int generateRaw(char *, const TimeTz&, bool useZ); #endif // BDE_OMIT_INTERNAL_DEPRECATED // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "GENERATE 'TimeTz'" << endl << "=================" << endl; typedef bdlt::TimeTz TYPE; const int OBJLEN = Util::k_TIMETZ_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int ILINE = TIME_DATA[ti].d_line; const int HOUR = TIME_DATA[ti].d_hour; const int MIN = TIME_DATA[ti].d_min; const int SEC = TIME_DATA[ti].d_sec; const int MSEC = TIME_DATA[ti].d_msec; const int USEC = TIME_DATA[ti].d_usec; const char *ISO8601 = TIME_DATA[ti].d_iso8601; const bdlt::Time TIME(HOUR, MIN, SEC, MSEC, USEC); const bsl::string EXPECTED_TIME(ISO8601); for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; const char *ISO8601 = ZONE_DATA[tj].d_iso8601; const bsl::string EXPECTED_ZONE(ISO8601); if (TIME == bdlt::Time() && OFFSET != 0) { continue; // skip invalid compositions } const TYPE X(TIME, OFFSET); const bsl::string BASE_EXPECTED(EXPECTED_TIME + EXPECTED_ZONE); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(X) P(BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_TIMETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, JLINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, JLINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Swap order of 'k' and 'X' in call to 'generate'. { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } #endif // BDE_OMIT_INTERNAL_DEPRECATED } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, JLINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, JLINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_TIMETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Test methods taking (legacy) 'bool useZAbbreviationForUtc'. const bool USEZ_CNFG_DATA[] = { false, true }; for (int tc = 0; tc < 2; ++tc) { const bool OMITCOLON = true; const int PRECISION = 3; const bool USECOMMA = true; const bool USEZ = USEZ_CNFG_DATA[tc]; if (veryVerbose) { T_ P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to use the complement of // 'USEZ'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, PRECISION, OMITCOLON, USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_TIMETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k, USEZ)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, USEZ)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, USEZ)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'USEZ_CNFG_DATA' #endif // BDE_OMIT_INTERNAL_DEPRECATED } // loop over 'ZONE_DATA' } // loop over 'TIME_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL(Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL(Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"), *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mS("qwerty"), *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"), *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); #endif } if (verbose) cout << "\t'generateRaw'" << endl; { const TYPE X; char buffer[OBJLEN]; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( 0, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL(Util::generateRaw( 0, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 5: { // -------------------------------------------------------------------- // GENERATE 'DateTz' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 2 In a second table, specify a set of distinct timezone values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 3 For each element 'R' in the cross product of the tables from P-1 //: and P-2: (C-1..5) //: //: 1 Create a 'const' 'DateTz' object, 'X', from 'R'. //: //: 2 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 3 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const DateTz&); // int generate(char *, int, const DateTz&, const Config&); // int generate(string *, const DateTz&); // int generate(string *, const DateTz&, const Config&); // ostream generate(ostream&, const DateTz&); // ostream generate(ostream&, const DateTz&, const Config&); // int generateRaw(char *, const DateTz&); // int generateRaw(char *, const DateTz&, const Config&); #ifndef BDE_OMIT_INTERNAL_DEPRECATED // int generate(char *, const DateTz&, int); // int generate(char *, const DateTz&, int, bool useZ); // ostream generate(ostream&, const DateTz&, bool useZ); // int generateRaw(char *, const DateTz&, bool useZ); #endif // BDE_OMIT_INTERNAL_DEPRECATED // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "GENERATE 'DateTz'" << endl << "=================" << endl; typedef bdlt::DateTz TYPE; const int OBJLEN = Util::k_DATETZ_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_ZONE_DATA = NUM_DEFAULT_ZONE_DATA; const DefaultZoneDataRow (&ZONE_DATA)[NUM_ZONE_DATA] = DEFAULT_ZONE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const char *ISO8601 = DATE_DATA[ti].d_iso8601; const bdlt::Date DATE(YEAR, MONTH, DAY); const bsl::string EXPECTED_DATE(ISO8601); for (int tj = 0; tj < NUM_ZONE_DATA; ++tj) { const int JLINE = ZONE_DATA[tj].d_line; const int OFFSET = ZONE_DATA[tj].d_offset; const char *ISO8601 = ZONE_DATA[tj].d_iso8601; const bsl::string EXPECTED_ZONE(ISO8601); const TYPE X(DATE, OFFSET); const bsl::string BASE_EXPECTED(EXPECTED_DATE + EXPECTED_ZONE); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(X) P(BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, JLINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, JLINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Swap order of 'k' and 'X' in call to 'generate'. { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } #endif // BDE_OMIT_INTERNAL_DEPRECATED } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, JLINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, JLINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Test methods taking (legacy) 'bool useZAbbreviationForUtc'. const bool USEZ_CNFG_DATA[] = { false, true }; for (int tc = 0; tc < 2; ++tc) { const bool OMITCOLON = true; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = true; const bool USEZ = USEZ_CNFG_DATA[tc]; if (veryVerbose) { T_ P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to use the complement of // 'USEZ'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, PRECISION, OMITCOLON, USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETZ_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k, USEZ)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, USEZ)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, USEZ)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'USEZ_CNFG_DATA' #endif // BDE_OMIT_INTERNAL_DEPRECATED } // loop over 'ZONE_DATA' } // loop over 'DATE_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL(Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL(Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"), *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mS("qwerty"), *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"), *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); #endif } if (verbose) cout << "\t'generateRaw'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( pc, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL(Util::generateRaw( pc, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 4: { // -------------------------------------------------------------------- // GENERATE 'Datetime' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 2 In a second table, specify a set of distinct 'Time' values (one //: per row) and their corresponding ISO 8601 string representations. //: //: 3 For each element 'R' in the cross product of the tables from P-1 //: and P-2: (C-1..5) //: //: 1 Create a 'const' 'Datetime' object, 'X', from 'R'. //: //: 2 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 3 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const Datetime&); // int generate(char *, int, const Datetime&, const Config&); // int generate(string *, const Datetime&); // int generate(string *, const Datetime&, const Config&); // ostream generate(ostream&, const Datetime&); // ostream generate(ostream&, const Datetime&, const Config&); // int generateRaw(char *, const Datetime&); // int generateRaw(char *, const Datetime&, const Config&); #ifndef BDE_OMIT_INTERNAL_DEPRECATED // int generate(char *, const Datetime&, int); #endif // BDE_OMIT_INTERNAL_DEPRECATED // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "GENERATE 'Datetime'" << endl << "===================" << endl; typedef bdlt::Datetime TYPE; const int OBJLEN = Util::k_DATETIME_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const char *ISO8601 = DATE_DATA[ti].d_iso8601; const bdlt::Date DATE(YEAR, MONTH, DAY); const bsl::string EXPECTED_DATE(ISO8601); for (int tj = 0; tj < NUM_TIME_DATA; ++tj) { const int JLINE = TIME_DATA[tj].d_line; const int HOUR = TIME_DATA[tj].d_hour; const int MIN = TIME_DATA[tj].d_min; const int SEC = TIME_DATA[tj].d_sec; const int MSEC = TIME_DATA[tj].d_msec; const int USEC = TIME_DATA[tj].d_usec; const char *ISO8601 = TIME_DATA[tj].d_iso8601; const bsl::string EXPECTED_TIME(ISO8601); const TYPE X(YEAR, MONTH, DAY, HOUR, MIN, SEC, MSEC, USEC); const bsl::string BASE_EXPECTED( EXPECTED_DATE + 'T' + EXPECTED_TIME); if (veryVerbose) { T_ P_(ILINE) P_(JLINE) P_(X) P(BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETIME_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, JLINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, JLINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Swap order of 'k' and 'X' in call to 'generate'. { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } #endif // BDE_OMIT_INTERNAL_DEPRECATED } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, JLINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, JLINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, JLINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, JLINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, JLINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATETIME_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' } // loop over 'TIME_DATA' } // loop over 'DATE_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL(Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL(Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"), *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mS("qwerty"), *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"), *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); #endif } if (verbose) cout << "\t'generateRaw'" << endl; { const TYPE X; char buffer[OBJLEN]; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( 0, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL(Util::generateRaw( 0, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 3: { // -------------------------------------------------------------------- // GENERATE 'Time' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Time' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 2 For each row 'R' in the table from P-1: (C-1..5) //: //: 1 Create a 'const' 'Time' object, 'X', from 'R'. //: //: 2 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 3 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const Time&); // int generate(char *, int, const Time&, const Config&); // int generate(string *, const Time&); // int generate(string *, const Time&, const Config&); // ostream generate(ostream&, const Time&); // ostream generate(ostream&, const Time&, const Config&); // int generateRaw(char *, const Time&); // int generateRaw(char *, const Time&, const Config&); #ifndef BDE_OMIT_INTERNAL_DEPRECATED // int generate(char *, const Time&, int); #endif // BDE_OMIT_INTERNAL_DEPRECATED // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "GENERATE 'Time'" << endl << "===============" << endl; typedef bdlt::Time TYPE; const int OBJLEN = Util::k_TIME_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_TIME_DATA = NUM_DEFAULT_TIME_DATA; const DefaultTimeDataRow (&TIME_DATA)[NUM_TIME_DATA] = DEFAULT_TIME_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_TIME_DATA; ++ti) { const int ILINE = TIME_DATA[ti].d_line; const int HOUR = TIME_DATA[ti].d_hour; const int MIN = TIME_DATA[ti].d_min; const int SEC = TIME_DATA[ti].d_sec; const int MSEC = TIME_DATA[ti].d_msec; const int USEC = TIME_DATA[ti].d_usec; const char *ISO8601 = TIME_DATA[ti].d_iso8601; const TYPE X(HOUR, MIN, SEC, MSEC, USEC); const bsl::string BASE_EXPECTED(ISO8601); if (veryVerbose) { T_ P_(ILINE) P_(X) P(BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_TIME_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Swap order of 'k' and 'X' in call to 'generate'. { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } #endif // BDE_OMIT_INTERNAL_DEPRECATED } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_TIME_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' } // loop over 'TIME_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL(Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL(Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"), *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mS("qwerty"), *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"), *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); #endif } if (verbose) cout << "\t'generateRaw'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( pc, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL(Util::generateRaw( pc, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 2: { // -------------------------------------------------------------------- // GENERATE 'Date' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'Date' values (one per row) and their corresponding ISO 8601 //: string representations. //: //: 2 For each row 'R' in the table from P-1: (C-1..5) //: //: 1 Create a 'const' 'Date' object, 'X', from 'R'. //: //: 2 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 3 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const Date&); // int generate(char *, int, const Date&, const Config&); // int generate(string *, const Date&); // int generate(string *, const Date&, const Config&); // ostream generate(ostream&, const Date&); // ostream generate(ostream&, const Date&, const Config&); // int generateRaw(char *, const Date&); // int generateRaw(char *, const Date&, const Config&); #ifndef BDE_OMIT_INTERNAL_DEPRECATED // int generate(char *, const Date&, int); #endif // BDE_OMIT_INTERNAL_DEPRECATED // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "GENERATE 'Date'" << endl << "===============" << endl; typedef bdlt::Date TYPE; const int OBJLEN = Util::k_DATE_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_DATE_DATA = NUM_DEFAULT_DATE_DATA; const DefaultDateDataRow (&DATE_DATA)[NUM_DATE_DATA] = DEFAULT_DATE_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_DATE_DATA; ++ti) { const int ILINE = DATE_DATA[ti].d_line; const int YEAR = DATE_DATA[ti].d_year; const int MONTH = DATE_DATA[ti].d_month; const int DAY = DATE_DATA[ti].d_day; const char *ISO8601 = DATE_DATA[ti].d_iso8601; const TYPE X(YEAR, MONTH, DAY); const bsl::string BASE_EXPECTED(ISO8601); if (veryVerbose) { T_ P_(ILINE) P_(X) P(BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATE_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } #ifndef BDE_OMIT_INTERNAL_DEPRECATED // Swap order of 'k' and 'X' in call to 'generate'. { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, X, k)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } #endif // BDE_OMIT_INTERNAL_DEPRECATED } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_DATE_MAX_PRECISION); const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' } // loop over 'DATE_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL(Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL(Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"), *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); bsl::string mS("qwerty"), *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"), *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); #endif } if (verbose) cout << "\t'generateRaw'" << endl; { const TYPE X; char buffer[OBJLEN]; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( 0, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL(Util::generateRaw( 0, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; case 1: { // -------------------------------------------------------------------- // GENERATE 'TimeInterval' // // Concerns: //: 1 The output generated by each method has the expected format and //: contents. //: //: 2 When sufficient capacity is indicated, the method taking //: 'bufferLength' generates a null terminator. //: //: 3 Each method returns the expected value (the correct character //: count or the supplied 'ostream', depending on the return type). //: //: 4 The value of the supplied object is unchanged. //: //: 5 The configuration that is in effect, whether user-supplied or the //: process-wide default, has the desired effect on the output. //: //: 6 QoI: Asserted precondition violations are detected when enabled. // // Plan: //: 1 Using the table-driven technique, specify a set of distinct //: 'TimeInterval' values (one per row) and their corresponding ISO //: 8601 string representations. //: //: 2 For each row 'R' in the table from P-1: (C-1..5) //: //: 1 Create a 'const' 'TimeInterval' object, 'X', from 'R'. //: //: 2 Invoke the six methods under test on 'X' for all possible //: configurations. Also exercise the method taking 'bufferLength' //: for all buffer lengths in the range '[0 .. L]', where 'L' //: provides sufficient capacity for a null terminator and a few //: extra characters. For each call, verify that the generated //: output matches the string from 'R' (taking the effect of the //: configuration into account), a null terminator is appended when //: expected, and the return value is correct. (C-1..5) //: //: 3 Verify that, in appropriate build modes, defensive checks are //: triggered for invalid arguments, but not triggered for adjacent //: valid ones (using the 'BSLS_ASSERTTEST_*' macros). (C-6) // // Testing: // int generate(char *, int, const TimeInterval&); // int generate(char *, int, const TimeInterval&, const Config&); // int generate(string *, const TimeInterval&); // int generate(string *, const TimeInterval&, const Config&); // ostream generate(ostream&, const TimeInterval&); // ostream generate(ostream&, const TimeInterval&, const Config&); // int generateRaw(char *, const TimeInterval&); // int generateRaw(char *, const TimeInterval&, const Config&); // -------------------------------------------------------------------- #ifdef U_TEST_PART_01 if (verbose) cout << endl << "GENERATE 'TimeInterval'" << endl << "=======================" << endl; ASSERT(u::BASIC.basic()); ASSERT(! u::BASIC.relaxed()); ASSERT(u::RELAXED_BASIC.basic()); ASSERT(u::RELAXED_BASIC.relaxed()); typedef bsls::TimeInterval TYPE; const int OBJLEN = Util::k_TIMEINTERVAL_STRLEN; const int BUFLEN = OBJLEN + 4; char buffer[BUFLEN]; char chaste[BUFLEN]; bsl::memset(chaste, '?', BUFLEN); const int NUM_INTERVAL_DATA = NUM_DEFAULT_INTERVAL_DATA; const DefaultIntervalDataRow (&INTERVAL_DATA)[NUM_INTERVAL_DATA] = DEFAULT_INTERVAL_DATA; const int NUM_CNFG_DATA = NUM_DEFAULT_CNFG_DATA; const DefaultCnfgDataRow (&CNFG_DATA)[NUM_CNFG_DATA] = DEFAULT_CNFG_DATA; for (int ti = 0; ti < NUM_INTERVAL_DATA; ++ti) { if (!INTERVAL_DATA[ti].d_canonical) { continue; } const int ILINE = INTERVAL_DATA[ti].d_line; const bsls::Types::Int64 SEC = INTERVAL_DATA[ti].d_sec; const int USEC = INTERVAL_DATA[ti].d_usec; const char *ISO8601 = INTERVAL_DATA[ti].d_iso8601; const TYPE X(SEC, USEC); const bsl::string BASE_EXPECTED(ISO8601); if (veryVerbose) { T_ P_(ILINE) P_(X) P(BASE_EXPECTED) } for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); Config::setDefaultConfiguration(C); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_INTERVAL_MAX_PRECISION); const ptrdiff_t OUTLEN = EXPECTED.length(); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' for (int tc = 0; tc < NUM_CNFG_DATA; ++tc) { const int CLINE = CNFG_DATA[tc].d_line; const bool OMITCOLON = CNFG_DATA[tc].d_omitColon; const int PRECISION = CNFG_DATA[tc].d_precision; const bool USECOMMA = CNFG_DATA[tc].d_useComma; const bool USEZ = CNFG_DATA[tc].d_useZ; if (veryVerbose) { T_ P_(CLINE) P_(OMITCOLON) P_(PRECISION) P_(USECOMMA) P(USEZ) } Config mC; const Config& C = mC; gg(&mC, PRECISION, OMITCOLON, USECOMMA, USEZ); // Set the default configuration to the complement of 'C'. Config mDFLT; const Config& DFLT = mDFLT; gg(&mDFLT, 9 - PRECISION, !OMITCOLON, !USECOMMA, !USEZ); Config::setDefaultConfiguration(DFLT); bsl::string EXPECTED(BASE_EXPECTED); updateExpectedPerConfig(&EXPECTED, C, k_TIME_MAX_PRECISION); const int OUTLEN = static_cast<int>(EXPECTED.length()); // 'generate' taking 'bufferLength' for (int k = 0; k < BUFLEN; ++k) { bsl::memset(buffer, '?', BUFLEN); if (veryVeryVerbose) { T_ T_ cout << "Length: "; P(k) } ASSERTV(ILINE, k, OUTLEN, OUTLEN == Util::generate(buffer, k, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, k < OUTLEN ? k : OUTLEN)); if (k <= OUTLEN) { ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k, BUFLEN - k)); } else { ASSERTV(ILINE, k, OUTLEN, '\0' == buffer[OUTLEN]); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + k + 1, BUFLEN - k - 1)); } } // 'generate' to a 'bsl::string' { bsl::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } // 'generate' to an 'std::string' { std::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR // 'generate' to an 'std::pmr::string' { std::pmr::string mS("qwerty"); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generate(&mS, X, C)); ASSERTV(ILINE, EXPECTED, mS, EXPECTED == mS); if (veryVerbose) { P_(EXPECTED) P(mS); } } #endif // 'generate' to an 'ostream' { bsl::ostringstream os; ASSERTV(ILINE, &os == &Util::generate(os, X, C)); ASSERTV(ILINE, EXPECTED, os.str(), EXPECTED == os.str()); if (veryVerbose) { P_(EXPECTED) P(os.str()); } } // 'generateRaw' { bsl::memset(buffer, '?', BUFLEN); ASSERTV(ILINE, OUTLEN, OUTLEN == Util::generateRaw(buffer, X, C)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(EXPECTED.c_str(), buffer, OUTLEN)); ASSERTV(ILINE, EXPECTED, buffer, 0 == bsl::memcmp(chaste, buffer + OUTLEN, BUFLEN - OUTLEN)); } } // loop over 'CNFG_DATA' } // loop over 'TIME_DATA' if (verbose) cout << "\nNegative Testing." << endl; { bsls::AssertTestHandlerGuard hG; const Config C; if (verbose) cout << "\t'generate'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X)); ASSERT_SAFE_FAIL(Util::generate( pc, OBJLEN, X)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X)); ASSERT_SAFE_FAIL(Util::generate(buffer, -1, X)); ASSERT_SAFE_PASS(Util::generate(buffer, OBJLEN, X, C)); ASSERT_FAIL(Util::generate( pc, OBJLEN, X, C)); ASSERT_SAFE_PASS(Util::generate(buffer, 0, X, C)); ASSERT_FAIL(Util::generate(buffer, -1, X, C)); bsl::string mB("qwerty"), *pb = 0; ASSERT_PASS(Util::generate(&mB, X)); ASSERT_FAIL(Util::generate( pb, X)); ASSERT_PASS(Util::generate(&mB, X, C)); ASSERT_FAIL(Util::generate( pb, X, C)); std::string mS("qwerty"), *ps = 0; ASSERT_PASS(Util::generate(&mS, X)); ASSERT_FAIL(Util::generate( ps, X)); ASSERT_PASS(Util::generate(&mS, X, C)); ASSERT_FAIL(Util::generate( ps, X, C)); #ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR std::pmr::string mP("qwerty"), *pp = 0; ASSERT_PASS(Util::generate(&mP, X)); ASSERT_FAIL(Util::generate( pp, X)); ASSERT_PASS(Util::generate(&mP, X, C)); ASSERT_FAIL(Util::generate( pp, X, C)); #endif } if (verbose) cout << "\t'generateRaw'" << endl; { const TYPE X; char buffer[OBJLEN], *pc = 0; ASSERT_SAFE_PASS(Util::generateRaw(buffer, X)); ASSERT_SAFE_FAIL(Util::generateRaw( pc, X)); ASSERT_SAFE_PASS(Util::generateRaw(buffer, X, C)); ASSERT_FAIL(Util::generateRaw( pc, X, C)); } } #else U_TEST_CASE_SKIPPED #endif } break; default: { cerr << "WARNING: CASE `" << test << "' NOT FOUND." << endl; testStatus = -1; } } if (testStatus > 0) { cerr << "Error, non-zero test status = " << testStatus << "." << endl; } return testStatus; } // ---------------------------------------------------------------------------- // Copyright 2023 Bloomberg Finance L.P. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ----------------------------- END-OF-FILE ----------------------------------
6babc6046ec2ba7d52b84d0b925274be3b8823c5
31f70eb188d1ad6f354b3e0edee3aeec41534671
/editsalesinvoice.h
7274f196afa01ffa53f1db8f9a63d38be178dcc1
[ "MIT" ]
permissive
miantanveer/bizjust-erp
a25082916638e4fa518b1ec553c0b49203ca103b
d3291e212bf89ab6e753194127b3951afcd02548
refs/heads/master
2023-04-13T06:03:27.441353
2020-12-20T19:42:50
2020-12-20T19:42:50
null
0
0
null
null
null
null
UTF-8
C++
false
false
1,870
h
editsalesinvoice.h
#ifndef EDITSALESINVOICE_H #define EDITSALESINVOICE_H #include <QWidget> #include "dbcon.h" #include "erp.h" #include <QCompleter> #include "sch.h" namespace Ui { class EditSalesInvoice; } class EditSalesInvoice : public QWidget { Q_OBJECT public: QString loginid; DbCon conn; ERP erp; SCH sch; explicit EditSalesInvoice(QWidget *parent = 0); ~EditSalesInvoice(); private slots: void autocompleter(QString sql, QLineEdit *txt1, QLineEdit *txt2); void onItemHighlighted(const QModelIndex &index); void editingFinished(); void on_txt_customername_textEdited(); void on_txt_itemname_textEdited(); void on_txt_itemid_textChanged(); void on_txt_qty_valueChanged(); void on_txt_price_valueChanged(); void on_txt_amt_valueChanged(); void on_btn_add_clicked(); void on_btn1_clicked(); void on_txt_discount_valueChanged(); void on_txt_freight_valueChanged(); void on_txt_customerid_textChanged(); void on_dateEntrydate_userDateChanged(); void on_txt_totalamt_valueChanged(); void on_txt_totNetAmount_valueChanged(); void on_comboSales_type_currentIndexChanged();//int index void on_btn_save_clicked(); void on_search_customername_textEdited(const QString &arg1); void on_btn_next_clicked(); void on_pushButton_clicked(); void on_btn_back_clicked(); void on_pushButton_Delete_clicked(); private: Ui::EditSalesInvoice *ui; enum columns{ ITEM, ITEMID, LOCATION, LOCATIONID, QTY,UNITNAME,UNITID, PRICE, AMOUNT, BUTTON }; enum searchcolumns{ INVOICEID,INVOICENO,INVAMOUNT,INVDATE,CUSTOMER }; void checkamt(); void checktotal(); bool isValid(); void clearform(); void searchFormLoad(); void editFormLoad(); void loadInvoiceInForm(int id); }; #endif // EDITSALESINVOICE_H
f35805e8dd3040938a515d51985203fbbeb880a8
ec18d6a50219b8af4049163f0ea4566a70e07895
/Qt_Core_IM_7/main.cpp
2b7a144603018448e25123f4e7b2040d810bd830
[]
no_license
8BitsCoding/Qt_Core_IM_7
ac309051799d05d592dfdc2964c78807e5b2b786
6acee772e0e6dff1c67d0d0ee5ea455948dc2ce4
refs/heads/master
2022-03-11T03:27:27.468918
2019-11-19T11:27:57
2019-11-19T11:27:57
null
0
0
null
null
null
null
UHC
C++
false
false
616
cpp
main.cpp
#include <QtCore/QCoreApplication> #include <qset.h> #include <qdebug.h> #include <qstring.h> // QSet<T> is one of Qt's generic container classes // It stores values in an unspecified order and provides very fast lookup of the values. Internally. int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSet<QString> people; people << "Bryan" << "Heather" << "Tammy" << "chris"; people.insert("Rango"); // 자동으로 정렬이 된다. foreach(QString person, people) { qInfo() << person; } // Very fast qInfo() << "Bryan in collection " << people.contains("Bryan"); return a.exec(); }
3c7f0c37f793fa100f08cb10c608327bd1ffa59e
3cd4ce1b2b0c5dabb851106a93da502ad97deba4
/include/radar_msg_ros_conversion/sehirus_conversion.h
526629d01ad5f3ec71232d19b7f0db5d74530bc2
[]
no_license
alejandrobrazabarba/radar_msg_ros_conversion
dc7dc60425aa7391c1341322a79511f346f9e88b
cd38ee57f9065bfc90f0f1770f36f0f1f347b073
refs/heads/master
2020-04-01T17:47:56.587988
2018-10-24T09:13:48
2018-10-24T09:13:48
153,451,105
0
0
null
null
null
null
UTF-8
C++
false
false
2,431
h
sehirus_conversion.h
#ifndef SEHIRUS_CONVERSION_H #define SEHIRUS_CONVERSION_H #include <iostream> #include <boost/array.hpp> #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/asio.hpp> #include <boost/chrono.hpp> #include <pthread.h> #include "ros/ros.h" #include "radar_msg_ros_conversion/SehirusHeartbeat.h" #include "radar_msg_ros_conversion/SehirusBasicTrackReport.h" #include "radar_msg_ros_conversion/SehirusNormalTrackReport.h" #include "radar_msg_ros_conversion/SehirusExtendedTrackReport.h" typedef boost::asio::ip::udp boostUdp; typedef radar_msg_ros_conversion::SehirusHeartbeat Heartbeat; typedef radar_msg_ros_conversion::SehirusBasicTrackReport BasicTrackReport; typedef radar_msg_ros_conversion::SehirusNormalTrackReport NormalTrackReport; typedef radar_msg_ros_conversion::SehirusExtendedTrackReport ExtendedTrackReport; // Default listening ports #define HBLSTPORT 6500 // Heartbeat #define TRLSTPORT 6501 // Track Report //#define BASICTRACKREPORTSIZE 76 // bytes //#define NORMALTRACKREPORTSIZE 152 // bytes //#define EXTENDEDTRACKREPORTSIZE 188 // bytes #define FLOATSIZE 4 class SehirusConversion { public: SehirusConversion(const uint16_t &heartbeatListeningPort, const uint16_t &trackReportListeningPort); ~SehirusConversion(); void main(); private: void udp_handle_receive_heartbeat(const boost::system::error_code& error, std::size_t num_bytes); void udp_handle_receive_trackreport(const boost::system::error_code& error, std::size_t num_bytes); void basicTrackReportMsgToROS(); void normalTrackReportMsgToROS(); void extendedTrackReportMsgToROS(); ros::NodeHandle _nodeHandle; ros::Publisher _heartBeatPublisher; ros::Publisher _basicTrackReportPublisher; ros::Publisher _normalTrackReportPublisher; ros::Publisher _extendedTrackReportPublisher; radar_msg_ros_conversion::SehirusHeartbeat _heartbeatMsg; radar_msg_ros_conversion::SehirusBasicTrackReport _basicTrackReportMsg; radar_msg_ros_conversion::SehirusNormalTrackReport _normalTrackReportMsg; radar_msg_ros_conversion::SehirusExtendedTrackReport _extendedTrackReportMsg; //boost::array<uint8_t, 1> _sendBuf; boost::array<uint8_t, 72> _heartbeatRecvBuf; boost::array<uint8_t, 188> _trackReportRecvBuf; boost::asio::io_service _io_service; boostUdp::endpoint _server_endpoint; boostUdp::socket _heartbeatSocket; boostUdp::socket _trackReportSocket; }; #endif /* SEHIRUS_CONVERSION_H */
5eefe751869ad079077dd897c2f55bf0a88afa3a
89a323a74fbf8cba16a878cfbd00418dbc73152e
/lap trinh c/BaiTap13C.cpp
60270a6c34a157091a3624190b8807cf45ffbbb6
[]
no_license
nquang19it3/Cristiano
e15ea2164c6f23fc49209eecfacff6d1c4b62c31
81fa03a9135e5e727bddd823e01359a9a12af6ec
refs/heads/master
2020-09-08T22:25:36.754809
2019-11-29T03:46:16
2019-11-29T03:46:16
221,260,097
0
0
null
null
null
null
UTF-8
C++
false
false
860
cpp
BaiTap13C.cpp
#include<stdio.h> #include<conio.h> main() { int i,j,m,n; int a[50][50]; printf("nhap so hang m="); scanf("%d",&m); printf("nhap so cot n="); scanf("%d",&n); printf("nhap vao ma tran:\n"); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { printf("Nhap a[%d][%d]=",i,j); scanf("%d",&a[i][j]); } printf("\n"); } printf("ma tran vua nhap la:\n"); for(i=1;i<=m;i++) { for(j=1;j<=n;j++) { printf("%d ",a[i][j]); } printf("\n"); } int count=0; int x; printf("Nhap so muon kiem tra:"); scanf("%d",&x); for(int i=1;i<=m;i++) { for(int j=1;j<=n;j++) { if(a[i][j]==x) { count++; printf("\ntrung o vi tri a[%d][%d]",i,j); } } } printf("\nCo %d phan tu trung voi %d",count,x); }
389988940e8aa2519953fe69e3dc103315d105ed
5a82ac1cefcf56f77368b2cf523a5e7832d74d93
/src/srcinput/XYZfile.h
9bf0a5a395956313c528e60432753b7d19d18173
[]
no_license
scharlton2/wphast3
a1b225955af8a662dfc487650a140a70f3b44705
23a334f0693ebc42ca914a7b4e17cd11875cc025
refs/heads/master
2023-08-27T18:51:33.531066
2021-10-26T21:31:41
2021-10-26T21:31:41
null
0
0
null
null
null
null
UTF-8
C++
false
false
543
h
XYZfile.h
#if !defined(XYZFILE_H_INCLUDED) #define XYZFILE_H_INCLUDED #include "Filedata.h" #include <string> #include <vector> class Point; class XYZfile:public Filedata { public: XYZfile(void); XYZfile(std::string filename, PHAST_Transform::COORDINATE_SYSTEM cs); bool Make_polygons(int field, PHAST_polygon & polygons); int Get_columns(void) { return this->columns; }; void Set_columns(int i) { this->columns = i; }; public: virtual ~ XYZfile(void); protected: // data int columns; }; #endif // !defined(XYZFILE_H_INCLUDED)
e48db71b017f973fc6e3096636c577400ac60928
b5949adb96586fdf7109dbe27465b4caea5f4a0d
/lib/output_system/include/exception.h
bc8f8a4f51d1d2f7e262d0f5cf8679de0b99291a
[ "MIT" ]
permissive
buzyaba/SimEngine
79c240b7fa2f8d5555e939f5ee3327ec3a9b2b3c
e5469f927154de43ea52ad74c0ca4a0af9a7b721
refs/heads/master
2021-06-23T02:04:04.744298
2021-05-15T16:48:54
2021-05-15T16:50:46
216,178,505
5
2
MIT
2021-05-15T16:47:25
2019-10-19T09:07:30
C++
UTF-8
C++
false
false
2,265
h
exception.h
///////////////////////////////////////////////////////////////////////////// // // // LOBACHEVSKY STATE UNIVERSITY OF NIZHNY NOVGOROD // // // // Copyright (c) 2015 by UNN. // // All Rights Reserved. // // // // File: exception.h // // // // Purpose: Header file for exception handling class // // // // Author(s): Sysoyev A. // // // ///////////////////////////////////////////////////////////////////////////// #ifndef __EXCEPTION_H__ #define __EXCEPTION_H__ #include "messages.h" // ------------------------------------------------------------------------------------------------ class TException { private: char *File; int Line; char *Function; char *Description; public: TException(const char *_File, int _Line, const char *_Function, const char *_Description); TException(const TException &e); ~TException(); const char* GetFile() const; int GetLine() const; const char* GetFunction() const; const char* GetDescription() const; void PrintToFile(const char* fileName = "") const; void PrintToConsole() const; void Print(const char* fileName = "") const; }; // ------------------------------------------------------------------------------------------------ void Unexpected(); // ------------------------------------------------------------------------------------------------ void Terminate(); #define EXCEPTION(msg) TException(__FILE__, __LINE__, __FUNCTION__, msg) #endif // __EXCEPTION_H__ // - end of file ----------------------------------------------------------------------------------
f96456fddc5de9e858890cbb68e974d6465ce861
e6afebf31c0ff4e70cd3ff3330e244539574cc83
/ADTs/Stack.h
71be442f8bcf0483bd2a10ab86fc346e21e5a249
[]
no_license
Akinloluwa-Adedijo/CMPT125
724f357fdc3191b862cf0fa1fc060a9c0a205a76
58f5a41b29b83b4262dfd411e005ff147312a13b
refs/heads/main
2023-07-13T00:08:01.791785
2021-08-18T01:49:53
2021-08-18T01:49:53
397,416,651
0
0
null
null
null
null
UTF-8
C++
false
false
2,062
h
Stack.h
// Stack.h #include <string> #include <vector> using namespace std; class Stack { public: virtual ~Stack() { } // always include a virtual destructor in a base class // Pre-condition: // none // Post-condition: // returns true if the stack is empty, and false otherwise virtual bool is_empty() const = 0; // Pre-condition: // none // Post-condition: // returns the number of elements in this stack virtual int size() const = 0; // Pre-condition: // none // Post-condition: // puts x on the top of the stack virtual void push(const string& x) = 0; // Pre-condition: // none // Post-condition: // pushes all the elements of v onto the stack; first v[0] is pushed, // then v[1], etc. virtual void push(const vector<string>& v) = 0; // Pre-condition: // none // Post-condition: // if x occurs anywhere on the stack, then does nothing; otherwise, // pushes x onto the stack virtual void push_new(const string& s) = 0; // Pre-condition: // !is_empty() // Post-condition: // removes and returns the top element of the stack virtual string pop() = 0; // Pre-condition: // none // Post-condition: // if n <= 0, an empty vector is returned; otherwise, pops the first n items // off the stack and returns them in a vector such that the first item of the vector // is the top of the stack, the second item of the vector is the second item of the /// stack, and so on; if n > size(), then all items are popped and returned virtual vector<string> pop(int n) = 0; // Pre-condition: // none // Post-condition: // pops all elements from the stack virtual void pop_all() { while (!is_empty()) pop(); } // Pre-condition: // !is_empty() // Post-condition: // returns a copy of the top element of the stack (without removing it) virtual string peek() const = 0; }; // class Stack
06ab9fbc6e985607aae6bec2657b44669f6bf839
38cdd8fe67239909721c84199fc2132400830d40
/torch.cpp
24e221d620c52e252b7635f8e526ed493633cb39
[]
no_license
YogaVicky/Codeforces-Solutions
5cf38fb431456799d303fc38957c49b16f6696dc
5e8c1a83829db9c5e226bc2984630e4cc617d80e
refs/heads/master
2022-05-12T13:19:15.324034
2022-03-24T13:59:53
2022-03-24T13:59:53
252,093,118
4
0
null
null
null
null
UTF-8
C++
false
false
368
cpp
torch.cpp
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mod 1000000007 #define mp make_pair void solve(){ ll n,i,m,k; ll tot = 0; cin>>n>>m>>k; tot+=k; ll s = (k*m) + k - 1; if(s%(n-1)==0) tot+=s/(n-1); else tot+=s/(n-1) + 1; cout<<tot<<endl; } int main(){ ll t; cin>>t; while(t--){ solve(); } return 0; }
b4e2a74def1a21bb612cdc9a1a62fcf8fb79d08b
40866fe4602ebd84001aee587cdb8a73f7203b4b
/python_indentation.cpp
2b06709384114d108d25751b3398756e91bfead5
[]
no_license
kaushalmahi12/DS_ALGO
6652eda8054fdf0d425bcd178b0c4c4eba5efdf7
949b6be3d308aecdc7f562d36d9f4ac167ad7324
refs/heads/master
2020-05-02T13:24:41.670356
2019-08-13T16:44:28
2019-08-13T16:44:28
177,983,344
0
0
null
null
null
null
UTF-8
C++
false
false
810
cpp
python_indentation.cpp
#include<cstring> #include<iostream> using namespace std; const int mx = 5 * 1e3 + 2; const int mod = 1e9 + 7; int dp[mx][mx]; int a[mx], n; int f(int pos, int nest) { if(nest < 0){ return 0; } if(pos > n){ return 1; } if(dp[pos][nest] != -1){ return dp[pos][nest]; } int res = f(pos , nest - 1); if(a[pos-1] == 0){ res += f(pos + 1 , nest); } else{ res += f(pos + 1 , nest + 1); res -= f(pos + 1 , nest); } if(res >= mod){ res -= mod; } if(res < 0){ res += mod; } return dp[pos][nest] = res; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i=0; i<n; i++) { char c; cin >> c; if (c=='f') a[i] = 1; else a[i] = 0; } memset(dp, -1, sizeof(dp)); cout << f(1, 0) << "\n"; return 0; }
b056452aa64394db05d891130dec9ec262b08c33
3577505f1fc8b56a8ab14038bef04907b3cbf32e
/source/Communicators/Communicator_utils.h
517412ed053723ba50f232bda4661c93fa2eb3fd
[ "MIT" ]
permissive
stjordanis/smarties
d6cbe82126e0a2568ec28718802063f272fd30e7
edaef91bffdb4846c43de860f3d77cba1a016fd6
refs/heads/master
2020-07-03T06:34:58.660905
2019-05-20T10:27:22
2019-05-20T10:27:22
null
0
0
null
null
null
null
UTF-8
C++
false
false
2,106
h
Communicator_utils.h
// // smarties // Copyright (c) 2018 CSE-Lab, ETH Zurich, Switzerland. All rights reserved. // Distributed under the terms of the MIT license. // // Created by Guido Novati (novatig@ethz.ch) and Panagiotis Hadjidoukas. // #pragma once #include <iostream> #include <cmath> #include <cassert> #include <dirent.h> #include <netdb.h> #include <unistd.h> #include <signal.h> #include <sys/stat.h> #include <sys/time.h> #include <fcntl.h> #include <limits> inline void intToDoublePtr(const int i, double*const ptr) { assert(i>=0); *ptr = (double)i+0.1; } inline int doublePtrToInt(const double*const ptr) { return (int)*ptr; } inline double* _alloc(const int size) { double* ret = (double*) malloc(size); memset(ret, 0, size); return ret; } inline void _dealloc(double* ptr) { if(ptr not_eq nullptr) { free(ptr); ptr=nullptr; } } inline void launch_exec(const std::string exec, const int socket_id) { printf("About to exec %s.... \n",exec.c_str()); const int res = execlp(exec.c_str(), exec.c_str(), std::to_string(socket_id).c_str(), NULL); //int res = execvp(*largv, largv); if (res < 0) fprintf(stderr,"Unable to exec file '%s'!\n", exec.c_str()); } inline int redirect_stdout_stderr() { fflush(0); char output[256]; sprintf(output, "output"); int fd = open(output, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); dup2(fd, 1); // make stdout go to file dup2(fd, 2); // make stderr go to file close(fd); // fd no longer needed return fd; } int recv_all(int fd, void *buffer, unsigned int size); int send_all(int fd, void *buffer, unsigned int size); int parse2(char *line, char **argv); int cp(const char *from, const char *to); int copy_from_dir(const std::string name); void sockRecv(int fd, double*const data, const int size); void sockSend(int fd, double*const data, const int size); #ifdef MPI_VERSION inline int getRank(const MPI_Comm comm) { int rank; MPI_Comm_rank(comm, &rank); return rank; } inline int getSize(const MPI_Comm comm) { int size; MPI_Comm_size(comm, &size); return size; } #endif
8c2de95dc6778410771005e41b853823c160cfd9
833323a57441946ae8bdf96ea4dc9eebea4003d8
/src/Async/AnyEventTargetImpl.h
c75f6929064aa041cc2b9d95e08060fd41e19b17
[]
no_license
slimek/Caramel
0131b272f5ed230db6f2c0a3d7e5001a8f75b3d1
bc7cf122fd2cbb74a58f58095dbd3a2c3b456ff2
refs/heads/master
2021-01-23T08:39:05.509747
2015-11-05T12:51:15
2015-11-05T12:51:15
13,272,701
0
0
null
null
null
null
UTF-8
C++
false
false
1,389
h
AnyEventTargetImpl.h
// Caramel C++ Library - Async Facility - Any Event Target Private Header #ifndef __CARAMEL_ASYNC_ANY_EVENT_TARGET_IMPL_H #define __CARAMEL_ASYNC_ANY_EVENT_TARGET_IMPL_H #pragma once #include <Caramel/Setup/CaramelDefs.h> #include <Caramel/Async/AnyEvent.h> #include <Caramel/Thread/MutexLocks.h> #include <mutex> namespace Caramel { /////////////////////////////////////////////////////////////////////////////// // // Any Event Target // class AnyEventTargetImpl { public: AnyEventTargetImpl(); virtual ~AnyEventTargetImpl() {} virtual void Send( const AnyEvent& evt, Uint age ) = 0; /// Target Destroyed /// // The owner should call this function in destructor. // - ATTENTION: If the owner is copyable, you may need additional reference counting. void Destroy(); Bool IsDestroyed() const { return m_destroyed; } /// Reference Aging /// void IncrementAge(); // The lock is not locked if the age doesn't equal. UniqueLock CompareAge( Uint age ) const; Uint GetAge() const { return m_age; } private: Bool m_destroyed; Uint m_age; mutable std::mutex m_ageMutex; }; typedef std::shared_ptr< AnyEventTargetImpl > AnyEventTargetPtr; /////////////////////////////////////////////////////////////////////////////// } // namespace Caramel #endif // __CARAMEL_ASYNC_ANY_EVENT_TARGET_IMPL_H
8ec58dfb55641363e4badc3e7c55078c9a4202ae
8f14f3335d916ba97c9d1967c1079d453a13bea6
/lib/command/command.h
a370ed40930cef8a3c6e4a0668167f6be1b17afc
[]
no_license
Solitry/mediaplayer_for_srt
3f9a313105d9811f8e638d77170584fb2ee97fd6
7fe6df3ee9eb9f74c2a56886e966e6ba1f75e42f
refs/heads/master
2021-01-21T05:23:14.930292
2015-07-31T03:06:04
2015-07-31T03:06:04
39,983,283
0
0
null
2015-07-31T02:49:29
2015-07-31T02:49:29
null
UTF-8
C++
false
false
34
h
command.h
#pragma once class Command { };
5e05e9415eba2a03c168e07788a9b018f04f6e34
9216eb383e166c8265790c2d6cc3bc5d9e23f11f
/src/OLD/Protocols.old/HTTP/Messages.h++
938d225b6b385594b7fa089851a50637e17842a4
[]
no_license
phatcabbage/EDNAS
fca7d88b092fb008847c335bae27eb7352eca6d6
90f57129c1e584acbf818e75efbb08b462097de8
refs/heads/master
2016-09-06T18:06:03.539627
2011-12-07T02:31:44
2011-12-07T02:31:44
2,929,741
1
0
null
null
null
null
UTF-8
C++
false
false
191
Messages.h++
#ifndef PROTOCOLS__HTTP__MESSAGES_HXX__ #define PROTOCOLS__HTTP__MESSAGES_HXX__ #include "./RequestMessages.h++" #include "./ResponseMessages.h++" #endif // PROTOCOLS__HTTP__MESSAGES_HXX__
8a3a06c618ff8031ea9a2c9005b81df9fbfd0e37
7c58dc6ece33475300b5766b18a324617da6d578
/source/Game.Desktop.OpenGL/ActionSpriteDraw.h
9010faf009149005886105181f351d656c6ab007
[]
no_license
ash9991win/VVVVVV
6301322380e1be3aee9ed2be74c30604e715d85a
96c2eea67302678d120e2cd1c0ce9c18b5435823
refs/heads/master
2021-07-25T02:33:59.661244
2017-11-05T03:22:25
2017-11-05T03:22:25
109,548,772
0
0
null
null
null
null
UTF-8
C++
false
false
722
h
ActionSpriteDraw.h
#pragma once #include "Action.h" using namespace LibraryDesktop; class ActionSpriteDraw final : public Action { public: ///Default constructor for this object ActionSpriteDraw(); ActionSpriteDraw(const ActionSpriteDraw& rhs) = delete; ActionSpriteDraw& operator=(const ActionSpriteDraw& rhs) = delete; ///Default destructor for this object virtual ~ActionSpriteDraw() = default; /** @brief This action updates and draws a sprite, using the entity that this action is contained in * @param worldState Current state of the game's affairs. */ virtual void Update(class WorldState& worldState) override; RTTI_DECLARATIONS(ActionSpriteDraw, Action) }; ConcreteFactory(RTTI, ActionSpriteDraw);
387b89fb32faf38fdc9c1d6a6a6d60cc72324182
260e5dec446d12a7dd3f32e331c1fde8157e5cea
/Indi/SDK/Indi_ItemContainer_BP_functions.cpp
25326a61fc038177a856b2acec9ee3babba82401
[]
no_license
jfmherokiller/TheOuterWorldsSdkDump
6e140fde4fcd1cade94ce0d7ea69f8a3f769e1c0
18a8c6b1f5d87bb1ad4334be4a9f22c52897f640
refs/heads/main
2023-08-30T09:27:17.723265
2021-09-17T00:24:52
2021-09-17T00:24:52
407,437,218
0
0
null
null
null
null
UTF-8
C++
false
false
6,163
cpp
Indi_ItemContainer_BP_functions.cpp
// TheOuterWorlds SDK #ifdef _MSC_VER #pragma pack(push, 0x8) #endif #include "Indi_ItemContainer_BP_parameters.hpp" namespace SDK { //--------------------------------------------------------------------------- //Functions //--------------------------------------------------------------------------- // Function ItemContainer_BP.ItemContainer_BP_C.OnOutro // () // Parameters: // struct FScriptDelegate* AnimationCompleteCallback (ConstParm, BlueprintVisible, BlueprintReadOnly, Parm, OutParm, ZeroConstructor, ReferenceParm) // bool ReturnValue (Parm, OutParm, ZeroConstructor, ReturnParm, IsPlainOldData) bool UItemContainer_BP_C::OnOutro(struct FScriptDelegate* AnimationCompleteCallback) { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.OnOutro"); UItemContainer_BP_C_OnOutro_Params params; params.AnimationCompleteCallback = AnimationCompleteCallback; auto flags = fn->FunctionFlags; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; return params.ReturnValue; } // Function ItemContainer_BP.ItemContainer_BP_C.OnIntro // () // Parameters: // struct FScriptDelegate* AnimationCompleteCallback (ConstParm, BlueprintVisible, BlueprintReadOnly, Parm, OutParm, ZeroConstructor, ReferenceParm) // bool ReturnValue (Parm, OutParm, ZeroConstructor, ReturnParm, IsPlainOldData) bool UItemContainer_BP_C::OnIntro(struct FScriptDelegate* AnimationCompleteCallback) { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.OnIntro"); UItemContainer_BP_C_OnIntro_Params params; params.AnimationCompleteCallback = AnimationCompleteCallback; auto flags = fn->FunctionFlags; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; return params.ReturnValue; } // Function ItemContainer_BP.ItemContainer_BP_C.Construct // (Final, RequiredAPI, BlueprintAuthorityOnly, BlueprintCosmetic, Net, NetReliable, NetRequest, Exec, Native, Event, NetResponse, Static, NetMulticast) void UItemContainer_BP_C::STATIC_Construct() { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.Construct"); UItemContainer_BP_C_Construct_Params params; auto flags = fn->FunctionFlags; fn->FunctionFlags |= 0x400; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } // Function ItemContainer_BP.ItemContainer_BP_C.OnCancelShutdown // (Final, RequiredAPI, BlueprintAuthorityOnly, BlueprintCosmetic, Net, NetReliable, NetRequest, Exec, Native, Event, NetResponse, Static, NetMulticast) void UItemContainer_BP_C::STATIC_OnCancelShutdown() { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.OnCancelShutdown"); UItemContainer_BP_C_OnCancelShutdown_Params params; auto flags = fn->FunctionFlags; fn->FunctionFlags |= 0x400; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } // Function ItemContainer_BP.ItemContainer_BP_C.ShowContainer // (Final, RequiredAPI, BlueprintAuthorityOnly, BlueprintCosmetic, Net, NetReliable, NetRequest, Exec, Native, Event, NetResponse, Static, NetMulticast) void UItemContainer_BP_C::STATIC_ShowContainer() { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.ShowContainer"); UItemContainer_BP_C_ShowContainer_Params params; auto flags = fn->FunctionFlags; fn->FunctionFlags |= 0x400; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } // Function ItemContainer_BP.ItemContainer_BP_C.HideContainer // (Final, RequiredAPI, BlueprintAuthorityOnly, BlueprintCosmetic, Net, NetReliable, NetRequest, Exec, Native, Event, NetResponse, Static, NetMulticast) void UItemContainer_BP_C::STATIC_HideContainer() { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.HideContainer"); UItemContainer_BP_C_HideContainer_Params params; auto flags = fn->FunctionFlags; fn->FunctionFlags |= 0x400; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } // Function ItemContainer_BP.ItemContainer_BP_C.OnIntroStart // (Final, RequiredAPI, BlueprintAuthorityOnly, BlueprintCosmetic, Net, NetReliable, NetRequest, Exec, Native, Event, NetResponse, Static, NetMulticast) void UItemContainer_BP_C::STATIC_OnIntroStart() { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.OnIntroStart"); UItemContainer_BP_C_OnIntroStart_Params params; auto flags = fn->FunctionFlags; fn->FunctionFlags |= 0x400; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } // Function ItemContainer_BP.ItemContainer_BP_C.OnOutroEnd // (Final, RequiredAPI, BlueprintAuthorityOnly, BlueprintCosmetic, Net, NetReliable, NetRequest, Exec, Native, Event, NetResponse, Static, NetMulticast) void UItemContainer_BP_C::STATIC_OnOutroEnd() { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.OnOutroEnd"); UItemContainer_BP_C_OnOutroEnd_Params params; auto flags = fn->FunctionFlags; fn->FunctionFlags |= 0x400; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } // Function ItemContainer_BP.ItemContainer_BP_C.ExecuteUbergraph_ItemContainer_BP // (Final, RequiredAPI, BlueprintAuthorityOnly, BlueprintCosmetic, Net, NetReliable, NetRequest, Exec, Native, Event, NetResponse, Static, NetMulticast) // Parameters: // int EntryPoint (BlueprintVisible, BlueprintReadOnly, Parm, ZeroConstructor, IsPlainOldData) void UItemContainer_BP_C::STATIC_ExecuteUbergraph_ItemContainer_BP(int EntryPoint) { static auto fn = UObject::FindObject<UFunction>("Function ItemContainer_BP.ItemContainer_BP_C.ExecuteUbergraph_ItemContainer_BP"); UItemContainer_BP_C_ExecuteUbergraph_ItemContainer_BP_Params params; params.EntryPoint = EntryPoint; auto flags = fn->FunctionFlags; fn->FunctionFlags |= 0x400; UObject::ProcessEvent(fn, &params); fn->FunctionFlags = flags; } } #ifdef _MSC_VER #pragma pack(pop) #endif
b89747d95004671b7ec59a628a79dbb8291cdb9e
abbb1e132b3d339ba2173129085f252e2f3311dc
/inference-engine/thirdparty/movidius/tests/XLink/cases/XLink_specific_cases.hpp
4638dd3929707a84b2851c5b3d4d227b98d688ad
[ "Apache-2.0" ]
permissive
0xF6/openvino
56cce18f1eb448e25053fd364bcbc1da9f34debc
2e6c95f389b195f6d3ff8597147d1f817433cfb3
refs/heads/master
2022-12-24T02:49:56.686062
2020-09-22T16:05:34
2020-09-22T16:05:34
297,745,570
2
0
Apache-2.0
2020-09-22T19:03:06
2020-09-22T19:03:04
null
UTF-8
C++
false
false
915
hpp
XLink_specific_cases.hpp
// Copyright (C) 2018-2019 Intel Corporation // SPDX-License-Identifier: Apache-2.0 // #pragma once #include "XLink_common_cases.hpp" //------------------------------------------------------------------------------ // class XLinkBootUSBTests //------------------------------------------------------------------------------ class XLinkBootUSBTests : public XLinkTests {}; //------------------------------------------------------------------------------ // class XLinkFindFirstSuitableDeviceUSBTests //------------------------------------------------------------------------------ class XLinkFindFirstSuitableDeviceUSBTests : public XLinkTests {}; //------------------------------------------------------------------------------ // class XLinkFindPCIEDeviceTests //------------------------------------------------------------------------------ class XLinkPCIEDeviceTests: public XLinkTests {};
ee4ada2dae78aed17f3f5a71c01e854c47bf1f9d
593ebdc02ada39326776d212a08f9847e73300ad
/constrained3dPositioning.cpp
14a9f85da76ec4aae7bca8e79f991cff40ff16d5
[]
no_license
ysyangntut/CvimGui
316ca7e9a36a1217a09a46c75818a46fba0b0673
222d98c7201f86914e4e070ee9c40d7a35ab6e13
refs/heads/master
2023-02-26T18:48:58.650083
2021-02-09T06:36:33
2021-02-09T06:36:33
333,788,372
0
0
null
null
null
null
UTF-8
C++
false
false
17,137
cpp
constrained3dPositioning.cpp
#include <iostream> using namespace std; #include "opencv2/core/core.hpp" #include "opencv2/calib3d.hpp" #include "opencv2/imgproc.hpp" class PlaneConstrainProjectionCostFunction :public cv::MinProblemSolver::Function { public: // called by optimization double calc(const double* x) const { double dx, dy, err; cv::Mat trial3d(1, 1, CV_64FC3), trial2d(1, 1, CV_64FC2); trial3d.at<cv::Point3d>(0, 0).x = xc[0] + x[0] * xcVec1[0] + x[1] * xcVec2[0]; trial3d.at<cv::Point3d>(0, 0).y = xc[1] + x[0] * xcVec1[1] + x[1] * xcVec2[1]; trial3d.at<cv::Point3d>(0, 0).z = xc[2] + x[0] * xcVec1[2] + x[1] * xcVec2[2]; cv::projectPoints(trial3d, rvec, tvec, camMat, disVec, trial2d); dx = trial2d.at<cv::Point2d>(0, 0).x - imgPoint[0]; dy = trial2d.at<cv::Point2d>(0, 0).y - imgPoint[1]; // cout << "Triai point: " << trial3d << endl; // cout << "Proj 2d: " << trial2d << endl; err = dx * dx + dy * dy; return err; } virtual int getDims() const { return 2; } // setting cv::Mat camMat; cv::Mat disVec; cv::Mat rvec; cv::Mat tvec; double imgPoint[2]; double xc[3]; double xcVec1[3]; double xcVec2[3]; }; int plane_constrained3dPositioning( const cv::Mat & camMat, // 3x3 camera matrix const cv::Mat & disVec, // 4x1 or 5x1 (or Nx1) distortion coefficients const cv::Mat & rmat, // 3x3 Rotation matrix or 3x1 or 1x3 vector of this camera (wrt global coord.). const cv::Mat & tvec, // 3x1 or 1x3 Translation vector of the camera. const cv::Mat & imgPoints, // Nx1 2-channel image points on photo. N is number of points to track. const cv::Mat & xc, // Nx1 3-channel constraining points, which define surfaces const cv::Mat & xcVec1, // Nx1 3-channel vector 1 of each tracking point, which define surfaces const cv::Mat & xcVec2, // Nx1 3-channel vector 2 of each tracking point, which define surfaces cv::Mat & xp // Nx1 3-channel positioned points, will be on the surface ) { int ret = 0; // check if (camMat.cols != 3 || camMat.rows != 3) { cerr << "plane_constrained3dPositioning: camMat has wrong size " << camMat.rows << "x" << camMat.cols << endl; return -1; } if (disVec.cols != 1 && disVec.rows != 1) { cerr << "plane_constrained3dPositioning: disVec has wrong size " << disVec.rows << "x" << disVec.cols << endl; return -1; } if (rmat.cols * rmat.rows != 3 && !(rmat.cols == 3 && rmat.rows == 3)) { cerr << "plane_constrained3dPositioning: rmat has wrong size " << rmat.rows << "x" << rmat.cols << endl; return -1; } if (tvec.cols * tvec.rows != 3) { cerr << "plane_constrained3dPositioning: tvec has wrong size " << tvec.rows << "x" << tvec.cols << endl; return -1; } if (imgPoints.cols != 1 || imgPoints.rows < 1) { cerr << "plane_constrained3dPositioning: imgPoints has wrong size " << imgPoints.rows << "x" << imgPoints.cols << endl; return -1; } if (imgPoints.type() != CV_32FC2) { cerr << "plane_constrained3dPositioning: imgPoints has wrong type (should be CV_32FC2 but) " << imgPoints.type() << endl; } if (xc.cols != 1 || xc.rows < 1) { cerr << "plane_constrained3dPositioning: xc has wrong size " << xc.rows << "x" << xc.cols << endl; return -1; } if (xc.type() != CV_64FC3) { cerr << "plane_constrained3dPositioning: xc has wrong type (should be CV_64FC3 but) " << xc.type() << endl; } if (xcVec1.cols != 1 || xcVec1.rows < 1) { cerr << "plane_constrained3dPositioning: xcVec1 has wrong size " << xcVec1.rows << "x" << xcVec1.cols << endl; return -1; } if (xcVec1.type() != CV_64FC3) { cerr << "plane_constrained3dPositioning: xcVec1 has wrong type (should be CV_64FC3 but) " << xcVec1.type() << endl; } if (xcVec2.cols != 1 || xcVec2.rows < 1) { cerr << "plane_constrained3dPositioning: xcVec2 has wrong size " << xcVec2.rows << "x" << xcVec2.cols << endl; return -1; } if (xcVec2.type() != CV_64FC3) { cerr << "plane_constrained3dPositioning: xcVec2 has wrong type (should be CV_64FC3 but) " << xcVec2.type() << endl; } if (xp.cols != 1 || xp.rows < 1) { xp = cv::Mat::zeros(xcVec2.rows, 1, CV_64FC3); } if (xp.type() != CV_64FC3) { xp = cv::Mat::zeros(xcVec2.rows, 1, CV_64FC3); } if (imgPoints.rows != xc.rows || xc.rows != xcVec1.rows || xcVec1.rows != xcVec2.rows && xcVec2.rows != xp.rows) { cerr << "plane_constrained3dPositioning: imgPoints/xc/xcVec1/xcVec2/xp do not have consistent # of rows: " << imgPoints.rows << " " << xc.rows << " " << xcVec1.rows << " " << xcVec2.rows << " " << xp.rows << endl; return -1; } int nPoint = imgPoints.rows; // cost function PlaneConstrainProjectionCostFunction * costFunc = new PlaneConstrainProjectionCostFunction; camMat.copyTo(costFunc->camMat); disVec.copyTo(costFunc->disVec); tvec.copyTo(costFunc->tvec); cv::Mat rvec(3, 1, CV_64F); if (rmat.cols == 3 && rmat.rows == 3) { cv::Rodrigues(rmat, rvec); rvec.copyTo(costFunc->rvec); } else { rmat.copyTo(costFunc->rvec); } // cout << "camMat: \n" << camMat << endl; // cout << "disVec: \n" << disVec << endl; // cout << "rvec: \n" << rmat << endl; // cout << "tvec: \n" << tvec << endl; // cout << "imgPoints: \n" << imgPoints << endl; // cout << "xc: \n" << xc << endl; // cout << "xcVec1: \n" << xcVec1 << endl; // cout << "xcVec2: \n" << xcVec2 << endl; // cout << "xp: \n" << xp << endl; // Solver cv::Ptr<cv::MinProblemSolver::Function> costFuncPtr(costFunc); // cv::Ptr<cv::ConjGradSolver> mySolver = cv::ConjGradSolver::create(); cv::Ptr<cv::DownhillSolver> mySolver = cv::DownhillSolver::create(); mySolver->setInitStep(10 * cv::Mat::ones(1, 2, CV_64F)); mySolver->setFunction(costFuncPtr); // Positioning for (int i = 0; i < nPoint; i++) { // set cost function object costFunc->imgPoint[0] = imgPoints.at<cv::Point2f>(i, 0).x; costFunc->imgPoint[1] = imgPoints.at<cv::Point2f>(i, 0).y; costFunc->xc[0] = xc.at<cv::Point3d>(i, 0).x; costFunc->xc[1] = xc.at<cv::Point3d>(i, 0).y; costFunc->xc[2] = xc.at<cv::Point3d>(i, 0).z; costFunc->xcVec1[0] = xcVec1.at<cv::Point3d>(i, 0).x; costFunc->xcVec1[1] = xcVec1.at<cv::Point3d>(i, 0).y; costFunc->xcVec1[2] = xcVec1.at<cv::Point3d>(i, 0).z; costFunc->xcVec2[0] = xcVec2.at<cv::Point3d>(i, 0).x; costFunc->xcVec2[1] = xcVec2.at<cv::Point3d>(i, 0).y; costFunc->xcVec2[2] = xcVec2.at<cv::Point3d>(i, 0).z; // solve cv::Mat dx = cv::Mat::zeros(2, 1, CV_64F); // cout << "Before minimization\n"; cv::TermCriteria criteria = cv::TermCriteria( cv::TermCriteria::COUNT + cv::TermCriteria::EPS, 100, 1e-8); mySolver->setTermCriteria(criteria); double res = mySolver->minimize(dx); // cout << "After minimization\n"; // xp xp.at<cv::Point3d>(i, 0).x = xc.at<cv::Point3d>(i, 0).x + dx.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).x + dx.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).x; xp.at<cv::Point3d>(i, 0).y = xc.at<cv::Point3d>(i, 0).y + dx.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).y + dx.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).y; xp.at<cv::Point3d>(i, 0).z = xc.at<cv::Point3d>(i, 0).z + dx.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).z + dx.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).z; } // cout << "xp: \n" << xp << endl; return ret; } int plane_constrained3dPositioning_newton( const cv::Mat & camMat, // 3x3 camera matrix const cv::Mat & disVec, // 4x1 or 5x1 (or Nx1) distortion coefficients const cv::Mat & rmat, // 3x3 Rotation matrix or 3x1 or 1x3 vector of this camera (wrt global coord.). const cv::Mat & tvec, // 3x1 or 1x3 Translation vector of the camera. const cv::Mat & imgPoints, // Nx1 2-channel image points on photo. N is number of points to track. const cv::Mat & xc, // Nx1 3-channel constraining points, which define surfaces const cv::Mat & xcVec1, // Nx1 3-channel vector 1 of each tracking point, which define surfaces const cv::Mat & xcVec2, // Nx1 3-channel vector 2 of each tracking point, which define surfaces cv::Mat & xp // Nx1 3-channel positioned points, will be on the surface ) { int ret = 0; // check if (camMat.cols != 3 || camMat.rows != 3) { cerr << "plane_constrained3dPositioning: camMat has wrong size " << camMat.rows << "x" << camMat.cols << endl; return -1; } if (disVec.cols != 1 && disVec.rows != 1) { cerr << "plane_constrained3dPositioning: disVec has wrong size " << disVec.rows << "x" << disVec.cols << endl; return -1; } if (rmat.cols * rmat.rows != 3 && !(rmat.cols == 3 && rmat.rows == 3)) { cerr << "plane_constrained3dPositioning: rmat has wrong size " << rmat.rows << "x" << rmat.cols << endl; return -1; } if (tvec.cols * tvec.rows != 3) { cerr << "plane_constrained3dPositioning: tvec has wrong size " << tvec.rows << "x" << tvec.cols << endl; return -1; } if (imgPoints.cols != 1 || imgPoints.rows < 1) { cerr << "plane_constrained3dPositioning: imgPoints has wrong size " << imgPoints.rows << "x" << imgPoints.cols << endl; return -1; } if (imgPoints.type() != CV_32FC2) { cerr << "plane_constrained3dPositioning: imgPoints has wrong type (should be CV_32FC2 but) " << imgPoints.type() << endl; } if (xc.cols != 1 || xc.rows < 1) { cerr << "plane_constrained3dPositioning: xc has wrong size " << xc.rows << "x" << xc.cols << endl; return -1; } if (xc.type() != CV_64FC3) { cerr << "plane_constrained3dPositioning: xc has wrong type (should be CV_64FC3 but) " << xc.type() << endl; } if (xcVec1.cols != 1 || xcVec1.rows < 1) { cerr << "plane_constrained3dPositioning: xcVec1 has wrong size " << xcVec1.rows << "x" << xcVec1.cols << endl; return -1; } if (xcVec1.type() != CV_64FC3) { cerr << "plane_constrained3dPositioning: xcVec1 has wrong type (should be CV_64FC3 but) " << xcVec1.type() << endl; } if (xcVec2.cols != 1 || xcVec2.rows < 1) { cerr << "plane_constrained3dPositioning: xcVec2 has wrong size " << xcVec2.rows << "x" << xcVec2.cols << endl; return -1; } if (xcVec2.type() != CV_64FC3) { cerr << "plane_constrained3dPositioning: xcVec2 has wrong type (should be CV_64FC3 but) " << xcVec2.type() << endl; } if (xp.cols != 1 || xp.rows < 1) { xp = cv::Mat::zeros(xcVec2.rows, 1, CV_64FC3); } if (xp.type() != CV_64FC3) { xp = cv::Mat::zeros(xcVec2.rows, 1, CV_64FC3); } if (imgPoints.rows != xc.rows || xc.rows != xcVec1.rows || xcVec1.rows != xcVec2.rows && xcVec2.rows != xp.rows) { cerr << "plane_constrained3dPositioning: imgPoints/xc/xcVec1/xcVec2/xp do not have consistent # of rows: " << imgPoints.rows << " " << xc.rows << " " << xcVec1.rows << " " << xcVec2.rows << " " << xp.rows << endl; return -1; } int nPoint = imgPoints.rows; // cost function cv::Mat rvec(3, 1, CV_64F); if (rmat.cols == 3 && rmat.rows == 3) { cv::Rodrigues(rmat, rvec); rvec.copyTo(rvec); } else { rmat.copyTo(rvec); } // cout << "camMat: \n" << camMat << endl; // cout << "disVec: \n" << disVec << endl; // cout << "rvec: \n" << rmat << endl; // cout << "tvec: \n" << tvec << endl; // cout << "imgPoints: \n" << imgPoints << endl; // cout << "xc: \n" << xc << endl; // cout << "xcVec1: \n" << xcVec1 << endl; // cout << "xcVec2: \n" << xcVec2 << endl; // cout << "xp: \n" << xp << endl; // Solver // Positioning // Positioning: estimating the jacobian finite step size // double tol = 1e-4; double dx[2] = {}; for (int i = 0; i < nPoint; i++) { double xi = xc.at<cv::Point3d>(i, 0).x; double yi = xc.at<cv::Point3d>(i, 0).y; double zi = xc.at<cv::Point3d>(i, 0).z; dx[0] += sqrt(xi * xi + yi * yi + zi * zi) / nPoint; } dx[0] *= 1e-9; dx[1] = dx[0]; // cout << " Finite step: " << dx[0] << endl; // Positioning: running iterations for (int i = 0; i < nPoint; i++) { // from imgPoint, xc, xcVec1, xcVec2, to xp // double target[2] = {}, trial[2] = {}, x3trial[3] = {}, xitrial[2] = {}, err[2]; double target[2]; int nIterMax = 20; // init cv::Mat X = cv::Mat::zeros(2, 1, CV_64F); cv::Mat Y = cv::Mat::zeros(2, 1, CV_64F); cv::Mat J = cv::Mat::zeros(2, 2, CV_64F); cv::Mat XJ = cv::Mat::zeros(2, 1, CV_64F); cv::Mat YJ = cv::Mat::zeros(2, 1, CV_64F); target[0] = imgPoints.at<cv::Point2f>(i, 0).x; target[1] = imgPoints.at<cv::Point2f>(i, 0).y; // iteration double projErr; int itr; for (itr = 0; itr < nIterMax; itr++) { cv::Mat trial3d(1, 1, CV_64FC3), trial2d(1, 1, CV_64FC2); // Newton's method // double jtrial[2]; // Newton's method: Test current trial point (trial (0, 0)) XJ = X; trial3d.at<cv::Point3d>(0, 0).x = xc.at<cv::Point3d>(i, 0).x + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).x + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).x; trial3d.at<cv::Point3d>(0, 0).y = xc.at<cv::Point3d>(i, 0).y + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).y + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).y; trial3d.at<cv::Point3d>(0, 0).z = xc.at<cv::Point3d>(i, 0).z + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).z + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).z; cv::projectPoints(trial3d, rvec, tvec, camMat, disVec, trial2d); Y.at<double>(0, 0) = trial2d.at<cv::Point2d>(0, 0).x - imgPoints.at<cv::Point2f>(i, 0).x; Y.at<double>(1, 0) = trial2d.at<cv::Point2d>(0, 0).y - imgPoints.at<cv::Point2f>(i, 0).y; projErr = Y.at<double>(0, 0) * Y.at<double>(0, 0) + Y.at<double>(1, 0) * Y.at<double>(1, 0); // cout << "camMat: \n" << camMat << endl; // cout << "disVec: \n" << disVec << endl; // cout << "rvec: \n" << rvec << endl; // cout << "tvec: \n" << tvec << endl; // cout << "Newton X: " << X << endl; // cout << "Triai point: " << trial3d << endl; // cout << "Proj 2d: " << trial2d << endl; // cout << "Img 2d: " << imgPoints.at<cv::Point2f>(i, 0) << endl; // cout << "Projected Y: " << Y << endl; // cout << "Proj Err: " << projErr << endl; if (projErr < tol) break; // Newton's method: Jacobean Vector 1 (trial (1, 0)) XJ.at<double>(0, 0) = X.at<double>(0, 0) + dx[0]; XJ.at<double>(1, 0) = X.at<double>(1, 0) ; trial3d.at<cv::Point3d>(0, 0).x = xc.at<cv::Point3d>(i, 0).x + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).x + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).x; trial3d.at<cv::Point3d>(0, 0).y = xc.at<cv::Point3d>(i, 0).y + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).y + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).y; trial3d.at<cv::Point3d>(0, 0).z = xc.at<cv::Point3d>(i, 0).z + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).z + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).z; cv::projectPoints(trial3d, rvec, tvec, camMat, disVec, trial2d); // cout << "Triai point: " << trial3d << endl; // cout << "Proj 2d: " << trial2d << endl; YJ.at<double>(0, 0) = trial2d.at<cv::Point2d>(0, 0).x - imgPoints.at<cv::Point2f>(i, 0).x; YJ.at<double>(1, 0) = trial2d.at<cv::Point2d>(0, 0).y - imgPoints.at<cv::Point2f>(i, 0).y; J.at<double>(0, 0) = (YJ.at<double>(0, 0) - Y.at<double>(0, 0)) / dx[0]; J.at<double>(1, 0) = (YJ.at<double>(1, 0) - Y.at<double>(1, 0)) / dx[0]; // Newton's method: Jacobean Vector 2 (trial (0, 1)) XJ.at<double>(0, 0) = X.at<double>(0, 0); XJ.at<double>(1, 0) = X.at<double>(1, 0) + dx[1]; trial3d.at<cv::Point3d>(0, 0).x = xc.at<cv::Point3d>(i, 0).x + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).x + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).x; trial3d.at<cv::Point3d>(0, 0).y = xc.at<cv::Point3d>(i, 0).y + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).y + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).y; trial3d.at<cv::Point3d>(0, 0).z = xc.at<cv::Point3d>(i, 0).z + XJ.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).z + XJ.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).z; cv::projectPoints(trial3d, rvec, tvec, camMat, disVec, trial2d); // cout << "Triai point: " << trial3d << endl; // cout << "Proj 2d: " << trial2d << endl; YJ.at<double>(0, 0) = trial2d.at<cv::Point2d>(0, 0).x - imgPoints.at<cv::Point2f>(i, 0).x; YJ.at<double>(1, 0) = trial2d.at<cv::Point2d>(0, 0).y - imgPoints.at<cv::Point2f>(i, 0).y; J.at<double>(0, 1) = (YJ.at<double>(0, 0) - Y.at<double>(0, 0)) / dx[1]; J.at<double>(1, 1) = (YJ.at<double>(1, 0) - Y.at<double>(1, 0)) / dx[1]; // Next X X = X - 0.5 * J.inv() * Y; // cout << "J : " << J << endl; // cout << "Jinv : " << J.inv() << endl; // cout << endl << endl; } // cout << " Newton solver: " << itr << " iterations. Proj err: " << projErr << endl; // exit(1); // cv::projectPoints(trial3d, rvec, tvec, camMat, disVec, trial2d); // xp xp.at<cv::Point3d>(i, 0).x = xc.at<cv::Point3d>(i, 0).x + X.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).x + X.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).x; xp.at<cv::Point3d>(i, 0).y = xc.at<cv::Point3d>(i, 0).y + X.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).y + X.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).y; xp.at<cv::Point3d>(i, 0).z = xc.at<cv::Point3d>(i, 0).z + X.at<double>(0, 0) * xcVec1.at<cv::Point3d>(i, 0).z + X.at<double>(1, 0) * xcVec2.at<cv::Point3d>(i, 0).z; } // cout << "xp: \n" << xp << endl; return ret; }