GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cppgraphqlgen/samples/today/TodayMock.cpp at main · microsoft/cppgraphqlgen Expand file tree/ Copy pathTodayMock.cppMore file actions 1023 lines (834 loc) · 25.1 KB / Copy pathTodayMock.cppFile metadata and controls1023 lines (834 loc) · 25.1 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "TodayMock.h" #include "AppointmentConnectionObject.h" #include "CompleteTaskPayloadObject.h" #include "ExpensiveObject.h" #include "FolderConnectionObject.h" #include "NestedTypeObject.h" #include "TaskConnectionObject.h" #include "UnionTypeObject.h" #include <algorithm> #include <chrono> #include <future> #include <iostream> #include <mutex> namespace graphql::today { const response::IdType& getFakeAppointmentId() noexcept { static const auto s_fakeId = []() noexcept { std::string_view fakeIdString { "fakeAppointmentId" }; response::IdType result(fakeIdString.size()); std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin()); return response::IdType { std::move(result) }; }(); return s_fakeId; } const response::IdType& getFakeTaskId() noexcept { static const auto s_fakeId = []() noexcept { std::string_view fakeIdString { "fakeTaskId" }; response::IdType result(fakeIdString.size()); std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin()); return response::IdType { std::move(result) }; }(); return s_fakeId; } const response::IdType& getFakeFolderId() noexcept { static const auto s_fakeId = []() noexcept { std::string_view fakeIdString { "fakeFolderId" }; response::IdType result(fakeIdString.size()); std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin()); return response::IdType { std::move(result) }; }(); return s_fakeId; } std::unique_ptr<TodayMockService> mock_service() noexcept { auto result = std::make_unique<TodayMockService>(); auto query = std::make_shared<Query>( [mockService = result.get()]() -> std::vector<std::shared_ptr<Appointment>> { ++mockService->getAppointmentsCount; return { std::make_shared<Appointment>(response::IdType(getFakeAppointmentId()), "tomorrow", "Lunch?", false) }; }, [mockService = result.get()]() -> std::vector<std::shared_ptr<Task>> { ++mockService->getTasksCount; return { std::make_shared<Task>(response::IdType(getFakeTaskId()), "Don't forget", true) }; }, [mockService = result.get()]() -> std::vector<std::shared_ptr<Folder>> { ++mockService->getUnreadCountsCount; return { std::make_shared<Folder>(response::IdType(getFakeFolderId()), "\"Fake\" Inbox", 3) }; }); auto mutation = std::make_shared<Mutation>( [](CompleteTaskInput&& input) -> std::shared_ptr<CompleteTaskPayload> { return std::make_shared<CompleteTaskPayload>( std::make_shared<Task>(std::move(input.id), "Mutated Task!", *(input.isComplete)), std::move(input.clientMutationId)); }); auto subscription = std::make_shared<NextAppointmentChange>( [](const std::shared_ptr<service::RequestState>&) -> std::shared_ptr<Appointment> { return { std::make_shared<Appointment>(response::IdType(getFakeAppointmentId()), "tomorrow", "Lunch?", true) }; }); result->service = std::make_shared<Operations>(std::move(query), std::move(mutation), std::move(subscription)); return result; } RequestState::RequestState(size_t id) : requestId(id) { } PageInfo::PageInfo(bool hasNextPage, bool hasPreviousPage) : _hasNextPage(hasNextPage) , _hasPreviousPage(hasPreviousPage) { } bool PageInfo::getHasNextPage() const noexcept { return _hasNextPage; } bool PageInfo::getHasPreviousPage() const noexcept { return _hasPreviousPage; } Appointment::Appointment( response::IdType&& id, std::string&& when, std::string&& subject, bool isNow) : _id(std::move(id)) , _when(std::make_shared<response::Value>(std::move(when))) , _subject(std::make_shared<response::Value>(std::move(subject))) , _isNow(isNow) { } const response::IdType& Appointment::id() const noexcept { return _id; } service::AwaitableScalar<response::IdType> Appointment::getId() const noexcept { return _id; } std::shared_ptr<const response::Value> Appointment::getWhen() const noexcept { return _when; } std::shared_ptr<const response::Value> Appointment::getSubject() const noexcept { return _subject; } bool Appointment::getIsNow() const noexcept { return _isNow; } std::optional<std::string> Appointment::getForceError() const { throw std::runtime_error(R"ex(this error was forced)ex"); } AppointmentEdge::AppointmentEdge(std::shared_ptr<Appointment> appointment) : _appointment(std::move(appointment)) { } std::shared_ptr<object::Appointment> AppointmentEdge::getNode() const noexcept { return std::make_shared<object::Appointment>(_appointment); } service::AwaitableScalar<response::Value> AppointmentEdge::getCursor() const { co_return response::Value(co_await _appointment->getId()); } AppointmentConnection::AppointmentConnection( bool hasNextPage, bool hasPreviousPage, std::vector<std::shared_ptr<Appointment>> appointments) : _pageInfo(std::make_shared<PageInfo>(hasNextPage, hasPreviousPage)) , _appointments(std::move(appointments)) { } std::shared_ptr<object::PageInfo> AppointmentConnection::getPageInfo() const noexcept { return std::make_shared<object::PageInfo>(_pageInfo); } std::optional<std::vector<std::shared_ptr<object::AppointmentEdge>>> AppointmentConnection:: getEdges() const noexcept { auto result = std::make_optional<std::vector<std::shared_ptr<object::AppointmentEdge>>>( _appointments.size()); std::transform(_appointments.cbegin(), _appointments.cend(), result->begin(), [](const std::shared_ptr<Appointment>& node) { return std::make_shared<object::AppointmentEdge>( std::make_shared<AppointmentEdge>(node)); }); return result; } Task::Task(response::IdType&& id, std::string&& title, bool isComplete) : _id(std::move(id)) , _title(std::make_shared<response::Value>(std::move(title))) , _isComplete(isComplete) { } const response::IdType& Task::id() const { return _id; } service::AwaitableScalar<response::IdType> Task::getId() const noexcept { return _id; } std::shared_ptr<const response::Value> Task::getTitle() const noexcept { return _title; } bool Task::getIsComplete() const noexcept { return _isComplete; } TaskEdge::TaskEdge(std::shared_ptr<Task> task) : _task(std::move(task)) { } std::shared_ptr<object::Task> TaskEdge::getNode() const noexcept { return std::make_shared<object::Task>(_task); } service::AwaitableScalar<response::Value> TaskEdge::getCursor() const noexcept { co_return response::Value(co_await _task->getId()); } TaskConnection::TaskConnection( bool hasNextPage, bool hasPreviousPage, std::vector<std::shared_ptr<Task>> tasks) : _pageInfo(std::make_shared<PageInfo>(hasNextPage, hasPreviousPage)) , _tasks(std::move(tasks)) { } std::shared_ptr<object::PageInfo> TaskConnection::getPageInfo() const noexcept { return std::make_shared<object::PageInfo>(_pageInfo); } std::optional<std::vector<std::shared_ptr<object::TaskEdge>>> TaskConnection::getEdges() const noexcept { auto result = std::make_optional<std::vector<std::shared_ptr<object::TaskEdge>>>(_tasks.size()); std::transform(_tasks.cbegin(), _tasks.cend(), result->begin(), [](const std::shared_ptr<Task>& node) { return std::make_shared<object::TaskEdge>(std::make_shared<TaskEdge>(node)); }); return result; } Folder::Folder(response::IdType&& id, std::string&& name, int unreadCount) : _id(std::move(id)) , _name(std::make_shared<response::Value>(std::move(name))) , _unreadCount(unreadCount) { } const response::IdType& Folder::id() const noexcept { return _id; } service::AwaitableScalar<response::IdType> Folder::getId() const noexcept { return _id; } std::shared_ptr<const response::Value> Folder::getName() const noexcept { return _name; } int Folder::getUnreadCount() const noexcept { return _unreadCount; } FolderEdge::FolderEdge(std::shared_ptr<Folder> folder) : _folder(std::move(folder)) { } std::shared_ptr<object::Folder> FolderEdge::getNode() const noexcept { return std::make_shared<object::Folder>(_folder); } service::AwaitableScalar<response::Value> FolderEdge::getCursor() const noexcept { co_return response::Value(co_await _folder->getId()); } FolderConnection::FolderConnection( bool hasNextPage, bool hasPreviousPage, std::vector<std::shared_ptr<Folder>> folders) : _pageInfo(std::make_shared<PageInfo>(hasNextPage, hasPreviousPage)) , _folders(std::move(folders)) { } std::shared_ptr<object::PageInfo> FolderConnection::getPageInfo() const noexcept { return std::make_shared<object::PageInfo>(_pageInfo); } std::optional<std::vector<std::shared_ptr<object::FolderEdge>>> FolderConnection::getEdges() const noexcept { auto result = std::make_optional<std::vector<std::shared_ptr<object::FolderEdge>>>(_folders.size()); std::transform(_folders.cbegin(), _folders.cend(), result->begin(), [](const std::shared_ptr<Folder>& node) { return std::make_shared<object::FolderEdge>(std::make_shared<FolderEdge>(node)); }); return result; } Query::Query(appointmentsLoader&& getAppointments, tasksLoader&& getTasks, unreadCountsLoader&& getUnreadCounts) : _getAppointments(std::move(getAppointments)) , _getTasks(std::move(getTasks)) , _getUnreadCounts(getUnreadCounts) { } void Query::loadAppointments(const std::shared_ptr<service::RequestState>& state) { static std::mutex s_loaderMutex {}; std::lock_guard lock { s_loaderMutex }; if (_getAppointments) { if (state) { auto todayState = std::static_pointer_cast<RequestState>(state); todayState->appointmentsRequestId = todayState->requestId; todayState->loadAppointmentsCount++; } _appointments = _getAppointments(); _getAppointments = nullptr; } } std::shared_ptr<Appointment> Query::findAppointment( const service::FieldParams& params, const response::IdType& id) { loadAppointments(params.state); for (const auto& appointment : _appointments) { if (appointment->id() == id) { return appointment; } } return nullptr; } void Query::loadTasks(const std::shared_ptr<service::RequestState>& state) { static std::mutex s_loaderMutex {}; std::lock_guard lock { s_loaderMutex }; if (_getTasks) { if (state) { auto todayState = std::static_pointer_cast<RequestState>(state); todayState->tasksRequestId = todayState->requestId; todayState->loadTasksCount++; } _tasks = _getTasks(); _getTasks = nullptr; } } std::shared_ptr<Task> Query::findTask( const service::FieldParams& params, const response::IdType& id) { loadTasks(params.state); for (const auto& task : _tasks) { if (task->id() == id) { return task; } } return nullptr; } void Query::loadUnreadCounts(const std::shared_ptr<service::RequestState>& state) { static std::mutex s_loaderMutex {}; std::lock_guard lock { s_loaderMutex }; if (_getUnreadCounts) { if (state) { auto todayState = std::static_pointer_cast<RequestState>(state); todayState->unreadCountsRequestId = todayState->requestId; todayState->loadUnreadCountsCount++; } _unreadCounts = _getUnreadCounts(); _getUnreadCounts = nullptr; } } std::shared_ptr<Folder> Query::findUnreadCount( const service::FieldParams& params, const response::IdType& id) { loadUnreadCounts(params.state); for (const auto& folder : _unreadCounts) { if (folder->id() == id) { return folder; } } return nullptr; } template <class _Rep, class _Period> auto operator co_await(std::chrono::duration<_Rep, _Period> delay) { struct awaiter { const std::chrono::duration<_Rep, _Period> delay; constexpr bool await_ready() const { return true; } void await_suspend(coro::coroutine_handle<> h) noexcept { h.resume(); } void await_resume() { std::this_thread::sleep_for(delay); } }; return awaiter { delay }; } service::AwaitableObject<std::shared_ptr<object::Node>> Query::getNode( service::FieldParams params, response::IdType id) { // query { node(id: "ZmFrZVRhc2tJZA==") { ...on Task { title } } } using namespace std::literals; co_await 100ms; auto appointment = findAppointment(params, id); if (appointment) { co_return std::make_shared<object::Node>( std::make_shared<object::Appointment>(std::move(appointment))); } auto task = findTask(params, id); if (task) { co_return std::make_shared<object::Node>(std::make_shared<object::Task>(std::move(task))); } auto folder = findUnreadCount(params, id); if (folder) { co_return std::make_shared<object::Node>( std::make_shared<object::Folder>(std::move(folder))); } co_return nullptr; } template <class _Object, class _Connection> struct EdgeConstraints { using vec_type = std::vector<std::shared_ptr<_Object>>; using itr_type = typename vec_type::const_iterator; EdgeConstraints(const std::shared_ptr<service::RequestState>& state, const vec_type& objects) : _state(state) , _objects(objects) { } std::shared_ptr<_Connection> operator()(const std::optional<int>& first, std::optional<response::Value>&& after, const std::optional<int>& last, std::optional<response::Value>&& before) const { auto itrFirst = _objects.cbegin(); auto itrLast = _objects.cend(); if (after) { auto afterId = after->release<response::IdType>(); auto itrAfter = std::find_if(itrFirst, itrLast, [&afterId](const std::shared_ptr<_Object>& entry) { return entry->id() == afterId; }); if (itrAfter != itrLast) { itrFirst = itrAfter; } } if (before) { auto beforeId = before->release<response::IdType>(); auto itrBefore = std::find_if(itrFirst, itrLast, [&beforeId](const std::shared_ptr<_Object>& entry) { return entry->id() == beforeId; }); if (itrBefore != itrLast) { itrLast = itrBefore; ++itrLast; } } if (first) { if (*first < 0) { std::ostringstream error; error << "Invalid argument: first value: " << *first; throw service::schema_exception { { service::schema_error { error.str() } } }; } if (itrLast - itrFirst > *first) { itrLast = itrFirst + *first; } } if (last) { if (*last < 0) { std::ostringstream error; error << "Invalid argument: last value: " << *last; throw service::schema_exception { { service::schema_error { error.str() } } }; } if (itrLast - itrFirst > *last) { itrFirst = itrLast - *last; } } std::vector<std::shared_ptr<_Object>> edges(itrLast - itrFirst); std::copy(itrFirst, itrLast, edges.begin()); return std::make_shared<_Connection>(itrLast<_objects.cend(), itrFirst> _objects.cbegin(), std::move(edges)); } private: const std::shared_ptr<service::RequestState>& _state; const vec_type& _objects; }; std::future<std::shared_ptr<object::AppointmentConnection>> Query::getAppointments( const service::FieldParams& params, std::optional<int> first, std::optional<response::Value>&& after, std::optional<int> last, std::optional<response::Value>&& before) { auto spThis = shared_from_this(); auto state = params.state; return std::async( std::launch::async, [this, spThis, state](std::optional<int>&& firstWrapped, std::optional<response::Value>&& afterWrapped, std::optional<int>&& lastWrapped, std::optional<response::Value>&& beforeWrapped) { loadAppointments(state); EdgeConstraints<Appointment, AppointmentConnection> constraints(state, _appointments); auto connection = constraints(firstWrapped, std::move(afterWrapped), lastWrapped, std::move(beforeWrapped)); return std::make_shared<object::AppointmentConnection>(connection); }, std::move(first), std::move(after), std::move(last), std::move(before)); } std::future<std::shared_ptr<object::TaskConnection>> Query::getTasks( const service::FieldParams& params, std::optional<int> first, std::optional<response::Value>&& after, std::optional<int> last, std::optional<response::Value>&& before) { auto spThis = shared_from_this(); auto state = params.state; return std::async( std::launch::async, [this, spThis, state](std::optional<int>&& firstWrapped, std::optional<response::Value>&& afterWrapped, std::optional<int>&& lastWrapped, std::optional<response::Value>&& beforeWrapped) { loadTasks(state); EdgeConstraints<Task, TaskConnection> constraints(state, _tasks); auto connection = constraints(firstWrapped, std::move(afterWrapped), lastWrapped, std::move(beforeWrapped)); return std::make_shared<object::TaskConnection>(connection); }, std::move(first), std::move(after), std::move(last), std::move(before)); } std::future<std::shared_ptr<object::FolderConnection>> Query::getUnreadCounts( const service::FieldParams& params, std::optional<int> first, std::optional<response::Value>&& after, std::optional<int> last, std::optional<response::Value>&& before) { auto spThis = shared_from_this(); auto state = params.state; return std::async( std::launch::async, [this, spThis, state](std::optional<int>&& firstWrapped, std::optional<response::Value>&& afterWrapped, std::optional<int>&& lastWrapped, std::optional<response::Value>&& beforeWrapped) { loadUnreadCounts(state); EdgeConstraints<Folder, FolderConnection> constraints(state, _unreadCounts); auto connection = constraints(firstWrapped, std::move(afterWrapped), lastWrapped, std::move(beforeWrapped)); return std::make_shared<object::FolderConnection>(connection); }, std::move(first), std::move(after), std::move(last), std::move(before)); } std::vector<std::shared_ptr<object::Appointment>> Query::getAppointmentsById( const service::FieldParams& params, const std::vector<response::IdType>& ids) { std::vector<std::shared_ptr<object::Appointment>> result(ids.size()); std::transform(ids.cbegin(), ids.cend(), result.begin(), [this, ¶ms](const response::IdType& id) { return std::make_shared<object::Appointment>(findAppointment(params, id)); }); return result; } std::vector<std::shared_ptr<object::Task>> Query::getTasksById( const service::FieldParams& params, const std::vector<response::IdType>& ids) { std::vector<std::shared_ptr<object::Task>> result(ids.size()); std::transform(ids.cbegin(), ids.cend(), result.begin(), [this, ¶ms](const response::IdType& id) { return std::make_shared<object::Task>(findTask(params, id)); }); return result; } std::vector<std::shared_ptr<object::Folder>> Query::getUnreadCountsById( const service::FieldParams& params, const std::vector<response::IdType>& ids) { std::vector<std::shared_ptr<object::Folder>> result(ids.size()); std::transform(ids.cbegin(), ids.cend(), result.begin(), [this, ¶ms](const response::IdType& id) { return std::make_shared<object::Folder>(findUnreadCount(params, id)); }); return result; } std::shared_ptr<object::NestedType> Query::getNested(service::FieldParams&& params) { return std::make_shared<object::NestedType>(std::make_shared<NestedType>(std::move(params), 1)); } std::vector<std::shared_ptr<object::Expensive>> Query::getExpensive() { std::vector<std::shared_ptr<object::Expensive>> result(Expensive::count); for (auto& entry : result) { entry = std::make_shared<object::Expensive>(std::make_shared<Expensive>()); } return result; } TaskState Query::getTestTaskState() { return TaskState::Unassigned; } std::vector<std::shared_ptr<object::UnionType>> Query::getAnyType( const service::FieldParams& params, const std::vector<response::IdType>&) { loadAppointments(params.state); std::vector<std::shared_ptr<object::UnionType>> result(_appointments.size()); std::transform(_appointments.cbegin(), _appointments.cend(), result.begin(), [](const auto& appointment) noexcept { return std::make_shared<object::UnionType>( std::make_shared<object::Appointment>(appointment)); }); return result; } std::optional<std::string> Query::getDefault() const noexcept { return std::nullopt; } CompleteTaskPayload::CompleteTaskPayload( std::shared_ptr<Task> task, std::optional<std::string>&& clientMutationId) : _task(std::move(task)) , _clientMutationId(std::move(clientMutationId)) { } std::shared_ptr<object::Task> CompleteTaskPayload::getTask() const noexcept { return std::make_shared<object::Task>(_task); } const std::optional<std::string>& CompleteTaskPayload::getClientMutationId() const noexcept { return _clientMutationId; } Mutation::Mutation(completeTaskMutation&& mutateCompleteTask) : _mutateCompleteTask(std::move(mutateCompleteTask)) { } std::shared_ptr<object::CompleteTaskPayload> Mutation::applyCompleteTask( CompleteTaskInput&& input) noexcept { return std::make_shared<object::CompleteTaskPayload>(_mutateCompleteTask(std::move(input))); } std::optional<double> Mutation::_setFloat = std::nullopt; double Mutation::getFloat() noexcept { return *_setFloat; } double Mutation::applySetFloat(double valueArg) noexcept { _setFloat = std::make_optional(valueArg); return valueArg; } std::shared_ptr<object::Appointment> Subscription::getNextAppointmentChange() const { throw std::runtime_error("Unexpected call to getNextAppointmentChange"); } std::shared_ptr<object::Node> Subscription::getNodeChange(const response::IdType&) const { throw std::runtime_error("Unexpected call to getNodeChange"); } size_t NextAppointmentChange::_notifySubscribeCount = 0; size_t NextAppointmentChange::_subscriptionCount = 0; size_t NextAppointmentChange::_notifyUnsubscribeCount = 0; NextAppointmentChange::NextAppointmentChange(nextAppointmentChange&& changeNextAppointment) : _changeNextAppointment(std::move(changeNextAppointment)) { } size_t NextAppointmentChange::getCount(service::ResolverContext resolverContext) { switch (resolverContext) { case service::ResolverContext::NotifySubscribe: return _notifySubscribeCount; case service::ResolverContext::Subscription: return _subscriptionCount; case service::ResolverContext::NotifyUnsubscribe: return _notifyUnsubscribeCount; default: throw std::runtime_error("Unexpected ResolverContext"); } } std::shared_ptr<object::Appointment> NextAppointmentChange::getNextAppointmentChange( const service::FieldParams& params) const { switch (params.resolverContext) { case service::ResolverContext::NotifySubscribe: { ++_notifySubscribeCount; break; } case service::ResolverContext::Subscription: { ++_subscriptionCount; break; } case service::ResolverContext::NotifyUnsubscribe: { ++_notifyUnsubscribeCount; break; } default: throw std::runtime_error("Unexpected ResolverContext"); } return std::make_shared<object::Appointment>(_changeNextAppointment(params.state)); } std::shared_ptr<object::Node> NextAppointmentChange::getNodeChange(const response::IdType&) const { throw std::runtime_error("Unexpected call to getNodeChange"); } NodeChange::NodeChange(nodeChange&& changeNode) : _changeNode(std::move(changeNode)) { } std::shared_ptr<object::Appointment> NodeChange::getNextAppointmentChange() const { throw std::runtime_error("Unexpected call to getNextAppointmentChange"); } std::shared_ptr<object::Node> NodeChange::getNodeChange( const service::FieldParams& params, response::IdType&& idArg) const { return _changeNode(params.resolverContext, params.state, std::move(idArg)); } std::stack<CapturedParams> NestedType::_capturedParams; NestedType::NestedType(service::FieldParams&& params, int depth) : depth(depth) { _capturedParams.push({ { params.operationDirectives }, params.fragmentDefinitionDirectives->empty() ? service::Directives {} : service::Directives { params.fragmentDefinitionDirectives->front().get() }, params.fragmentSpreadDirectives->empty() ? service::Directives {} : service::Directives { params.fragmentSpreadDirectives->front() }, params.inlineFragmentDirectives->empty() ? service::Directives {} : service::Directives { params.inlineFragmentDirectives->front() }, std::move(params.fieldDirectives) }); } int NestedType::getDepth() const noexcept { return depth; } std::shared_ptr<object::NestedType> NestedType::getNested( service::FieldParams&& params) const noexcept { return std::make_shared<object::NestedType>( std::make_shared<NestedType>(std::move(params), depth + 1)); } std::stack<CapturedParams> NestedType::getCapturedParams() noexcept { auto result = std::move(_capturedParams); return result; } std::mutex Expensive::testMutex {}; std::mutex Expensive::pendingExpensiveMutex {}; std::condition_variable Expensive::pendingExpensiveCondition {}; size_t Expensive::pendingExpensive = 0; std::atomic<size_t> Expensive::instances = 0; bool Expensive::Reset() noexcept { std::unique_lock pendingExpensiveLock(pendingExpensiveMutex); pendingExpensive = 0; pendingExpensiveLock.unlock(); return instances == 0; } Expensive::Expensive() : order(++instances) { } Expensive::~Expensive() { --instances; } std::future<int> Expensive::getOrder(const service::FieldParams& params) const noexcept { return std::async( params.launch.await_ready() ? std::launch::deferred : std::launch::async, [](bool blockAsync, int instanceOrder) noexcept { if (blockAsync) { // Block all of the Expensive objects in async mode until the count is reached. std::unique_lock pendingExpensiveLock(pendingExpensiveMutex); if (++pendingExpensive < count) |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |