[CXX-643] Beginner problems learning new v3 C++ driver API Created: 30/Jul/15 Updated: 07/Apr/23 Resolved: 10/Jan/16 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | API |
| Affects Version/s: | 0.2.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Eloise Destelle | Assignee: | Unassigned |
| Resolution: | Incomplete | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
ubuntu (14.04 current; standard g++) |
||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
I have had quite a few problems learning to use the new C++ driver. It's things like an apparent inconsistency in bsoncxx/builder/stream/document's handling of open/close document and open/close array, maybe missing overloaded append functions in stream-core, and a lack of clarity about handling types. I've found that I am having to use instances of type::b_document and types::b_array in ways that seem unnatural - but I couldn't find another way to get things to work. |
| Comments |
| Comment by Mira Carey [ 28/Aug/15 ] | ||||||||||||||||||||||||||||
|
Sorry for the slow turn around on this. It seems like the main problem you've run into is how to programatically manipulate the stream within one expression (as you've noted, ending the statement loses the type information and leads to slightly obtuse type errors). The stream interface is probably a bit too clever for it's own good here, but the solution is that a variety of callables can be passed. Consider the bsoncxx builder test:
Note that you can use Callable's that take a:
So, looking at your examples:
Considering finalize, what you're getting there is a conversion to a document::value, which is an owned buffer. Generally speaking, getting views of subdocs during construction is only sort of supported (views are invalidated by any operations and the bytes aren't really consistent depending on if subdocs are currently opened) The other thing you were seeing, where b_array and b_document show up, is mostly geared around aligning types with the reading api. It's for copying bytes in, rather than contiguously building in a reallocing buffer. Hope that helps, |