473,659 Members | 3,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

std::streambuf: :setp and std::streambuf: :epptr()

I am trying to empty and reset my internal buffer in my derived sync method.

Am I correct in assuming I can call setp( std::streambuf: :pbase(),
std::streambuf: :pbase()); to reset the internal buffer?

Also, I am unsure whether the pointer returned by epptr() is supposed to
point just beyond the end of the sequence or at the last element of the
sequence? As such, should the second argument to my setp call be
std::streambuf: :pbase() + 1?

Thanks. I've got a book on streams coming for Christmas by the way. Yay!
References on the topic seem to be scarce, yet it is such a huge topic. I
guess most people ignore it as much as they can.
Dec 12 '07 #1
1 2938
On Dec 12, 9:12 am, "Christophe r Pisz" <some...@somewh ere.netwrote:
I am trying to empty and reset my internal buffer in my
derived sync method.
Am I correct in assuming I can call setp( std::streambuf: :pbase(),
std::streambuf: :pbase()); to reset the internal buffer?
It depends on what you want to do. If you simply want to clear
the buffer, making sure that the next attempt to write will end
up calling overflow() (where presumably, you'll reinitialize
it), then setting both pointers to NULL is the simplest
solution. If you want to initialize a new (empty) buffer, the
first pointer should be the address of the buffer, and the
second the address one past the end of the buffer.
Also, I am unsure whether the pointer returned by epptr() is
supposed to point just beyond the end of the sequence or at
the last element of the sequence?
One past the end. epptr() - pbase() is the length of the
buffer.
As such, should the second argument to my setp call be
std::streambuf: :pbase() + 1?
That would provide a buffer of size 1.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2703
by: Fred Ma | last post by:
Hello, I posted previously under the thread: How to break this up into streambuf/ostream I've asked our library to get "C++ IOStreams and Locales..." by A. Langer et al. Meantime, I've looked at the C++ standard (ISO/IEC 14882) from the web to get a grip on the relationship between ostream methods and streambuf methods: flush(), operator<<(), sputc(),
6
1583
by: William Payne | last post by:
Hi, I have a function declared as: void foo(const std::string& s, std::ostream& verbose_output); I want foo() to write a lot of data to the ostream if it's a valid stream. If it's valid or not should depend on user input (command line arguments actually). If the user decides he/she wants verbose output, I will pass std::cout as the last argument when calling foo(). But what should I pass if the user doesn't want any output? And how...
1
2070
by: Peter Jansson | last post by:
Dear newsgroup, I have implemented a class that inherits from std::streambuf (in order to create a stream for some specialized I/O). In the constructor, I have the following code (bufferSize is a previously defined const unsigned int): char* p1=new char; std::streambuf::setg(p1,p1,p1+bufferSize); char* p2=new char; std::streambuf::setp(p2,p2+bufferSize);
7
9982
by: Lee | last post by:
Hi, I'm a stream virgin and am attempting to output strings to a file. My approach is to write the string initially to a 'stringstream' and only when complete write the stringstream to the file (ofstream). The process works fine however appears to be rather slow. For example outputting about 2Mb of data takes a couple of minutes (most of the time appears to be writing to the stringstream) and as I'm creating several hundred files in...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.