Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1361)

Side by Side Diff: ipc/ipc_message_utils.h

Issue 2938613002: Add a variadic version of ParamTraits, to allow for >5 IPC parameters. (Closed)
Patch Set: Added Tuple to the helper name. Simplified end conditions. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef IPC_IPC_MESSAGE_UTILS_H_ 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_
6 #define IPC_IPC_MESSAGE_UTILS_H_ 6 #define IPC_IPC_MESSAGE_UTILS_H_
7 7
8 #include <limits.h> 8 #include <limits.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 static void Write(base::Pickle* m, const param_type& p) {} 717 static void Write(base::Pickle* m, const param_type& p) {}
718 static bool Read(const base::Pickle* m, 718 static bool Read(const base::Pickle* m,
719 base::PickleIterator* iter, 719 base::PickleIterator* iter,
720 param_type* r) { 720 param_type* r) {
721 return true; 721 return true;
722 } 722 }
723 static void Log(const param_type& p, std::string* l) { 723 static void Log(const param_type& p, std::string* l) {
724 } 724 }
725 }; 725 };
726 726
727 template <class A> 727 template <typename T, int I, int COUNT>
Ken Rockot(use gerrit already) 2017/06/20 16:35:53 super nitty nit: The style guide seems to be silen
728 struct ParamTraits<std::tuple<A>> { 728 struct TupleParamTraitsHelper {
729 typedef std::tuple<A> param_type; 729 using Next = TupleParamTraitsHelper<T, I + 1, COUNT>;
730
731 static void GetSize(base::PickleSizer* sizer, const T& p) {
732 GetParamSize(sizer, std::get<I>(p));
733 Next::GetSize(sizer, p);
734 }
735
736 static void Write(base::Pickle* m, const T& p) {
737 WriteParam(m, std::get<I>(p));
738 Next::Write(m, p);
739 }
740
741 static bool Read(const base::Pickle* m, base::PickleIterator* iter, T* r) {
742 return ReadParam(m, iter, &std::get<I>(*r)) && Next::Read(m, iter, r);
743 }
744
745 static void Log(const T& p, std::string* l) {
746 LogParam(std::get<I>(p), l);
747 if (I < COUNT - 1)
748 l->append(", ");
749 Next::Log(p, l);
750 }
751 };
752
753 template <typename T, int I>
754 struct TupleParamTraitsHelper<T, I, I> {
755 static void GetSize(base::PickleSizer* sizer, const T& p) {}
756 static void Write(base::Pickle* m, const T& p) {}
757 static bool Read(const base::Pickle* m, base::PickleIterator* iter, T* r) {
758 return true;
759 }
760 static void Log(const T& p, std::string* l) {}
761 };
762
763 template <class... Args>
Ken Rockot(use gerrit already) 2017/06/20 16:35:53 nit: for consistency with most new code please con
764 struct ParamTraits<std::tuple<Args...>> {
765 using param_type = std::tuple<Args...>;
766 using Helper =
767 TupleParamTraitsHelper<param_type, 0, std::tuple_size<param_type>::value>;
768
730 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 769 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
731 GetParamSize(sizer, std::get<0>(p)); 770 Helper::GetSize(sizer, p);
732 } 771 }
772
733 static void Write(base::Pickle* m, const param_type& p) { 773 static void Write(base::Pickle* m, const param_type& p) {
734 WriteParam(m, std::get<0>(p)); 774 Helper::Write(m, p);
735 } 775 }
776
736 static bool Read(const base::Pickle* m, 777 static bool Read(const base::Pickle* m,
737 base::PickleIterator* iter, 778 base::PickleIterator* iter,
738 param_type* r) { 779 param_type* r) {
739 return ReadParam(m, iter, &std::get<0>(*r)); 780 return Helper::Read(m, iter, r);
740 } 781 }
741 static void Log(const param_type& p, std::string* l) {
742 LogParam(std::get<0>(p), l);
743 }
744 };
745 782
746 template <class A, class B> 783 static void Log(const param_type& p, std::string* l) { Helper::Log(p, l); }
747 struct ParamTraits<std::tuple<A, B>> {
748 typedef std::tuple<A, B> param_type;
749 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
750 GetParamSize(sizer, std::get<0>(p));
751 GetParamSize(sizer, std::get<1>(p));
752 }
753 static void Write(base::Pickle* m, const param_type& p) {
754 WriteParam(m, std::get<0>(p));
755 WriteParam(m, std::get<1>(p));
756 }
757 static bool Read(const base::Pickle* m,
758 base::PickleIterator* iter,
759 param_type* r) {
760 return (ReadParam(m, iter, &std::get<0>(*r)) &&
761 ReadParam(m, iter, &std::get<1>(*r)));
762 }
763 static void Log(const param_type& p, std::string* l) {
764 LogParam(std::get<0>(p), l);
765 l->append(", ");
766 LogParam(std::get<1>(p), l);
767 }
768 };
769
770 template <class A, class B, class C>
771 struct ParamTraits<std::tuple<A, B, C>> {
772 typedef std::tuple<A, B, C> param_type;
773 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
774 GetParamSize(sizer, std::get<0>(p));
775 GetParamSize(sizer, std::get<1>(p));
776 GetParamSize(sizer, std::get<2>(p));
777 }
778 static void Write(base::Pickle* m, const param_type& p) {
779 WriteParam(m, std::get<0>(p));
780 WriteParam(m, std::get<1>(p));
781 WriteParam(m, std::get<2>(p));
782 }
783 static bool Read(const base::Pickle* m,
784 base::PickleIterator* iter,
785 param_type* r) {
786 return (ReadParam(m, iter, &std::get<0>(*r)) &&
787 ReadParam(m, iter, &std::get<1>(*r)) &&
788 ReadParam(m, iter, &std::get<2>(*r)));
789 }
790 static void Log(const param_type& p, std::string* l) {
791 LogParam(std::get<0>(p), l);
792 l->append(", ");
793 LogParam(std::get<1>(p), l);
794 l->append(", ");
795 LogParam(std::get<2>(p), l);
796 }
797 };
798
799 template <class A, class B, class C, class D>
800 struct ParamTraits<std::tuple<A, B, C, D>> {
801 typedef std::tuple<A, B, C, D> param_type;
802 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
803 GetParamSize(sizer, std::get<0>(p));
804 GetParamSize(sizer, std::get<1>(p));
805 GetParamSize(sizer, std::get<2>(p));
806 GetParamSize(sizer, std::get<3>(p));
807 }
808 static void Write(base::Pickle* m, const param_type& p) {
809 WriteParam(m, std::get<0>(p));
810 WriteParam(m, std::get<1>(p));
811 WriteParam(m, std::get<2>(p));
812 WriteParam(m, std::get<3>(p));
813 }
814 static bool Read(const base::Pickle* m,
815 base::PickleIterator* iter,
816 param_type* r) {
817 return (ReadParam(m, iter, &std::get<0>(*r)) &&
818 ReadParam(m, iter, &std::get<1>(*r)) &&
819 ReadParam(m, iter, &std::get<2>(*r)) &&
820 ReadParam(m, iter, &std::get<3>(*r)));
821 }
822 static void Log(const param_type& p, std::string* l) {
823 LogParam(std::get<0>(p), l);
824 l->append(", ");
825 LogParam(std::get<1>(p), l);
826 l->append(", ");
827 LogParam(std::get<2>(p), l);
828 l->append(", ");
829 LogParam(std::get<3>(p), l);
830 }
831 };
832
833 template <class A, class B, class C, class D, class E>
834 struct ParamTraits<std::tuple<A, B, C, D, E>> {
835 typedef std::tuple<A, B, C, D, E> param_type;
836 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
837 GetParamSize(sizer, std::get<0>(p));
838 GetParamSize(sizer, std::get<1>(p));
839 GetParamSize(sizer, std::get<2>(p));
840 GetParamSize(sizer, std::get<3>(p));
841 GetParamSize(sizer, std::get<4>(p));
842 }
843 static void Write(base::Pickle* m, const param_type& p) {
844 WriteParam(m, std::get<0>(p));
845 WriteParam(m, std::get<1>(p));
846 WriteParam(m, std::get<2>(p));
847 WriteParam(m, std::get<3>(p));
848 WriteParam(m, std::get<4>(p));
849 }
850 static bool Read(const base::Pickle* m,
851 base::PickleIterator* iter,
852 param_type* r) {
853 return (ReadParam(m, iter, &std::get<0>(*r)) &&
854 ReadParam(m, iter, &std::get<1>(*r)) &&
855 ReadParam(m, iter, &std::get<2>(*r)) &&
856 ReadParam(m, iter, &std::get<3>(*r)) &&
857 ReadParam(m, iter, &std::get<4>(*r)));
858 }
859 static void Log(const param_type& p, std::string* l) {
860 LogParam(std::get<0>(p), l);
861 l->append(", ");
862 LogParam(std::get<1>(p), l);
863 l->append(", ");
864 LogParam(std::get<2>(p), l);
865 l->append(", ");
866 LogParam(std::get<3>(p), l);
867 l->append(", ");
868 LogParam(std::get<4>(p), l);
869 }
870 }; 784 };
871 785
872 template <class P, size_t stack_capacity> 786 template <class P, size_t stack_capacity>
873 struct ParamTraits<base::StackVector<P, stack_capacity> > { 787 struct ParamTraits<base::StackVector<P, stack_capacity> > {
874 typedef base::StackVector<P, stack_capacity> param_type; 788 typedef base::StackVector<P, stack_capacity> param_type;
875 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 789 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
876 GetParamSize(sizer, static_cast<int>(p->size())); 790 GetParamSize(sizer, static_cast<int>(p->size()));
877 for (size_t i = 0; i < p->size(); i++) 791 for (size_t i = 0; i < p->size(); i++)
878 GetParamSize(sizer, p[i]); 792 GetParamSize(sizer, p[i]);
879 } 793 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 template <class ReplyParamType> 1110 template <class ReplyParamType>
1197 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, 1111 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1198 const Message* msg) {} 1112 const Message* msg) {}
1199 1113
1200 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} 1114 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
1201 #endif 1115 #endif
1202 1116
1203 } // namespace IPC 1117 } // namespace IPC
1204 1118
1205 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1119 #endif // IPC_IPC_MESSAGE_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698