Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 877271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:34:45+00:00 2026-05-15T11:34:45+00:00

For an API that I am working on, I want to allow the user

  • 0

For an API that I am working on, I want to allow the user to insert custom objects into an ostream, but these objects have no meaning on their own, and are too memory constrained to include an additional pointer or reference for context. (Think tens of millions of 16-/32-/48-bit objects in an embedded system with limited memory.)

Suppose the user initializes the underlying context, and looks up one of these objects:

DDB ddb("xc5vlx330t");
Tilewire tw = ddb.lookUpTilewire("DSP_X34Y0", "DSP_IMUX_B5_3");
...
std::cout << complexDataStructure;

In an entirely different scope, possibly nested far away from the user’s explicit code, we may need to insert the object into an ostream, with ddb unavailable.

os << tw;

The actual value encapsulated by tw is 97,594,974, but the desired output is this:

DSP_IMUX_B5_3@[263,84] DSP "DSP_X34Y0" (1488@77406)

In order for this to work, the appropriate insertion operator would need access to ddb, but it cannot rely on static or global variables or functions (for multithreading reasons). What I’d like to do is allow the user to request and use a stream wrapper kind of like this:

ostream& wrappedCout = ddb.getWrappedOstream(std::cout);

The returned subclass of ostream would include a reference to ddb for use by special stream inserters that needed it, and a reference to the original stream—std::cout in this case—where it would forward all of its output.

Unfortunately, the inheritance or composition schemes that I have come up with are messy to code up (not an enormous concern), and possibly problematic for the user (a much larger concern). Any suggestions on how to elegantly make ddb available to insertion operators? I am marginally aware of boost.Iostreams, but not sure that it will help me out here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T11:34:46+00:00Added an answer on May 15, 2026 at 11:34 am

    Write a custom stream manipulator that stores a reference to ddb using the iword/pword mechanism. Here is an example, you’d need to add locking around the iwork_indexes map in a multithreaded program.

    class dbb
    {
    public:
        explicit dbb(int value) : m_value(value) {}
        int value() const { return m_value; }
    private:
        int m_value;
    };
    
    class dbb_reliant_type
    {
    public:
        dbb_reliant_type(const std::string& value) : m_value(value) {}
        const std::string& value() const { return m_value; }
    private:
        std::string m_value;
    };
    
    typedef std::map<std::ostream*, int> iword_map;
    iword_map iword_indexes;
    
    inline int get_iword_index(std::ostream& os)
    {
        iword_map::const_iterator index = iword_indexes.find(&os);
    
        if(index == iword_indexes.end())
        {
            std::pair<iword_map::iterator, bool> inserted = iword_indexes.insert(std::make_pair(&os, os.xalloc()));
            index = inserted.first;
        }
    
        return index->second;
    }
    
    
    inline std::ostream& operator<<(std::ostream& os, const dbb& value)
    {
        const int index = get_iword_index(os);
    
        if(os.pword(index) == 0)
            os.pword(index) = &const_cast<dbb&>(value);
    
        return os;
    }
    
    std::ostream& operator<<(std::ostream& os, const dbb_reliant_type& value)
    {
        const int index = get_iword_index(os);
        dbb* deebeebee = reinterpret_cast<dbb*>(os.pword(index));
        os << value.value() << "(" << deebeebee->value() << ")";
        return os;
    }
    
    int main(int, char**)
    {
        dbb deebeebee(5);
        dbb_reliant_type variable("blah");
        std::cout << deebeebee << variable << std::endl;
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am busy working on a project that needs a REST API to allow
I have two UITextViews that I want to be displayed when the user sends
`I am working with an API that sends back an XML response upon request.
I'm working on a php web api that was handed to me with a
I'm working on an API that accepts data from remote clients, some of which
Working on a movie website and would love to find an API that I
I'm working on a Python library that interfaces with a web service API. Like
I am working on an Android app that utilizes the Google Maps API MapView,
I'm working on an app that plays audio continuously using the waveOut... API from
I have an API that is dependent on certain state information between requests. As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.