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

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: Rebase 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 <int I, int MAX>
Ken Rockot(use gerrit already) 2017/06/14 17:42:26 How about counting down instead of counting up? Th
ossu-chromium 2017/06/20 11:57:19 I tried it and I think my new version reads a bit
728 struct ParamTraits<std::tuple<A>> { 728 struct ParamTraitsHelper {
729 typedef std::tuple<A> param_type; 729 template <typename T>
Ken Rockot(use gerrit already) 2017/06/14 17:42:27 Not sure there's much reason to template each meth
ossu-chromium 2017/06/20 11:57:19 Right. I've just put the type as a third class tem
730 static void GetSize(base::PickleSizer* sizer, const T& p) {
731 GetParamSize(sizer, std::get<I>(p));
732 ParamTraitsHelper<I + 1, MAX>::GetSize(sizer, p);
733 }
734
735 template <typename T>
736 static void Write(base::Pickle* m, const T& p) {
737 WriteParam(m, std::get<I>(p));
738 ParamTraitsHelper<I + 1, MAX>::Write(m, p);
739 }
740
741 template <typename T>
742 static bool Read(const base::Pickle* m, base::PickleIterator* iter, T* r) {
743 return ReadParam(m, iter, &std::get<I>(*r)) &&
744 ParamTraitsHelper<I + 1, MAX>::Read(m, iter, r);
745 }
746
747 template <typename T>
748 static void Log(const T& p, std::string* l) {
749 LogParam(std::get<I>(p), l);
750 l->append(", ");
751 ParamTraitsHelper<I + 1, MAX>::Log(p, l);
752 }
753 };
754
755 template <int I>
756 struct ParamTraitsHelper<I, I> {
757 template <typename T>
758 static void GetSize(base::PickleSizer* sizer, const T& p) {
759 GetParamSize(sizer, std::get<I>(p));
760 }
761
762 template <typename T>
763 static void Write(base::Pickle* m, const T& p) {
764 WriteParam(m, std::get<I>(p));
765 }
766
767 template <typename T>
768 static bool Read(const base::Pickle* m, base::PickleIterator* iter, T* r) {
769 return ReadParam(m, iter, &std::get<I>(*r));
770 }
771
772 template <typename T>
773 static void Log(const T& p, std::string* l) {
774 LogParam(std::get<I>(p), l);
775 }
776 };
777
778 template <class... Args>
779 struct ParamTraits<std::tuple<Args...>> {
780 typedef std::tuple<Args...> param_type;
781 typedef ParamTraitsHelper<0, std::tuple_size<param_type>::value - 1> Helper;
782
730 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 783 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
731 GetParamSize(sizer, std::get<0>(p)); 784 Helper::GetSize(sizer, p);
732 } 785 }
786
733 static void Write(base::Pickle* m, const param_type& p) { 787 static void Write(base::Pickle* m, const param_type& p) {
734 WriteParam(m, std::get<0>(p)); 788 Helper::Write(m, p);
735 } 789 }
790
736 static bool Read(const base::Pickle* m, 791 static bool Read(const base::Pickle* m,
737 base::PickleIterator* iter, 792 base::PickleIterator* iter,
738 param_type* r) { 793 param_type* r) {
739 return ReadParam(m, iter, &std::get<0>(*r)); 794 return Helper::Read(m, iter, r);
740 } 795 }
741 static void Log(const param_type& p, std::string* l) {
742 LogParam(std::get<0>(p), l);
743 }
744 };
745 796
746 template <class A, class B> 797 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 }; 798 };
871 799
872 template <class P, size_t stack_capacity> 800 template <class P, size_t stack_capacity>
873 struct ParamTraits<base::StackVector<P, stack_capacity> > { 801 struct ParamTraits<base::StackVector<P, stack_capacity> > {
874 typedef base::StackVector<P, stack_capacity> param_type; 802 typedef base::StackVector<P, stack_capacity> param_type;
875 static void GetSize(base::PickleSizer* sizer, const param_type& p) { 803 static void GetSize(base::PickleSizer* sizer, const param_type& p) {
876 GetParamSize(sizer, static_cast<int>(p->size())); 804 GetParamSize(sizer, static_cast<int>(p->size()));
877 for (size_t i = 0; i < p->size(); i++) 805 for (size_t i = 0; i < p->size(); i++)
878 GetParamSize(sizer, p[i]); 806 GetParamSize(sizer, p[i]);
879 } 807 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 template <class ReplyParamType> 1124 template <class ReplyParamType>
1197 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, 1125 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params,
1198 const Message* msg) {} 1126 const Message* msg) {}
1199 1127
1200 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} 1128 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {}
1201 #endif 1129 #endif
1202 1130
1203 } // namespace IPC 1131 } // namespace IPC
1204 1132
1205 #endif // IPC_IPC_MESSAGE_UTILS_H_ 1133 #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