Click here to Skip to main content
15,895,538 members
Articles / High Performance Computing / Vectorization

A C++ String Class

Rate me:
Please Sign up or sign in to vote.
4.96/5 (29 votes)
3 Jan 2015CPOL13 min read 121.3K   2.6K   93  
A fast, reference counted, copy-on-write string class
#pragma once
#ifndef __HWINOBJECT_H__
#define __HWINOBJECT_H__

#include "hwindef.h"
#include "hwinlog.h"
#include "hwinobjimpl.h"

namespace harlinn
{
    namespace windows
    {

        class ComObject;
        class Object : public std::enable_shared_from_this<Object>
        {
            friend class ComObject;
            ComObject* comObject;
        public:
            HWIN_EXPORT Object();
            HWIN_EXPORT virtual ~Object();



            HWIN_EXPORT virtual HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void **ppvObject );
            HWIN_EXPORT Object& Initialize();




            HWIN_EXPORT Object& AddInterface(const Guid& riid, Unknown unknown);
            HWIN_EXPORT Object& RemoveInterface(const Guid& riid);
            HWIN_EXPORT Unknown FindInterface(const Guid& riid) const;

            template<typename T> 
            std::shared_ptr<const T> As() const
            {
                HWIN_TRACE();
                return std::dynamic_pointer_cast<const T,const Object>(shared_from_this());
            }

            template<typename T> 
            std::shared_ptr<T> As()
            {
                HWIN_TRACE();
                return std::dynamic_pointer_cast<T,Object>(shared_from_this());
            }

            template<typename T> 
            bool Is() const
            {
                HWIN_TRACE();
                auto downcasted = As<T>();
                if(downcasted)
                {
                    return true;
                }
                return false;
            }

            HWIN_EXPORT virtual Object& Assign(const Object& source);
            HWIN_EXPORT virtual String GetNamePath() const;
        protected:
            HWIN_EXPORT virtual std::shared_ptr<Object> GetOwner() const;
            HWIN_EXPORT virtual const Object& AssignTo(Object& destination) const;
            HWIN_EXPORT virtual ComObject* CreateComObject() const;
        };


        template< typename T >
        std::shared_ptr<T> make_object( )
        {
            HWIN_TRACE();
            auto result = std::make_shared<T>();
            result->Initialize( );
            return result;
        }


        template< typename T, typename A >
        std::shared_ptr<T> make_object(const A& argument)
        {
            HWIN_TRACE();
            auto result = std::make_shared<T>(argument);
            result->Initialize( );
            return result;
        }

        template< typename T, typename A1, typename A2 >
        std::shared_ptr<T> make_object(const A1& argument1, const A2& argument2)
        {
            HWIN_TRACE();
            auto result = std::make_shared<T>(argument1,argument2);
            result->Initialize( );
            return result;
        }

        template< typename T, typename A1, typename A2, typename A3 >
        std::shared_ptr<T> make_object(const A1& argument1, const A2& argument2, const A3& argument3)
        {
            HWIN_TRACE();
            auto result = std::make_shared<T>(argument1,argument2,argument3);
            result->Initialize( );
            return result;
        }

        template< typename T, typename A1, typename A2, typename A3, typename A4 >
        std::shared_ptr<T> make_object(const A1& argument1, const A2& argument2, const A3& argument3, const A4& argument4)
        {
            HWIN_TRACE();
            auto result = std::make_shared<T>(argument1,argument2,argument3, argument4);
            result->Initialize( );
            return result;
        }

        template< typename T, typename A1, typename A2, typename A3, typename A4, typename A5 >
        std::shared_ptr<T> make_object(const A1& argument1, const A2& argument2, const A3& argument3, const A4& argument4, const A5& argument5)
        {
            HWIN_TRACE();
            auto result = std::make_shared<T>(argument1,argument2,argument3, argument4,argument5);
            result->Initialize( );
            return result;
        }


        




    };
};


#endif //__HWINOBJECT_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions