CN108932123A - parameter processing method and device - Google Patents

parameter processing method and device Download PDF

Info

Publication number
CN108932123A
CN108932123A CN201810646530.1A CN201810646530A CN108932123A CN 108932123 A CN108932123 A CN 108932123A CN 201810646530 A CN201810646530 A CN 201810646530A CN 108932123 A CN108932123 A CN 108932123A
Authority
CN
China
Prior art keywords
parameter
class
universal
universal class
template
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201810646530.1A
Other languages
Chinese (zh)
Other versions
CN108932123B (en
Inventor
赵肖勇
康高杰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201810646530.1A priority Critical patent/CN108932123B/en
Publication of CN108932123A publication Critical patent/CN108932123A/en
Application granted granted Critical
Publication of CN108932123B publication Critical patent/CN108932123B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code

Abstract

The invention discloses parameter processing methods and device.The described method includes: obtaining several parameters to be processed;According to preset Parameter Switch template, which is stored as universal class object, obtains universal class information corresponding with the universal class object;The universal class information is passed into parameter recipient, by the parameter recipient according to the universal class acquisition of information several parameters.The beneficial effect of the technical solution is, by can support any type of parameter of any number in Parameter Switch template theory, does not need to carry out serializing and unserializing processing, and fool proof, more efficient.

Description

Parameter processing method and device
Technical field
The present invention relates to field of computer technology, and in particular to parameter processing method and device.
Background technique
Developer is known, the type diversification of parameter, such as fundamental type (integer int, long long, character string Char ...), function, pointer etc. all can serve as parameter carry out using.
However as the continuous change of demand, there are many new problems.For example, parameter recipient wishes received ginseng Several classes of types, number of parameters be it is unfixed, in this way if all scenario is considered to be clearly to be not easily accomplished one by one.It is a kind of Way is that argument sequence to be passed is turned to a character string, carries out unserializing processing after receiving parameter by parameter person, But it is very dangerous in this way, there is limitation to parameter, and efficiency is very low.
Summary of the invention
In view of the above problems, it proposes on the present invention overcomes the above problem or at least be partially solved in order to provide one kind State the parameter processing method and device of problem.
According to one aspect of the present invention, a kind of parameter processing method is provided, comprising:
Obtain several parameters to be processed;
According to preset Parameter Switch template, which is stored as universal class object, is obtained general with this The corresponding universal class information of type object;
The universal class information is passed into parameter recipient, is believed by the parameter recipient according to the universal class Breath obtains several parameters.
Optionally, the parameter includes following one or more:
Fundamental type object, lambda expression formula, pointer, intelligent pointer, generic function.
Optionally, the preset Parameter Switch template includes empty parameter packaging base class, and according to template The derived class for the parameter packaging base class that template is realized;
It is described that several parameters are stored as by universal class object according to preset Parameter Switch template, it obtains and is somebody's turn to do The corresponding universal class information of universal class object includes:
Derivation class object corresponding with several parameters is generated according to derived class construction, is obtained and the derived class pair As corresponding base class pointer.
Optionally, described to include: according to derived class construction generation derivation class object corresponding with several parameters
According to the parameter packing method in the derived class, which is packed.
Optionally, the parameter packing method according in the derived class, which is carried out include:
A tuple is created according to the variable element template in the parameter packing method, which is written into institute It states in tuple.
Optionally, the variable element template according in the parameter packing method creates a tuple and comprises determining that The index information of several parameters in the tuple.
Optionally, the index information includes the write-in type that each position corresponds to parameter in the tuple.
Optionally, described to include: according to derived class construction generation derivation class object corresponding with several parameters
When the quantity of parameter to be processed is for the moment, to judge whether the type of the parameter belongs to preset kind;
It is to store the parameter in the memory headroom of the derived class application, otherwise applies new memory headroom for depositing Store up the parameter.
Optionally, the memory headroom of the derived class application is divided into three regions in order, sequentially for storing Virtual Function Table, base class pointer and parameter.
Optionally, the parameter recipient is the observer in Observer Pattern or pending function.
Another aspect according to the present invention provides a kind of parameter processing method, comprising:
Obtain universal class information corresponding with universal class object, wherein the universal class object is stored with several A parameter;
According to the universal class information, target component is taken out from the universal class object by specified type.
Optionally, the universal class object is according to preset Parameter Switch template generation, the preset parameter Conversion module includes empty parameter packaging base class, and the derivation according to the template template parameter packaging base class realized Class;
The universal class object is specially the derivation class object generated according to derived class construction, the universal class Information is base class pointer corresponding with the derived class.
Optionally, the universal class object includes the index information for storing the tuple and tuple of several parameters;
It is described according to the universal class information, target component packet is taken out from the universal class object by specified type It includes: inheriting parameter in the derived class and obtain Virtual Function, according to the base class pointer and the index information from the tuple It is middle to take out corresponding parameter.
Optionally, the index information includes the write-in type that each position corresponds to parameter in the tuple;
It is described according to the base class pointer and the index information taken out from the tuple corresponding parameter include: according to Each position corresponds to the write-in type of parameter in the tuple, obtains out the parameter of corresponding position.
Optionally, the write-in type that parameter is corresponded to according to each position in the tuple, obtains out the ginseng of corresponding position Number includes:
According to preset fuzzy matching rule, the matched taking-up type of said write type institute is determined;
According to it is matched take out type take out corresponding position parameter;
In the fuzzy matching rule, a taking-up type corresponds to one or more write-in types.
Another aspect according to the present invention, provides a kind of parameter processing apparatus, comprising:
Parameter acquiring unit, suitable for obtaining several parameters to be processed;
Parameter processing unit is suitable for that several parameters are stored as universal class according to preset Parameter Switch template Object obtains universal class information corresponding with the universal class object;
Parameter transfer unit, suitable for the universal class information is passed to parameter recipient, by the parameter recipient According to the universal class acquisition of information several parameters.
Optionally, the parameter includes following one or more:
Fundamental type object, lambda expression formula, pointer, intelligent pointer, generic function.
Optionally, the preset Parameter Switch template includes empty parameter packaging base class, and according to template The derived class for the parameter packaging base class that template is realized;
The parameter processing unit is suitable for generating derived class corresponding with several parameters according to derived class construction Object obtains base class pointer corresponding with the derivation class object.
Optionally, the parameter processing unit, suitable for according to the parameter packing method in the derived class, to this several Parameter is packed.
Optionally, the parameter processing unit, suitable for being created according to the variable element template in the parameter packing method Several parameters are written in the tuple one tuple.
Optionally, the parameter processing unit is adapted to determine that the index information of several parameters in the tuple.
Optionally, the index information includes the write-in type that each position corresponds to parameter in the tuple.
Optionally, the parameter processing unit is for the moment, to judge the class of the parameter suitable for the quantity when parameter to be processed Whether type belongs to preset kind;It is to store the parameter in the memory headroom of the derived class application, otherwise applies new interior Space is deposited for storing the parameter.
Optionally, the memory headroom of the derived class application is divided into three regions in order, sequentially for storing Virtual Function Table, base class pointer and parameter.
Optionally, the parameter recipient is the observer in Observer Pattern or pending function.
According to the present invention in another aspect, providing a kind of parameter processing apparatus, comprising:
Universal class information acquisition unit is suitable for obtaining universal class information corresponding with universal class object, wherein institute It states universal class object and is stored with several parameters;
Parameter extraction unit is suitable for according to the universal class information, by specified type from the universal class object Take out target component.
Optionally, the universal class object is according to preset Parameter Switch template generation, the preset parameter Conversion module includes empty parameter packaging base class, and the derivation according to the template template parameter packaging base class realized Class;
The universal class object is specially the derivation class object generated according to derived class construction, the universal class Information is base class pointer corresponding with the derived class.
Optionally, the universal class object includes the index information for storing the tuple and tuple of several parameters;
The parameter extraction unit, the parameter suitable for inheriting in the derived class obtain Virtual Function, are referred to according to the base class Needle and the index information take out corresponding parameter from the tuple.
Optionally, the index information includes the write-in type that each position corresponds to parameter in the tuple;
The parameter extraction unit obtains out phase suitable for corresponding to the write-in type of parameter according to each position in the tuple Answer the parameter of position.
Optionally, the parameter extraction unit is suitable for determining said write type institute according to preset fuzzy matching rule Matched taking-up type;According to it is matched take out type take out corresponding position parameter;In the fuzzy matching rule, one A taking-up type corresponds to one or more write-in types.
According to the present invention in another aspect, providing a kind of intelligent terminal, comprising: processor;And it is arranged to store The memory of computer executable instructions, the executable instruction execute the processor such as any of the above-described institute The method stated.
According to the present invention in another aspect, providing a kind of computer readable storage medium, wherein it is described computer-readable Storage medium stores one or more programs, and one or more of programs when being executed by a processor, are realized as any of the above-described The method.
It can be seen from the above, technical solution of the present invention utilizes preset Parameter Switch after getting parameter to be processed Several parameters are stored as universal class object by template, and obtain universal class letter corresponding with the universal class object Breath, in parameter in use, universal class information is passed to parameter recipient, is obtained by parameter recipient according to universal class information Take several parameters.The beneficial effect of the technical solution is, by that can support any in Parameter Switch template theory Any type of parameter of number does not need to carry out serializing and unserializing processing, and fool proof, more efficient.
The above description is only an overview of the technical scheme of the present invention, in order to better understand the technical means of the present invention, And it can be implemented in accordance with the contents of the specification, and in order to allow above and other objects of the present invention, feature and advantage can It is clearer and more comprehensible, the followings are specific embodiments of the present invention.
Detailed description of the invention
By reading the following detailed description of the preferred embodiment, various other advantages and benefits are common for this field Technical staff will become clear.The drawings are only for the purpose of illustrating a preferred embodiment, and is not considered as to the present invention Limitation.And throughout the drawings, the same reference numbers will be used to refer to the same parts.In the accompanying drawings:
Fig. 1 shows a kind of flow diagram of parameter processing method according to an embodiment of the invention;
Fig. 2 shows the flow diagrams of another parameter processing method according to an embodiment of the invention;
Fig. 3 shows a kind of structural schematic diagram of parameter processing apparatus according to an embodiment of the invention;
Fig. 4 shows a kind of structural schematic diagram of parameter processing apparatus according to an embodiment of the invention;
Fig. 5 shows the structural schematic diagram of intelligent terminal according to an embodiment of the invention;
Fig. 6 shows the structural schematic diagram of computer readable storage medium according to an embodiment of the invention.
Specific embodiment
Exemplary embodiments of the present disclosure are described in more detail below with reference to accompanying drawings.Although showing the disclosure in attached drawing Exemplary embodiment, it being understood, however, that may be realized in various forms the disclosure without should be by embodiments set forth here It is limited.On the contrary, these embodiments are provided to facilitate a more thoroughly understanding of the present invention, and can be by the scope of the present disclosure It is fully disclosed to those skilled in the art.
Fig. 1 shows a kind of flow diagram of parameter processing method according to an embodiment of the invention.Such as Fig. 1 institute Show, this method comprises:
Step S110 obtains several parameters to be processed.In one embodiment of the invention, in the above method, ginseng Number includes as follows one or more: fundamental type object, lambda expression formula, pointer, intelligent pointer, generic function.It is practical Upper manageable parameter is will not enumerate herein there are also very much.
Several parameters are stored as universal class object, obtained by step S120 according to preset Parameter Switch template Universal class information corresponding with the universal class object.
Universal class information is passed to parameter recipient, by parameter recipient according to universal class information by step S130 Obtain several parameters.
In this way, parameter recipient only needs to receive a universal class information, design is simple;And when using parameter, Parameter ready for use is extracted from universal class object, it is high-efficient, and ensure that the safety that data use.
As it can be seen that method shown in FIG. 1, after getting parameter to be processed, using preset Parameter Switch template, by this Several parameters are stored as universal class object, and obtain universal class information corresponding with the universal class object, in parameter In use, universal class information is passed to parameter recipient, by parameter recipient, according to universal class acquisition of information, this is several A parameter.The beneficial effect of the technical solution is, by that can support any class of any number in Parameter Switch template theory The parameter of type does not need to carry out serializing and unserializing processing, and fool proof, more efficient.
In one embodiment of the invention, in the above method, preset Parameter Switch template includes empty parameter packaging Base class, and the derived class according to the template template parameter packaging base class realized;According to preset Parameter Switch template, Several parameters are stored as universal class object, obtaining universal class information corresponding with the universal class object includes: Derivation class object corresponding with several parameters is generated according to derived class construction, obtains base class corresponding with the derivation class object Pointer.
That is, the type of parameter script has been carried out type erasing, by the base class pointer of derivation class object institute assignment Do not carry type information.It only needs to transmit a base class pointer when passing ginseng, derives from class object without transmitting, taking When ginseng, the parameter derived from class object is obtained further according to base class pointer.
In one embodiment of the invention, it in the above method, is generated and several parameters pair according to derived class construction The derivation class object answered includes: to be packed according to the parameter packing method in derived class to several parameters.Namely It says, either how many a parameters, it can be by being packaged to be a derivation class object.
Realizing for parameter packing method can be realized by the std::tuple that C++11 is provided.I.e. of the invention one In a embodiment, in the above method, according to the parameter packing method in derived class, which is carried out include: A tuple is created according to the variable element template in parameter packing method, which is written in tuple.
For example, parameter packaging base class is CParaWrapper:
class CParaWrapper;
Derived class is CparaWrapperT:
template<typename...Args>
class CParaWrapperT:public CParaWrapper
{
std::tuple<Args...>m_tuple;
}
It is generated when construction and derives from class object:
CParaWrapperT(Args2&&...args):m_tuple(std::forward<Args2>(args)...){}
Here with variable element template support any type, any number parameter the characteristics of.
In one embodiment of the invention, it in the above method, is created according to the variable element template in parameter packing method It builds a tuple and comprises determining that the index information of several parameters in tuple.
Here, since base class pointer does not store parameter, the type of parameter is not stored yet, and all information is in derived class pair As middle record, wherein needing to be arranged an index information, in order to not obscure when taking out parameter to define in each position Storage is all those parameters.
For example, in one embodiment of the invention, in the above method, index information includes the corresponding ginseng of each position in tuple Several write-in types.In this way, when parameter recipient needs using parameter writing for parameter can be corresponded to according to each position in tuple Enter type, obtains out the parameter of corresponding position.
In one embodiment of the invention, it in the above method, is generated and several parameters pair according to derived class construction The derivation class object answered includes: when the quantity of parameter to be processed is for the moment, to judge whether the type of the parameter belongs to default class Type;It is to store the parameter in the memory headroom of derived class application, otherwise applies new memory headroom for storing the parameter.
The number of parameters actually to be transmitted in many cases is fixed, but type is not fixed, in this case past It is also a parameter toward what is transmitted.Specialization processing, specifically, Ke Yijie have been carried out to such case in the present embodiment About space improves efficiency.
Here the class type that preset kind can be scalar type, support r value construction, size are not more than 8 bytes (sizeof≤8).When storing the parameter of these types, need to store the virtual table of 4 bytes, the base of 4 bytes in derived class Class pointer, the at most parameter of 8 bytes.And due to being contemplated that memory is aligned, then virtual table, base class pointer are respectively necessary for 4 The space of byte carries out memory alignment, produces waste.Therefore in one embodiment of the invention, in the above method, derive from The memory headroom of class application is divided into three regions in order, sequentially for storing virtual table, base class pointer and parameter.
Here, for preset kind, the method for first using placement new stores parameter in allocated space, The memory headroom of derived class application is divided into three regions in order without additionally applying for new memory headroom, while again, sequentially Store virtual table, base class pointer and parameter.In this way virtual table, base class pointer totally 8 bytes do not need memory alignment, just Save the space of 8 bytes.
In this way, if for virtual table not being empty, the method for illustrating to have used placement new, allocated Parameter is stored in space, if virtual table is sky, base class pointer is not sky, illustrate without using placement new, but it is new Memory headroom is applied for.If the two is all sky, illustrate no value.
In one embodiment of the invention, in the above method, parameter recipient be Observer Pattern in observer or The pending function of person.Often an observer will receive the message that multiple observed persons send, these message packages to Observer Pattern The parameter contained can be diversified, and the parameter that pending function is relied on also tends to be that demand is changeable.
Fig. 2 shows the flow diagrams of another parameter processing method according to an embodiment of the invention.Such as Fig. 2 institute Show, this method comprises:
Step S210 obtains universal class information corresponding with universal class object, wherein universal class object is stored with Several parameters.
Step S220 takes out target component from universal class object by specified type according to universal class information.
This method describes how to take out target component from the angle of parameter recipient.As can be seen that being still only needs A universal class object is obtained, can also be taken according to specified type in value, flexibly and easily.
In one embodiment of the invention, in the above method, universal class object is according to preset Parameter Switch mould What plate generated, preset Parameter Switch template includes empty parameter packaging base class, and is somebody's turn to do according to what template template was realized The derived class of parameter packaging base class;Universal class object is specially the derivation class object generated according to derived class construction, general class Type information is base class pointer corresponding with the derived class.These are similar with preceding method, and details are not described herein.
In one embodiment of the invention, in the above method, universal class object includes storing several parameters The index information of tuple and tuple;According to universal class information, target component is taken out from universal class object by specified type Include: that the parameter inherited in derived class obtains Virtual Function, takes out corresponding ginseng from tuple according to base class pointer and index information Number.
In conjunction with previous example, in parameter storage, CParaWrapper*p=CParaWrapper::New (11,22), Parameter 11 and 22 stores for derived class object, and base class pointer p is passed to parameter recipient.Parameter recipient take out when, Int n=p->GetValue<int>(0), can return to 11.
In one embodiment of the invention, in the above method, index information include in tuple each position correspond to parameter Type is written;It from corresponding parameter is taken out in tuple include: according to each position pair in tuple according to base class pointer and index information The write-in type for answering parameter, obtains out the parameter of corresponding position.
In this example, what kind of parameter is written, so that it may what kind of parameter is taken out, this is because in rope Fuse breath acceptance of the bid is poured in the write-in type that each position corresponds to parameter, in fact, can also be with more more flexible when taking out parameter, example It is such as stored in an int shape parameter, a long shape parameter can be taken out.
Therefore in one embodiment of the invention, in the above method, the write-in of parameter is corresponded to according to each position in tuple Type, the parameter for obtaining out corresponding position include: to determine the matched taking-up of write-in type institute according to preset fuzzy matching rule Type;According to it is matched take out type take out corresponding position parameter;In fuzzy matching rule, a taking-up type is corresponding Type is written in one or more.
In addition, multilevel-pointer can also be removed in fuzzy matching rule other than the example as int type, the long type CV, Multidimensional numerical is switched into multilevel-pointer etc..
Fig. 3 shows a kind of structural schematic diagram of parameter processing apparatus according to an embodiment of the invention.Such as Fig. 3 institute Show, parameter processing apparatus 300 includes:
Parameter acquiring unit 310, suitable for obtaining several parameters to be processed.In one embodiment of the invention, on It states in device, parameter includes following one or more: fundamental type object, lambda expression formula, pointer, intelligent pointer, general Pass function.The parameter that can actually be handled is will not enumerate herein there are also very much.
Parameter processing unit 320 is suitable for that several parameters are stored as general class according to preset Parameter Switch template Type object obtains universal class information corresponding with the universal class object.
Parameter transfer unit 330, suitable for universal class information is passed to parameter recipient, by parameter recipient according to logical Several parameters are obtained with type information.
In this way, parameter recipient only needs to receive a universal class information, design is simple;And when using parameter, Parameter ready for use is extracted from universal class object, it is high-efficient, and ensure that the safety that data use.
As it can be seen that device shown in Fig. 3, after getting parameter to be processed, using preset Parameter Switch template, by this Several parameters are stored as universal class object, and obtain universal class information corresponding with the universal class object, in parameter In use, universal class information is passed to parameter recipient, by parameter recipient, according to universal class acquisition of information, this is several A parameter.The beneficial effect of the technical solution is, by that can support any class of any number in Parameter Switch template theory The parameter of type does not need to carry out serializing and unserializing processing, and fool proof, more efficient.
In one embodiment of the invention, in above-mentioned apparatus, preset Parameter Switch template includes empty parameter packaging Base class, and the derived class according to the template template parameter packaging base class realized;Parameter processing unit 320 is suitable for root Derivation class object corresponding with several parameters is generated according to derived class construction, base class corresponding with the derivation class object is obtained and refers to Needle.
That is, the type of parameter script has been carried out type erasing, by the base class pointer of derivation class object institute assignment Do not carry type information.It only needs to transmit a base class pointer when passing ginseng, derives from class object without transmitting, taking When ginseng, the parameter derived from class object is obtained further according to base class pointer.
In one embodiment of the invention, in above-mentioned apparatus, parameter processing unit 320, suitable for according in derived class Parameter packing method packs several parameters.
That is, either how many a parameters, it can be by being packaged to be a derivation class object.
Realizing for parameter packing method can be realized by the std::tuple that C++11 is provided.I.e. of the invention one In a embodiment, in above-mentioned apparatus, parameter processing unit 320, suitable for being created according to the variable element template in parameter packing method A tuple is built, which is written in tuple.
For example, parameter packaging base class is CParaWrapper:
class CParaWrapper;
Derived class is CparaWrapperT:
template<typename...Args>
class CParaWrapperT:public CParaWrapper
{
std::tuple<Args...>m_tuple;
}
It is generated when construction and derives from class object:
CParaWrapperT(Args2&&...args):m_tuple(std::forward<Args2>(args)...){}
Here with variable element template support any type, any number parameter the characteristics of.
In one embodiment of the invention, in above-mentioned apparatus, parameter processing unit 320 is adapted to determine that several ginsengs Index information of the number in tuple.
Here, since base class pointer does not store parameter, the type of parameter is not stored yet, and all information is in derived class pair As middle record, wherein needing to be arranged an index information, in order to not obscure when taking out parameter to define in each position Storage is all those parameters.
For example, in one embodiment of the invention, in above-mentioned apparatus, index information includes the corresponding ginseng of each position in tuple Several write-in types.In this way, when parameter recipient needs using parameter writing for parameter can be corresponded to according to each position in tuple Enter type, obtains out the parameter of corresponding position.
In one embodiment of the invention, in above-mentioned apparatus, parameter processing unit 320, suitable for working as parameter to be processed Quantity be for the moment, judge whether the type of the parameter belongs to preset kind;It is to be deposited in the memory headroom of derived class application The parameter is stored up, otherwise applies new memory headroom for storing the parameter.
The number of parameters actually to be transmitted in many cases is fixed, but type is not fixed, in this case past It is also a parameter toward what is transmitted.Specialization processing, specifically, Ke Yijie have been carried out to such case in the present embodiment About space improves efficiency.
Here the class type that preset kind can be scalar type, support r value construction, size are not more than 8 bytes (sizeof≤8).When storing the parameter of these types, need to store the virtual table of 4 bytes, the base of 4 bytes in derived class Class pointer, the at most parameter of 8 bytes.And due to being contemplated that memory is aligned, then virtual table, base class pointer are respectively necessary for 4 The space of byte carries out memory alignment, produces waste.Therefore in one embodiment of the invention, in above-mentioned apparatus, derive from The memory headroom of class application is divided into three regions in order, sequentially for storing virtual table, base class pointer and parameter.
Here, for preset kind, the method for first using placement new stores parameter in allocated space, The memory headroom of derived class application is divided into three regions in order without additionally applying for new memory headroom, while again, sequentially Store virtual table, base class pointer and parameter.In this way virtual table, base class pointer totally 8 bytes do not need memory alignment, just Save the space of 8 bytes.
In this way, if for virtual table not being empty, the method for illustrating to have used placement new, allocated Parameter is stored in space, if virtual table is sky, base class pointer is not sky, illustrate without using placement new, but it is new Memory headroom is applied for.If the two is all sky, illustrate no value.
In one embodiment of the invention, in above-mentioned apparatus, parameter recipient be Observer Pattern in observer or The pending function of person.Often an observer will receive the message that multiple observed persons send, these message packages to Observer Pattern The parameter contained can be diversified, and the parameter that pending function is relied on also tends to be that demand is changeable.
Fig. 4 shows a kind of structural schematic diagram of parameter processing apparatus according to an embodiment of the invention.Such as Fig. 4 institute Show, parameter processing apparatus 400 includes:
Universal class information acquisition unit 410 is suitable for obtaining universal class information corresponding with universal class object, In, universal class object is stored with several parameters.
Parameter extraction unit 420 is suitable for taking out mesh from universal class object by specified type according to universal class information Mark parameter.
Here it describes how to take out target component from the angle of parameter recipient.It only needs to obtain as can be seen that being still A universal class object is taken, can also be taken according to specified type in value, flexibly and easily.
In one embodiment of the invention, in above-mentioned apparatus, universal class object is according to preset Parameter Switch mould What plate generated, preset Parameter Switch template includes empty parameter packaging base class, and is somebody's turn to do according to what template template was realized The derived class of parameter packaging base class;Universal class object is specially the derivation class object generated according to derived class construction, general class Type information is base class pointer corresponding with the derived class.These are similar with previous embodiment, and details are not described herein.
In one embodiment of the invention, in above-mentioned apparatus, universal class object includes storing several parameters The index information of tuple and tuple;Parameter extraction unit 420, the parameter suitable for inheriting in derived class obtains Virtual Function, according to base Class pointer and index information take out corresponding parameter from tuple.
In conjunction with previous example, in parameter storage, CParaWrapper*p=CParaWrapper::New (11,22), Parameter 11 and 22 stores for derived class object, and base class pointer p is passed to parameter recipient.Parameter recipient take out when, Int n=p->GetValue<int>(0), can return to 11.
In one embodiment of the invention, in above-mentioned apparatus, index information include in tuple each position correspond to parameter Type is written;Parameter extraction unit 420 obtains out corresponding positions suitable for corresponding to the write-in type of parameter according to each position in tuple The parameter set.
In this example, what kind of parameter is written, so that it may what kind of parameter is taken out, this is because in rope Fuse breath acceptance of the bid is poured in the write-in type that each position corresponds to parameter, in fact, can also be with more more flexible when taking out parameter, example It is such as stored in an int shape parameter, a long shape parameter can be taken out.
Therefore in one embodiment of the invention, in above-mentioned apparatus, parameter extraction unit 420 is suitable for according to preset Fuzzy matching rule determines the matched taking-up type of write-in type institute;According to matched type of taking out take out corresponding position Parameter;In fuzzy matching rule, a taking-up type corresponds to one or more write-in types.
In addition, multilevel-pointer can also be removed in fuzzy matching rule other than the example as int type, the long type CV, Multidimensional numerical is switched into multilevel-pointer etc..
In conclusion technical solution of the present invention utilizes preset Parameter Switch mould after getting parameter to be processed Several parameters are stored as universal class object by plate, and obtain universal class information corresponding with the universal class object, In parameter in use, universal class information is passed to parameter recipient, by parameter recipient according to universal class acquisition of information Several parameters.The beneficial effect of the technical solution is, by that can support any number in Parameter Switch template theory Any type of parameter does not need to carry out serializing and unserializing processing, and fool proof, more efficient.
It should be understood that
Algorithm and display be not inherently related to any certain computer, virtual bench or other equipment provided herein. Various fexible units can also be used together with teachings based herein.As described above, it constructs required by this kind of device Structure be obvious.In addition, the present invention is also not directed to any particular programming language.It should be understood that can use various Programming language realizes summary of the invention described herein, and the description done above to language-specific is to disclose this hair Bright preferred forms.
In the instructions provided here, numerous specific details are set forth.It is to be appreciated, however, that implementation of the invention Example can be practiced without these specific details.In some instances, well known method, structure is not been shown in detail And technology, so as not to obscure the understanding of this specification.
Similarly, it should be understood that in order to simplify the disclosure and help to understand one or more of the various inventive aspects, Above in the description of exemplary embodiment of the present invention, each feature of the invention is grouped together into single implementation sometimes In example, figure or descriptions thereof.However, the disclosed method should not be interpreted as reflecting the following intention: i.e. required to protect Shield the present invention claims features more more than feature expressly recited in each claim.More precisely, as following Claims reflect as, inventive aspect is all features less than single embodiment disclosed above.Therefore, Thus the claims for following specific embodiment are expressly incorporated in the specific embodiment, wherein each claim itself All as a separate embodiment of the present invention.
Those skilled in the art will understand that can be carried out adaptively to the module in the equipment in embodiment Change and they are arranged in one or more devices different from this embodiment.It can be the module or list in embodiment Member or component are combined into a module or unit or component, and furthermore they can be divided into multiple submodule or subelement or Sub-component.Other than such feature and/or at least some of process or unit exclude each other, it can use any Combination is to all features disclosed in this specification (including adjoint claim, abstract and attached drawing) and so disclosed All process or units of what method or apparatus are combined.Unless expressly stated otherwise, this specification is (including adjoint power Benefit require, abstract and attached drawing) disclosed in each feature can carry out generation with an alternative feature that provides the same, equivalent, or similar purpose It replaces.
In addition, it will be appreciated by those of skill in the art that although some embodiments described herein include other embodiments In included certain features rather than other feature, but the combination of the feature of different embodiments mean it is of the invention Within the scope of and form different embodiments.For example, in the following claims, embodiment claimed is appointed Meaning one of can in any combination mode come using.
Various component embodiments of the invention can be implemented in hardware, or to run on one or more processors Software module realize, or be implemented in a combination thereof.It will be understood by those of skill in the art that can be used in practice Microprocessor or digital signal processor (DSP) come realize some in parameter processing apparatus according to an embodiment of the present invention or The some or all functions of person's whole component.The present invention is also implemented as one for executing method as described herein Point or whole device or device programs (for example, computer program and computer program product).Such this hair of realization Bright program can store on a computer-readable medium, or may be in the form of one or more signals.It is such Signal can be downloaded from an internet website to obtain, and is perhaps provided on the carrier signal or is provided in any other form.
For example, Fig. 5 shows the structural schematic diagram of intelligent terminal according to an embodiment of the invention.The intelligent terminal packet It includes processor 510 and is arranged to the memory 520 of storage computer executable instructions (computer readable program code).Storage Device 520 can be such as flash memory, EEPROM (electrically erasable programmable read-only memory), EPROM, hard disk or ROM etc Electronic memory.Memory 520 has the computer-readable program stored for executing any method and step in the above method The memory space 530 of code 531.For example, the memory space 530 for storing computer readable program code may include difference For realizing each computer readable program code 531 of the various steps in above method.Computer readable program code 531 can read or be written to the production of this one or more computer program from one or more computer program product In product.These computer program products include such as hard disk, and the program code of compact-disc (CD), storage card or floppy disk etc carries Body.Such computer program product is usually computer readable storage medium described in such as Fig. 6.Fig. 6 is shown according to this A kind of structural schematic diagram of the computer readable storage medium of invention one embodiment.The computer readable storage medium 600 is deposited The computer readable program code 531 for executing steps of a method in accordance with the invention is contained, it can be by the place of intelligent terminal 500 It manages device 510 to read, when computer readable program code 531 is run by intelligent terminal 500, the intelligent terminal 500 is caused to execute Each step in method described above, specifically, the computer-readable journey of the computer-readable recording medium storage Sequence code 531 can execute method shown in any of the above-described embodiment.Computer readable program code 531 can be with appropriate shape Formula is compressed.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and ability Field technique personnel can be designed alternative embodiment without departing from the scope of the appended claims.In the claims, Any reference symbol between parentheses should not be configured to limitations on claims.Word "comprising" does not exclude the presence of not Element or step listed in the claims.Word "a" or "an" located in front of the element does not exclude the presence of multiple such Element.The present invention can be by means of including the hardware of several different elements and being come by means of properly programmed computer real It is existing.In the unit claims listing several devices, several in these devices can be through the same hardware branch To embody.The use of word first, second, and third does not indicate any sequence.These words can be explained and be run after fame Claim.
Embodiment of the invention discloses A1, a kind of parameter processing method, comprising:
Obtain several parameters to be processed;
According to preset Parameter Switch template, which is stored as universal class object, is obtained general with this The corresponding universal class information of type object;
The universal class information is passed into parameter recipient, is believed by the parameter recipient according to the universal class Breath obtains several parameters.
A2, method as described in a1, wherein the parameter includes following one or more:
Fundamental type object, lambda expression formula, pointer, intelligent pointer, generic function.
A3, method as described in a1, wherein the preset Parameter Switch template includes empty parameter packaging base class, with And the derived class according to the template template parameter packaging base class realized;
It is described that several parameters are stored as by universal class object according to preset Parameter Switch template, it obtains and is somebody's turn to do The corresponding universal class information of universal class object includes:
Derivation class object corresponding with several parameters is generated according to derived class construction, is obtained and the derived class pair As corresponding base class pointer.
A4, the method as described in A3, wherein described corresponding with several parameters according to derived class construction generation Deriving from class object includes:
According to the parameter packing method in the derived class, which is packed.
A5, the method as described in A4, wherein the parameter packing method according in the derived class, to this several Parameter carries out
A tuple is created according to the variable element template in the parameter packing method, which is written into institute It states in tuple.
A6, method as described in a5, wherein the variable element template creation one according in the parameter packing method A tuple comprises determining that the index information of several parameters in the tuple.
A7, the method as described in A6, wherein the index information includes the write-in that each position corresponds to parameter in the tuple Type.
A8, the method as described in A3, wherein described corresponding with several parameters according to derived class construction generation Deriving from class object includes:
When the quantity of parameter to be processed is for the moment, to judge whether the type of the parameter belongs to preset kind;
It is to store the parameter in the memory headroom of the derived class application, otherwise applies new memory headroom for depositing Store up the parameter.
A9, the method as described in A8, wherein the memory headroom of the derived class application is divided into three regions in order, according to Sequence is for storing virtual table, base class pointer and parameter.
A10, the method as described in any one of A1-A9, wherein the parameter recipient is the observation in Observer Pattern Person or pending function.
The embodiment of the present invention also discloses B11, a kind of parameter processing method, comprising:
Obtain universal class information corresponding with universal class object, wherein the universal class object is stored with several A parameter;
According to the universal class information, target component is taken out from the universal class object by specified type.
B12, method as described in b11, wherein the universal class object is according to preset Parameter Switch template generation , the preset Parameter Switch template includes empty parameter packaging base class, and the ginseng realized according to template template The derived class of number packaging base class;
The universal class object is specially the derivation class object generated according to derived class construction, the universal class Information is base class pointer corresponding with the derived class.
B13, as described in B12 method, wherein the universal class object include store several parameters tuple and The index information of tuple;
It is described according to the universal class information, target component packet is taken out from the universal class object by specified type It includes: inheriting parameter in the derived class and obtain Virtual Function, according to the base class pointer and the index information from the tuple It is middle to take out corresponding parameter.
B14, the method as described in B13, wherein the index information include in the tuple each position correspond to writing for parameter Enter type;
It is described according to the base class pointer and the index information taken out from the tuple corresponding parameter include: according to Each position corresponds to the write-in type of parameter in the tuple, obtains out the parameter of corresponding position.
B15, the method as described in B14, wherein the write-in type that parameter is corresponded to according to each position in the tuple, The parameter for obtaining out corresponding position includes:
According to preset fuzzy matching rule, the matched taking-up type of said write type institute is determined;
According to it is matched take out type take out corresponding position parameter;
In the fuzzy matching rule, a taking-up type corresponds to one or more write-in types.
The embodiment of the present invention also discloses C16, a kind of parameter processing apparatus, comprising:
Parameter acquiring unit, suitable for obtaining several parameters to be processed;
Parameter processing unit is suitable for that several parameters are stored as universal class according to preset Parameter Switch template Object obtains universal class information corresponding with the universal class object;
Parameter transfer unit, suitable for the universal class information is passed to parameter recipient, by the parameter recipient According to the universal class acquisition of information several parameters.
C17, the device as described in C16, wherein the parameter includes following one or more:
Fundamental type object, lambda expression formula, pointer, intelligent pointer, generic function.
C18, the device as described in C16, wherein the preset Parameter Switch template includes empty parameter packaging base class, And the derived class according to the template template parameter packaging base class realized;
The parameter processing unit is suitable for generating derived class corresponding with several parameters according to derived class construction Object obtains base class pointer corresponding with the derivation class object.
C19, the device as described in C18, wherein
The parameter processing unit, suitable for according to the parameter packing method in the derived class, to several parameters into Row packaging.
C20, the device as described in C19, wherein
The parameter processing unit, suitable for creating a member according to the variable element template in the parameter packing method Several parameters are written in the tuple group.
C21, the device as described in C20, wherein
The parameter processing unit is adapted to determine that the index information of several parameters in the tuple.
C22, the device as described in C21, wherein the index information include in the tuple each position correspond to writing for parameter Enter type.
C23, the device as described in C18, wherein
The parameter processing unit, suitable for when parameter to be processed quantity be for the moment, judge the parameter type whether Belong to preset kind;It is to store the parameter in the memory headroom of the derived class application, otherwise apply for new memory headroom For storing the parameter.
C24, the device as described in C23, wherein the memory headroom of the derived class application is divided into three regions in order, Sequentially for storing virtual table, base class pointer and parameter.
C25, the device as described in any one of C16-C24, wherein the parameter recipient is the sight in Observer Pattern The person of examining or pending function.
The embodiment of the present invention also discloses D26, a kind of parameter processing apparatus, comprising:
Universal class information acquisition unit is suitable for obtaining universal class information corresponding with universal class object, wherein institute It states universal class object and is stored with several parameters;
Parameter extraction unit is suitable for according to the universal class information, by specified type from the universal class object Take out target component.
D27, the device as described in D26, wherein the universal class object is according to preset Parameter Switch template generation , the preset Parameter Switch template includes empty parameter packaging base class, and the ginseng realized according to template template The derived class of number packaging base class;
The universal class object is specially the derivation class object generated according to derived class construction, the universal class Information is base class pointer corresponding with the derived class.
D28, the device as described in D27, wherein the universal class object include store several parameters tuple and The index information of tuple;
The parameter extraction unit, the parameter suitable for inheriting in the derived class obtain Virtual Function, are referred to according to the base class Needle and the index information take out corresponding parameter from the tuple.
D29, the device as described in D28, wherein the index information include in the tuple each position correspond to writing for parameter Enter type;
The parameter extraction unit obtains out phase suitable for corresponding to the write-in type of parameter according to each position in the tuple Answer the parameter of position.
D30, the device as described in D29, wherein
The parameter extraction unit is suitable for determining that said write type institute is matched according to preset fuzzy matching rule Take out type;According to it is matched take out type take out corresponding position parameter;In the fuzzy matching rule, a taking-up Type corresponds to one or more write-in types.
The embodiment of the present invention also discloses E31, a kind of intelligent terminal, wherein the intelligent terminal includes: processor;With And it is arranged to the memory of storage computer executable instructions, the executable instruction when executed holds the processor Method of the row as described in any one of A1-A10, alternatively, executing the method as described in any one of B11-B15.
The embodiment of the present invention also discloses F32, a kind of computer readable storage medium, wherein described computer-readable Storage medium stores one or more programs, and one or more of programs when being executed by a processor, are realized as in A1-A10 Described in any item methods, alternatively, realizing the method as described in any one of A11-A15.

Claims (10)

1. a kind of parameter processing method, comprising:
Obtain several parameters to be processed;
According to preset Parameter Switch template, which is stored as universal class object, is obtained and the universal class The corresponding universal class information of object;
The universal class information is passed into parameter recipient, is obtained by the parameter recipient according to the universal class information Take several parameters.
2. the method for claim 1, wherein the parameter includes following one or more:
Fundamental type object, lambda expression formula, pointer, intelligent pointer, generic function.
3. a kind of parameter processing method, comprising:
Obtain universal class information corresponding with universal class object, wherein the universal class object is stored with several ginsengs Number;
According to the universal class information, target component is taken out from the universal class object by specified type.
4. method as claimed in claim 3, wherein the universal class object is according to preset Parameter Switch template generation , the preset Parameter Switch template includes empty parameter packaging base class, and the ginseng realized according to template template The derived class of number packaging base class;
The universal class object is specially the derivation class object generated according to derived class construction, the universal class information For base class pointer corresponding with the derived class.
5. a kind of parameter processing apparatus, comprising:
Parameter acquiring unit, suitable for obtaining several parameters to be processed;
Parameter processing unit is suitable for that several parameters are stored as universal class object according to preset Parameter Switch template, Obtain universal class information corresponding with the universal class object;
Parameter transfer unit, suitable for the universal class information is passed to parameter recipient, by the parameter recipient according to The universal class acquisition of information several parameters.
6. device as claimed in claim 5, wherein the parameter includes following one or more:
Fundamental type object, lambda expression formula, pointer, intelligent pointer, generic function.
7. a kind of parameter processing apparatus, comprising:
Universal class information acquisition unit is suitable for obtaining universal class information corresponding with universal class object, wherein described logical Several parameters are stored with type object;
Parameter extraction unit is suitable for being taken out from the universal class object according to the universal class information by specified type Target component.
8. device as claimed in claim 7, wherein the universal class object is according to preset Parameter Switch template generation , the preset Parameter Switch template includes empty parameter packaging base class, and the ginseng realized according to template template The derived class of number packaging base class;
The universal class object is specially the derivation class object generated according to derived class construction, the universal class information For base class pointer corresponding with the derived class.
9. a kind of intelligent terminal, wherein the intelligent terminal includes: processor;And it is arranged to the executable finger of storage computer The memory of order, the executable instruction execute the processor as described in any one of claim 1-2 Method, alternatively, the method as described in any one of claim 3-4 of execution.
10. a kind of computer readable storage medium, wherein the computer-readable recording medium storage one or more program, One or more of programs when being executed by a processor, realize such as method of any of claims 1-2, alternatively, Realize the method as described in any one of claim 3-4.
CN201810646530.1A 2018-06-21 2018-06-21 Parameter processing method and device Active CN108932123B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810646530.1A CN108932123B (en) 2018-06-21 2018-06-21 Parameter processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810646530.1A CN108932123B (en) 2018-06-21 2018-06-21 Parameter processing method and device

Publications (2)

Publication Number Publication Date
CN108932123A true CN108932123A (en) 2018-12-04
CN108932123B CN108932123B (en) 2022-03-11

Family

ID=64446846

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810646530.1A Active CN108932123B (en) 2018-06-21 2018-06-21 Parameter processing method and device

Country Status (1)

Country Link
CN (1) CN108932123B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111610943A (en) * 2020-06-11 2020-09-01 上海乾臻信息科技有限公司 Method, device and system for managing and using panel board
CN112306472A (en) * 2020-10-27 2021-02-02 深圳市元征科技股份有限公司 Program interface parameter transmission method, system and related equipment
CN116400988A (en) * 2023-06-08 2023-07-07 中航信移动科技有限公司 Target parameter returning method, storage medium and electronic equipment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7010615B1 (en) * 1999-11-12 2006-03-07 Fujitsu Limited Communication network management system for automatically converting action parameters to network technology dependent parameters using a selected conversion rule conforming to a network technology
US20080163269A1 (en) * 2006-12-27 2008-07-03 Fujitsu Limited Remote procedure call system, remote procedure call method, program for implementing remote procedure call system
CN102981884A (en) * 2012-11-22 2013-03-20 用友软件股份有限公司 Serializing device and serializing method
CN103677790A (en) * 2012-09-26 2014-03-26 腾讯科技(深圳)有限公司 Software function modifying method
CN103914304A (en) * 2014-04-10 2014-07-09 国家电网公司 Method for converting different structure type parameters on basis of SAP (service access point) platforms
CN106775638A (en) * 2016-11-22 2017-05-31 北京皮尔布莱尼软件有限公司 A kind of object serialization method, device and computing device
CN107463668A (en) * 2017-08-02 2017-12-12 湖南新航动力信息科技有限公司 Serializing and method and device, computer equipment and the storage medium of unserializing

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7010615B1 (en) * 1999-11-12 2006-03-07 Fujitsu Limited Communication network management system for automatically converting action parameters to network technology dependent parameters using a selected conversion rule conforming to a network technology
US20080163269A1 (en) * 2006-12-27 2008-07-03 Fujitsu Limited Remote procedure call system, remote procedure call method, program for implementing remote procedure call system
CN103677790A (en) * 2012-09-26 2014-03-26 腾讯科技(深圳)有限公司 Software function modifying method
CN102981884A (en) * 2012-11-22 2013-03-20 用友软件股份有限公司 Serializing device and serializing method
CN103914304A (en) * 2014-04-10 2014-07-09 国家电网公司 Method for converting different structure type parameters on basis of SAP (service access point) platforms
CN106775638A (en) * 2016-11-22 2017-05-31 北京皮尔布莱尼软件有限公司 A kind of object serialization method, device and computing device
CN107463668A (en) * 2017-08-02 2017-12-12 湖南新航动力信息科技有限公司 Serializing and method and device, computer equipment and the storage medium of unserializing

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
王朋等: "O'Caml泛型编程中"泛型抽象"的研究", 《计算机技术与发展》 *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111610943A (en) * 2020-06-11 2020-09-01 上海乾臻信息科技有限公司 Method, device and system for managing and using panel board
CN112306472A (en) * 2020-10-27 2021-02-02 深圳市元征科技股份有限公司 Program interface parameter transmission method, system and related equipment
CN116400988A (en) * 2023-06-08 2023-07-07 中航信移动科技有限公司 Target parameter returning method, storage medium and electronic equipment
CN116400988B (en) * 2023-06-08 2023-08-11 中航信移动科技有限公司 Target parameter returning method, storage medium and electronic equipment

Also Published As

Publication number Publication date
CN108932123B (en) 2022-03-11

Similar Documents

Publication Publication Date Title
CN104461898B (en) Using the method for test, control server, test terminal and system
EP0772824B1 (en) Object-oriented operating system enhancement for filtering items in a window
US7331037B2 (en) Static memory allocation in a graphical programming system
CN108932123A (en) parameter processing method and device
US10303757B2 (en) Apparatuses, systems, and methods for providing a visual program for machine vision systems
CN108846264A (en) Code reinforcement means, device, intelligent terminal and computer readable storage medium
CN110134386A (en) A kind of program editing method and device
CN107133502B (en) A kind of processing method and processing device of application program
CN108984317A (en) The implementation method and device of interprocess communication IPC
CN104503778A (en) Installation method and installation device for applications
CN107153535A (en) A kind of operation ElasticSearch method and device
CN109598107A (en) A kind of code conversion method and device based on application installation package file
CN108875764A (en) Model training method, device, system and computer-readable medium
US20110225213A1 (en) Loop control flow diversion
CN112214256B (en) Machine learning operation control method and device, electronic equipment and storage medium
CN109933758A (en) Methods of exhibiting, device, electronic equipment and the computer readable storage medium of chart
US9552347B1 (en) Data grid cell styling systems and methods
CN108846265A (en) A kind of program reinforcement means and device
CN109725932A (en) A kind of application component illustrates document generation method and device
CN108829502A (en) The implementation method and device of threading operation
CN116501452B (en) Model processing method, simulation platform, electronic device and storage medium
CN108460276A (en) A kind for the treatment of method and apparatus of the dynamic link library SO files of Android installation kit
CN108846280A (en) The hulling method and device of application file
CN107885529A (en) The hook method and device of terminal applies
Hunt Recreating TOP in Golang

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant