-
Notifications
You must be signed in to change notification settings - Fork 120
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
Interface design of simple unified access to json, xml, yaml, ini, etc. #259
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
common/stream.h
Outdated
}; | ||
|
||
// read until EOF | ||
ReadAll readall(size_t min_buf = 1024, size_t max_buf = 1024 * 1024 * 1024); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the param 'min_buf' necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case that you want it start from, say, 1MB, to avoid some unnecessary realloc()
common/simple_dom.h
Outdated
class RootNode; | ||
struct NodeWrapper; | ||
|
||
// the interface for internal implementations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be concealed for internal use and not disclosed externally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No,because it's also the binary interface.
common/simple_dom.h
Outdated
NodeWrapper get(size_t i) const { | ||
IF_RET({_node->get(i)}); | ||
} | ||
NodeWrapper get(str key) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the result if the get operation fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an NodeWrapper with nullptr pointer to node implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This requires a clear explanation and instructions for use.
common/simple_dom.h
Outdated
// even if they are equivalent in binary form. | ||
Node* parse(char* text, size_t size, int flags); | ||
|
||
inline Node* parse(IStream::ReadAll&& buf, int flags) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the Node meant for internal use? How come it's being used by users here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parse(...)->wrap()
// 3. returning a pointer (of Node) is more efficient than an object (of Document),
// even if they are equivalent in binary form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For users, it's a direct use after parsing, and calling wrap is a burden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It a problem. The returned NodeImpl* is not the type used by the user and users must first determine if the returned NodeImpl* is nullptr before calling wrap. it's best not to expose these to users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
common/simple_dom.h
Outdated
else return {}; | ||
|
||
// the interface for users | ||
struct NodeWrapper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For user use, it's better to be named as "Node". The original "Node" can be renamed to NodeBase or something else, and not be exposed externally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
with examples and tests to show the usage