+
Skip to content

Allow capitalized Serialize functions #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2014

Conversation

mattyclarkson
Copy link
Contributor

Currently cereal searches for serialize, load and save. If they could be made #defines, the user of the library could specify the name of the functions that cereal should be looking for.

#ifndef CEREAL_SERIALIZE_FUNCTION_NAME
#define CEREAL_SERIALIZE_FUNCTION_NAME serialize
#endif
#ifndef CEREAL_LOAD_FUNCTION_NAME
#define CEREAL_LOAD_FUNCTION_NAME load
#endif
#ifndef CEREAL_SAVE_FUNCTION_NAME
#define CEREAL_SAVE_FUNCTION_NAME save
#endif

This is because some styling guides require functions that are Capitalized and having Serialize, Load, Save would conform.

How do you guys feel about this? Is this something that would be acceptable to create a pull request for?

@mattyclarkson
Copy link
Contributor Author

Thinking about this it would be possible to have a trait for both capitalized and non-capitalized.

@Devacor
Copy link

Devacor commented Mar 6, 2014

I don't like the idea of adding both capitalized and non-capitalized, it seems clunky and heavy-handed.

I think defines for the function names as you originally suggest is fine, and allows users to override the default naming convention of cereal in a useful way to avoid potential name clashes (what if save/load are existing methods in some classes and you'd like to rename them all to cereal_load, cereal_save etc? Or CerealLoad, CerealSave, or cerealLoad, cerealSave etc.)

@mattyclarkson
Copy link
Contributor Author

I agree the define seems to make much more sense now. Do you want me to
make a patch?
On 6 Mar 2014 01:28, "M2tM" notifications@github.com wrote:

I don't like the idea of adding both capitalized and non-capitalized, it
seems clunky and heavy-handed.

I think defines for the function names as you originally suggest is fine,
and allows users to override the default naming convention of cereal in a
useful way to avoid potential name clashes (what if save/load are existing
methods in some classes and you'd like to rename them all to cereal_load,
cereal_save etc? Or CerealLoad, CerealSave, or cerealLoad, cerealSave etc.)


Reply to this email directly or view it on GitHubhttps://github.com//issues/60#issuecomment-36812064
.

@AzothAmmo
Copy link
Contributor

Discussed this with @randvoorhies and we're fine with patching this in as #define.

@AzothAmmo AzothAmmo added this to the v1.1.0 milestone Mar 9, 2014
@mattyclarkson
Copy link
Contributor Author

Back from holiday now, so will have a patch ready soon.

@mattyclarkson
Copy link
Contributor Author

I've patched this up. Created a new file macros.hpp because helpers.hpp was the lowest hanging fruit to have the macros in but it didn't seem right putting them in there. I'm happy to change this. Quite nice being able to look at the macros.hpp file to work out what you can customize, but that's up to you guys. Pretty sure I've caught all of the places that need to be converted but have a review and see if I've missed anything that you might know about.

The following preprocessor defines have been added:

 - CEREAL_SERIALIZE_FUNCTION_NAME
 - CEREAL_SAVE_FUNCTION_NAME
 - CEREAL_LOAD_FUNCTION_NAME

These defines specifiy the name of the cereal serialization/deserialization
functions so that they can be customised by users. This is especially useful if
the user would like to have capitialized function names.
@AzothAmmo
Copy link
Contributor

This looks pretty good - I'm working on adding a new serialization method, load/save_minimal, and will pull this in when that is getting wrapped up.

@AzothAmmo
Copy link
Contributor

Going to push out 1.0 pretty soon - this and most of the other issues you've brought up will be part of 1.1. After 1.0 goes out I'm going to take a short break before addressing anything else.

@mattyclarkson
Copy link
Contributor Author

Thanks, good work on getting 1.0.0 out and I look forward to 1.1.0 😄

@AzothAmmo
Copy link
Contributor

Merged into a new branch here: https://github.com/USCiLab/cereal/tree/mattyclarkson-capitalization.

Haven't done minimal functions yet.

Wondering if it is worth it to change the error messages to reference the defined names instead of our defaults.

@mattyclarkson
Copy link
Contributor Author

It would be a good touch, but if you are jumping in deep enough to be
changing the macros for the function names then you probably have invested
enough effort to understand when something goes wrong!
On 26 Mar 2014 21:55, "Shane Grant" notifications@github.com wrote:

Merged into a new branch here:
https://github.com/USCiLab/cereal/tree/mattyclarkson-capitalization.

Haven't done minimal functions yet.

Wondering if it is worth it to change the error messages to reference the
defined names instead of our defaults.


Reply to this email directly or view it on GitHubhttps://github.com//pull/60#issuecomment-38745224
.

@AzothAmmo
Copy link
Contributor

We'll see - if it makes the code look cluttered, and it probably would, I'll probably just leave the messages as they are now, given the point you made.

@mattyclarkson
Copy link
Contributor Author

OK, up to you ;) Thanks for merging this into a working branch.
On 26 Mar 2014 22:05, "Shane Grant" notifications@github.com wrote:

We'll see - if it makes the code look cluttered, and it probably would,
I'll probably just leave the messages as they are now, given the point you
made.


Reply to this email directly or view it on GitHubhttps://github.com//pull/60#issuecomment-38746270
.

AzothAmmo added a commit that referenced this pull request Mar 27, 2014
Also added some documentation to macros.hpp

relates #60
@AzothAmmo AzothAmmo merged commit e7f7692 into USCiLab:develop Apr 15, 2014
@mattyclarkson mattyclarkson deleted the capitalization branch August 7, 2014 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载