Search code examples
c++booststructboost-logboost-multi-index

how to make modifier for a multiindex of struct having shared pointer to boost logger backend to reset this back end?


I am trying to modify multiindex of structs ,struct has member which is shared pointer to boost logger shared pointer of backend ,frontend and logger.
By nature of multiindex each struct is considered const when making iterator .
So when i take iterator by find or equal_range to certain index,this iterator is const .
when I try to modify the struct member shared pointer to reset it,it gives me error and will not compile.
this is the error:

cannot convert 'this' pointer from 'const boost::shared_ptr<boost::log::v2s_mt_nt6::sinks::text_file_backend>' to 'boost::shared_ptr<boost::log::v2s_mt_nt6::sinks::text_file_backend> &'

and this is the modifier:

if (it_US_MUS_update->BackendSharedPointer.unique() == true)
            {
                assert(US_MUS_index.modify(it_US_MUS_update, change_BSP(it_US_MUS_update->BackendSharedPointer.reset())));
                //assert(it_US_MUS_update->BackendSharedPointer.reset());
            }
            else if (it_US_MUS_update->BackendSharedPointer.unique() != true)
            {
                throw;
            }

and this is the definition of modifier change_BSP:

struct change_BSP
{
change_BSP(const boost::shared_ptr<sinks::text_file_backend> & new_BSP) :new_BSP_m(new_BSP) {}

void operator()(Log_file_Dur_Sig_F_Map_struct& e)
{
    e.BackendSharedPointer = new_BSP_m;
}

private:
boost::shared_ptr<sinks::text_file_backend> new_BSP_m;
};

what am I doing wrong? why the shared pointer member is considered const??
what does "this" pointer point to???the multi index container or struct or struct member shared pointer or object pointed to by shared pointer or the modifier struct change_BSP???
if more code needed I will edit but I do not want to clutter question with non required code?

these are the files:

//targetver.h //https://mega.nz/#!eDpmDARL!rmuyRtJUO3D6BbiUGUPYS2ZTMcTUxiLuTGcNgihkLOw
//stdafx.cpp
//    https://mega.nz/#!TKgiTaqT!GCEh7seVt41e2GsfNLpzJwA5nRvdilQ0NWgtUenPuSk
//stdafx.h
//    https://mega.nz/#!jTg2TKiQ!fOTHl9VQQuMbjGtfLi1hu4PZFAycimKob21GaE7nc7I




1- https://mega.nz/#!WW4gyCrS!wRE7PV1Qsi5-xza-kQgDaQK80ImgWwi9yDmqiQJQXo0  
2- https://mega.nz/#!eLxCQSbI!BE8bMK6p7NTqK88fqSOWvPJ3WyhKYRP3juNiQNcgwBU  
3- https://mega.nz/#!fSwAyCba!fZHUVNWiuMlonMnvhQTPcSInKoICdBn_7rBw6uX8V9U

file 1: my_logger_class_single_map_reduced.h

    //#pragma once
#ifndef MY_LOGGER_CLASS_SINGLE_MAP_O_H   // if my_logger.h hasn't been included yet...
#define MY_LOGGER_CLASS_SINGLE_MAP_O_H   //   #define this so the compiler knows it has been included

#include <boost/config.hpp>

#if !defined(NDEBUG)
#define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING
#define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE
#endif

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>

using boost::multi_index_container;
using namespace boost::multi_index;


#include <algorithm>
#include <iterator>
#include <string>
#include <iostream>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <vector>

#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/unlocked_frontend.hpp>
#include <boost/log/sinks/basic_sink_backend.hpp>
#include <boost/log/sinks/frontend_requirements.hpp>
#include <boost/log/sources/severity_channel_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
//for cout logger
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/core/null_deleter.hpp>

#include <boost/log/attributes.hpp> //for attr:
#include <boost/log/sources/logger.hpp> //for loggers
#include <boost/log/common.hpp> //for macros

#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/log/support/date_time.hpp>

#include <boost/bimap.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/bimap/vector_of.hpp>
#include <boost/bimap/list_of.hpp>
using namespace boost::bimaps;

#include <boost/ref.hpp>

#include <boost/filesystem.hpp>
using namespace boost::filesystem;

////#include "boost_create_directory_2.h"

#include "boost/date_time/gregorian/gregorian.hpp" //include all types plus i/o
using namespace boost::gregorian;

#include <boost/fusion/adapted/struct.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <boost/phoenix/phoenix.hpp>
using boost::phoenix::arg_names::arg1;

//=============================================================

namespace sinks = boost::log::sinks;
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;

// Complete sink type
typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
//for cout logger
typedef sinks::synchronous_sink< sinks::text_ostream_backend > cout_sink;
//make the RCF ban map using US USvalue and duration
struct RCF_Ban_Map_struct   //
{
    std::string Duration = "";
    std::string UniqueSignal = "";
    std::string UniqueSignalvalue = "";

    RCF_Ban_Map_struct()
    {
    }

    RCF_Ban_Map_struct(const std::string& duration, const std::string& UniqueSignal, std::string const& UniqueSignalvalue) : Duration(duration), UniqueSignal(UniqueSignal), UniqueSignalvalue(UniqueSignalvalue)
    {
    }

    //bool operator<(const Log_file_Dur_Sig_F_Map_struct& e)const { return Duration < e.Duration; }

};

struct change_D_RCF_Ban_Map_struct
{
    change_D_RCF_Ban_Map_struct(const std::string& new_D) :new_D_m(new_D) {}

    void operator()(RCF_Ban_Map_struct& e)
    {
        e.Duration = new_D_m;
    }

private:
    std::string new_D_m;
};
struct change_US_RCF_Ban_Map_struct
{
    change_US_RCF_Ban_Map_struct(const std::string& new_US) :new_US_m(new_US) {}

    void operator()(RCF_Ban_Map_struct& e)
    {
        e.UniqueSignal = new_US_m;
    }

private:
    std::string new_US_m;
};
struct change_USvalue_RCF_Ban_Map_struct
{
    change_USvalue_RCF_Ban_Map_struct(const std::string& new_USvalue) :new_USvalue_m(new_USvalue) {}

    void operator()(RCF_Ban_Map_struct& e)
    {
        e.UniqueSignalvalue = new_USvalue_m;
    }

private:
    std::string new_USvalue_m;
};


// tags for accessing the corresponding indices of  //
struct US_USvalue_D {};
struct D {};
struct US_USvalue {};



/*
*NB: The use of derivation here instead of simple typedef is explained in
* Compiler specifics : type hiding.
*/
////check if we need to define composite_key_compare
struct US_USvalue_D_key :composite_key <
    RCF_Ban_Map_struct,
    BOOST_MULTI_INDEX_MEMBER(RCF_Ban_Map_struct, std::string, UniqueSignal),
    BOOST_MULTI_INDEX_MEMBER(RCF_Ban_Map_struct, std::string, UniqueSignalvalue),
    BOOST_MULTI_INDEX_MEMBER(RCF_Ban_Map_struct, std::string, Duration)

> {};

// reducing symbol names through type hiding
// type hide the index specifier list within employee_set_indices

struct RCF_Ban_Map_struct_set_indices :
    indexed_by <
    ordered_non_unique<
    tag<US_USvalue_D>, US_USvalue_D_key >
    >
{};

typedef multi_index_container<
    RCF_Ban_Map_struct,
    RCF_Ban_Map_struct_set_indices
> RCF_Ban_Map_struct_set;

typedef RCF_Ban_Map_struct_set::index<US_USvalue_D>::type RCF_Ban_Map_struct_set_by_US_USvalue_D;

BOOST_FUSION_ADAPT_STRUCT(RCF_Ban_Map_struct, (std::string, UniqueSignal)(std::string, UniqueSignalvalue) (std::string, Duration));

struct Log_file_Dur_Sig_F_Map_struct   //Duration_Signal_Folder_Map_struct >>>log file destination
{

    int         Id;
    std::string Duration;
    std::string FolderDuration;//??
    std::string FolderDurationSpecefied;
    std::string FolderDurationPathString;//??
    std::string FolderDurationSpecefiedPathString;

    //make fields for UniqueSignal and ModifiedUniqueSignal
    std::string UniqueSignal = "";
    std::string ModifiedUniqueSignal = "";
    std::string ModifiedUniqueSignalCertainUniqueSignal = "";

    std::string FolderDurationSpecefiedUniqueSignal="";
    std::string FolderDurationSpecefiedUniqueSignalPathString = "";
    std::string FolderDurationSpecefiedModifiedUniqueSignalCertainUniqueSignal="";
    std::string FolderDurationSpecefiedModifiedUniqueSignalCertainUniqueSignalPathString = "";

    //5
    //make fields for Backend
    std::string UniqueSignalvalue = "";
    std::string BackendName{ "" };
    std::string BackendFileName{ "" };
    std::string BackendFileNamePathString{ "" };
    std::string BackendFileNamePathString_parent{ "" };
    boost::shared_ptr<sinks::text_file_backend> BackendSharedPointer{ nullptr };//12-23-2019 study shared pointer //default constructed empty

    //make fields for logger
    std::string loggerChannelName{""};
    boost::shared_ptr<src::channel_logger_mt<>> loggerChannelSharedPointer{ nullptr };//default constructed empty

    //make fields for FrontendName
    std::string FrontendName { "" };    
    boost::shared_ptr<file_sink> FrontendSharedPointer{ nullptr };//default constructed empty

    Log_file_Dur_Sig_F_Map_struct(const std::string& duration, const std::string& folderdurationspecefied, std::string const& folderdurationspecefiedpathstring, const path folderdurationspecefiedpath) : Duration(duration), FolderDurationSpecefied(folderdurationspecefied), FolderDurationSpecefiedPathString(folderdurationspecefiedpathstring)
    {
        if (duration == "AllTime")
        {
            Id = 0;
        }
        else if (duration == "Yearly")
        {
            Id = 1;
        }
        else if (duration == "Monthly")
        {
            Id = 2;
        }
        else if (duration == "Daily")
        {
            Id = 3;
        }

        FolderDuration = folderdurationspecefiedpath.parent_path().filename().generic_string();//why i get Duration in arguments???>>>>>>>>>>>>>>>>>>>>x1>>because duration means the time duration and FolderDuration means the folder built for time duration which include certain time like 2019 or 00 month...
        FolderDurationPathString = folderdurationspecefiedpath.parent_path().generic_string() ;
    }
    bool operator<(const Log_file_Dur_Sig_F_Map_struct& e)const { return Id<e.Id; }
};

BOOST_FUSION_ADAPT_STRUCT(Log_file_Dur_Sig_F_Map_struct, (int, Id)(std::string, Duration)(std::string, FolderDuration)(std::string, FolderDurationSpecefied)(std::string, FolderDurationPathString)(std::string, FolderDurationSpecefiedPathString)(std::string, UniqueSignal)(std::string, ModifiedUniqueSignal)(std::string, ModifiedUniqueSignalCertainUniqueSignal)(std::string, FolderDurationSpecefiedUniqueSignal)(std::string, FolderDurationSpecefiedUniqueSignalPathString)(std::string, FolderDurationSpecefiedModifiedUniqueSignalCertainUniqueSignal) (std::string, FolderDurationSpecefiedModifiedUniqueSignalCertainUniqueSignalPathString) (std::string ,UniqueSignalvalue) (std::string, BackendName)(std::string, BackendFileName)(std::string, BackendFileNamePathString)  (std::string, BackendFileNamePathString_parent) (std::string ,loggerChannelName)(std::string ,FrontendName)(boost::shared_ptr<sinks::text_file_backend>, BackendSharedPointer));//12-23-2019 study shared pointer (boost::shared_ptr<sinks::text_file_backend>, BackendSharedPointer)(boost::shared_ptr<file_sink> ,FrontendSharedPointer)(boost::shared_ptr<src::channel_logger_mt<>> ,loggerChannelSharedPointer)

struct change_BName
{
    change_BName(const std::string& new_BName) :new_BName_m(new_BName) {}

    void operator()(Log_file_Dur_Sig_F_Map_struct& e)
    {
        e.BackendName = new_BName_m;
    }

private:
    std::string new_BName_m;
};

struct change_BSP
{
    change_BSP(const boost::shared_ptr<sinks::text_file_backend> & new_BSP) :new_BSP_m(new_BSP) {}

    void operator()(Log_file_Dur_Sig_F_Map_struct& e)
    {
        e.BackendSharedPointer = new_BSP_m;
    }

private:
    boost::shared_ptr<sinks::text_file_backend> new_BSP_m;
};

struct change_LCSP
{
    change_LCSP(const boost::shared_ptr<src::channel_logger_mt<>> &new_LCSP) :new_LCSP_m(new_LCSP) {}

    void operator()(Log_file_Dur_Sig_F_Map_struct& e)
    {
        e.loggerChannelSharedPointer = new_LCSP_m;
    }

private:
    boost::shared_ptr<src::channel_logger_mt<>> new_LCSP_m;
};

struct change_FSP
{
    change_FSP(const boost::shared_ptr<file_sink> &new_FSP) :new_FSP_m(new_FSP) {}

    void operator()(Log_file_Dur_Sig_F_Map_struct& e)
    {
        e.FrontendSharedPointer = new_FSP_m;
    }

private:
    boost::shared_ptr<file_sink>    new_FSP_m;
};
struct US_MUS {};

/*
*NB: The use of derivation here instead of simple typedef is explained in
* Compiler specifics : type hiding.
*/
////check if we need to define composite_key_compare
struct US_MUS_key :composite_key <
    Log_file_Dur_Sig_F_Map_struct,
    BOOST_MULTI_INDEX_MEMBER(Log_file_Dur_Sig_F_Map_struct, std::string, UniqueSignal), 
    BOOST_MULTI_INDEX_MEMBER(Log_file_Dur_Sig_F_Map_struct, std::string, ModifiedUniqueSignal)
> {};

// reducing symbol names through type hiding
// type hide the index specifier list within employee_set_indices

struct Log_file_Dur_Sig_F_Map_struct_set_indices :
    indexed_by <    
    ordered_non_unique<
    tag<US_MUS>, US_MUS_key >
    >
{};

typedef multi_index_container<
    Log_file_Dur_Sig_F_Map_struct,
    Log_file_Dur_Sig_F_Map_struct_set_indices
> Log_file_Dur_Sig_F_Map_struct_set;

typedef Log_file_Dur_Sig_F_Map_struct_set::index<US_MUS>::type Log_file_Dur_Sig_F_Map_struct_set_by_US_MUS;

class LoggingClass_2
{
private:
    RCF_Ban_Map_struct_set RCF_Ban_Map;

    Log_file_Dur_Sig_F_Map_struct_set Log_file_Dur_Sig_F_Map;
    static boost::bimap<set_of<std::string>, set_of<std::string>> mMUS_Map; 
    std::vector<const Log_file_Dur_Sig_F_Map_struct *> vector_new_structs;

    //make UniqueSignal vector
    static std::vector<std::string>  UniqueSignalVector;
    //make UniqueSignal map
    static std::map<std::string,unsigned int>  mlogUS_SizeMap;

    // create a cout backend
    boost::shared_ptr< sinks::text_ostream_backend > backendCout = boost::make_shared< sinks::text_ostream_backend >();

    // create a cout frontend   
    boost::shared_ptr< cout_sink > sink_cout = boost::make_shared<cout_sink>(backendCout);  

public:
    LoggingClass_2();//it automatically defines where log files are stored
    LoggingClass_2(std::string, std::string);

    void CreateUpdateLoggingStructure(std::string, std::string);
    void CreateUpdate_RCF_Ban_Map(std::string, std::string);

    void RotateLogFile(boost::shared_ptr< file_sink >);
    void init_file_collecting_path(boost::shared_ptr< file_sink >, std::string);
    src::channel_logger_mt<> mloggerCoutLog{ keywords::channel = "m_cout_log" };

    //getting the instance of core singleton class
    boost::shared_ptr< logging::core > core = logging::core::get();

    // Setup the common formatter for all sinks
    logging::formatter fmt;
};
#endif//MY_LOGGER_CLASS_SINGLE_MAP_O_H

file 2: my_logger_class_single_map_reduced.cpp

//#include "../../stdafx.h"
#include "stdafx.h"
//#include "../../stdafx.h"
#include "my_logger_class_single_map_reduced.h"
//allUniqueSignalResponsesOfSameValue 00 00 00 Or 01 01 01 or 200 200 200 Or 404 404 404
std::string allUniqueSignalResponsesOfSameValue{ "ARS_" };// AllRespSame_ = ARS_

//allUniqueSignalResponses 00 01 02 01 19 or 200 200 200 400 404 404 >>>>>>>>>>>>>single file
std::string allUniqueSignalResponsesTogether{ "AR_" };//AllResp_ = AR_

//allUniqueSignalResponsesForFirstTime  00 01 02 04 22 or 200 300 500 400 404 >>>>>>>>>>>>>>>>>>>>single file
std::string allUniqueSignalResponsesForFirstTimeTogether{ "ARF_" };// AllRespFirst_ = ARF_

//UniqueSignalResponseOfCertainValueForFirstTime  00 Or 01 or 300 Or 200 Or 404
std::string UniqueSignalResponseOfCertainValueForFirstTime{ "RCF_" };// RespCertainFirst_= RCF_

boost::bimap<set_of<std::string>, set_of<std::string>> LoggingClass_2::mMUS_Map;


std::vector<std::string>  LoggingClass_2::UniqueSignalVector;
std::map<std::string, unsigned int>  LoggingClass_2::mlogUS_SizeMap;

//==========================================================================
LoggingClass_2::LoggingClass_2()
{
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("allUniqueSignalResponsesOfSameValue", allUniqueSignalResponsesOfSameValue));
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("allUniqueSignalResponsesTogether", allUniqueSignalResponsesTogether));
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("allUniqueSignalResponsesForFirstTimeTogether", allUniqueSignalResponsesForFirstTimeTogether));
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("UniqueSignalResponseOfCertainValueForFirstTime", UniqueSignalResponseOfCertainValueForFirstTime));

    backendCout->add_stream(boost::shared_ptr< std::ostream >(&std::cout, boost::null_deleter()));
    sink_cout->set_filter(expr::attr<std::string>("Channel") == "m_cout_log");//==
    sink_cout->set_formatter(fmt);
    core->add_sink(sink_cout);

    // And also add some logging core attributes
    core->add_global_attribute("TimeStamp", attrs::local_clock());
    core->add_global_attribute("RecordID", attrs::counter< unsigned int >());

    // Setup the common formatter for all sinks
    fmt = expr::format("[%1%] [%2%]  [%5%]")//[%3%] [%4%]
        % expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S.%f")
        % expr::attr<unsigned int>("ThreadID")
        //% expr::attr<string>("Scope")
        //% trivial::severity       
        % expr::smessage;


}

LoggingClass_2::LoggingClass_2(std::string pathFolder, std::string folderBehaviour)
{
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("allUniqueSignalResponsesOfSameValue", allUniqueSignalResponsesOfSameValue));
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("allUniqueSignalResponsesTogether", allUniqueSignalResponsesTogether));
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("allUniqueSignalResponsesForFirstTimeTogether", allUniqueSignalResponsesForFirstTimeTogether));
    LoggingClass_2::mMUS_Map.left.insert(boost::bimap<set_of<std::string>, set_of<std::string>>::left_value_type("UniqueSignalResponseOfCertainValueForFirstTime", UniqueSignalResponseOfCertainValueForFirstTime));

    backendCout->add_stream(boost::shared_ptr< std::ostream >(&std::cout, boost::null_deleter()));
    sink_cout->set_filter(expr::attr<std::string>("Channel") == "m_cout_log");
    sink_cout->set_formatter(fmt);

    // And also add some logging core attributes
    core->add_global_attribute("TimeStamp", attrs::local_clock());
    core->add_global_attribute("RecordID", attrs::counter< unsigned int >());


    //========================================================================
    // Setup the common formatter for all sinks
    fmt = expr::format("[%1%] [%2%]  [%5%]")//[%3%] [%4%]
        % expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S.%f")
        % expr::attr<unsigned int>("ThreadID")
        //% expr::attr<string>("Scope")
        //% trivial::severity       
        % expr::smessage;


}


void LoggingClass_2::CreateUpdate_RCF_Ban_Map(std::string UniqueSignal, std::string UniqueSignalValue)
{
    //1
    RCF_Ban_Map_struct_set_by_US_USvalue_D & US_USvalue_D_index = RCF_Ban_Map.get<US_USvalue_D>();
    //2-2
    RCF_Ban_Map_struct_set_by_US_USvalue_D::iterator it_US_USvalue_D_0, it_US_USvalue_D_1;
    boost::tie(it_US_USvalue_D_0, it_US_USvalue_D_1) = US_USvalue_D_index.equal_range(boost::make_tuple(UniqueSignal, UniqueSignalValue));
    auto it_US_USvalue_D_update = it_US_USvalue_D_0;
    if (it_US_USvalue_D_0 == it_US_USvalue_D_1)
    {
        //boost::fusion::for_each(*it_US_USvalue_D_update, std::cout << arg1 << "\n");

        //RCF_Ban_Map_struct new_struct{ *it_US_USvalue_D_update };
        RCF_Ban_Map_struct new_struct{  };

        change_US_RCF_Ban_Map_struct(UniqueSignal).operator()(new_struct);
        change_USvalue_RCF_Ban_Map_struct(UniqueSignalValue).operator()(new_struct);
        //change_D(Duration).operator()(new_struct);

        bool successful_insert = false;
        RCF_Ban_Map_struct_set_by_US_USvalue_D::iterator it_US_USvalue_D_new;
        boost::tie(it_US_USvalue_D_new, successful_insert) = US_USvalue_D_index.insert(new_struct);////,FolderDuration,FolderDurationSpecefied));
                                                                                                                //here i should put code to catch error regarding insert>>>>>>>>>>>>>>>>>>>>x2>>
        assert(successful_insert);
        boost::fusion::for_each(*it_US_USvalue_D_new, std::cout << arg1 << "\n");

    }
    else if (it_US_USvalue_D_0 != it_US_USvalue_D_1)
    {
        //do nothing because value is already registered for this UniqueSignal
    }
}

//mLogModifiedUniqueSignalUpdateBackendsParametersMap???????????????????????????//

void LoggingClass_2::CreateUpdateLoggingStructure(std::string UniqueSignal, std::string UniqueSignalValue)
{
    //make RCF_ items clear
    //make index and get range having RCF_
    //using iterator clear RCF_ items to ""
    Log_file_Dur_Sig_F_Map_struct_set_by_US_MUS & US_MUS_index = Log_file_Dur_Sig_F_Map.get<US_MUS>();

    Log_file_Dur_Sig_F_Map_struct_set_by_US_MUS::iterator it_US_MUS_0, it_US_MUS_1;//, it_US_D_FD_FDS_MUS_update_original;
    boost::tie(it_US_MUS_0, it_US_MUS_1) = US_MUS_index.equal_range(boost::make_tuple(UniqueSignal, UniqueSignalResponseOfCertainValueForFirstTime));
    if (it_US_MUS_0 == it_US_MUS_1)
    {
        //error happens because there is no such US in the folder system so look at Modify_Unique_Signal
        throw;
    }
    else if (it_US_MUS_0 != it_US_MUS_1)
    {
        auto itx = it_US_MUS_1;
        std::advance(itx, -1);

        //3
        for (auto it_US_MUS_update = it_US_MUS_0; it_US_MUS_update != it_US_MUS_1;)
        {
            //std::cout << "\033[2J\033[1;1H"   << std::endl;
            std::cout << "\n" << std::endl;
            boost::fusion::for_each(*it_US_MUS_update, std::cout << arg1 << "\n");
            std::cout << US_MUS_index.count(boost::make_tuple(UniqueSignal,UniqueSignalResponseOfCertainValueForFirstTime)) << std::endl;
            boost::fusion::for_each(*itx, std::cout << arg1 << "\n");

            if (it_US_MUS_update->BackendName != "")
            {
                assert(US_MUS_index.modify(it_US_MUS_update, change_BName("")));
                //assert(US_MUS_index.modify(it_US_MUS_update, change_BSP(boost::make_shared< sinks::text_file_backend >(keywords::file_name = BackendFileName))));
                if (it_US_MUS_update->BackendSharedPointer.unique() == true)
                {
                    assert(US_MUS_index.modify(it_US_MUS_update, change_BSP(it_US_MUS_update->BackendSharedPointer.reset())));
                    //assert(it_US_MUS_update->BackendSharedPointer.reset());
                    ////assert(dynamic_pointer_cast<Log_file_Dur_Sig_F_Map_struct::BackendSharedPointer>(it_US_MUS_update->BackendSharedPointer).reset());
                    //const_cast<const foo*>(this)->bar();
                }
                else if (it_US_MUS_update->BackendSharedPointer.unique() != true)
                {
                    throw;
                }


                // Break the feeding loop
                ////it_US_MUS_update->FrontendSharedPointer->stop();

                // Flush all log records that may have left buffered
                it_US_MUS_update->FrontendSharedPointer->flush();

                if (it_US_MUS_update->ModifiedUniqueSignal == "AR_" || it_US_MUS_update->ModifiedUniqueSignal == "ARF_")
                {
                    //it_US_MUS_update->FrontendSharedPointer->reset_filter();//????????????ARS_
                    throw;
                }
                //else if (ModifiedUniqueSignal == "ARS_" || ModifiedUniqueSignal == "RCF_")
                else if (it_US_MUS_update->ModifiedUniqueSignal == "RCF_")
                {
                    it_US_MUS_update->FrontendSharedPointer->reset_filter();
                    it_US_MUS_update->FrontendSharedPointer->reset_formatter();
                    it_US_MUS_update->FrontendSharedPointer->locked_backend()->rotate_file();//???????
                    it_US_MUS_update->FrontendSharedPointer->locked_backend()->set_file_collector(sinks::file::make_collector(
                        keywords::target = ""));//< the target directory >

                }

                //??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
                if (it_US_MUS_update->FrontendSharedPointer.unique() == true)
                {
                    assert(US_MUS_index.modify(it_US_MUS_update, change_FSP(it_US_MUS_update->FrontendSharedPointer.reset())));
                }
                else if (it_US_MUS_update->FrontendSharedPointer.unique() != true)
                {
                    throw;
                }   

                // Remove the sink from the core, so that no records are passed to it
                core->remove_sink(it_US_MUS_update->FrontendSharedPointer);




                //the next line might be changed so that channel=ModifiedUniqueSignalCertainUniqueSignal with AR_,ARF_,RCF_ and channel=ModifiedUniqueSignalCertainUniqueSignalCertainValue with ARS_
                if (it_US_MUS_update->ModifiedUniqueSignal == "AR_" || it_US_MUS_update->ModifiedUniqueSignal == "ARF_")
                {
                    ////assert(US_MUS_index.modify(it_US_MUS_update, change_LCSP(boost::make_shared<src::channel_logger_mt<>>(keywords::channel = ModifiedUniqueSignalCertainUniqueSignal))));
                    throw;
                }
                ////else if (ModifiedUniqueSignal == "ARS_" || ModifiedUniqueSignal == "RCF_")
                else if (it_US_MUS_update->ModifiedUniqueSignal == "RCF_")
                {
                    ////assert(US_MUS_index.modify(it_US_MUS_update, change_LCSP(boost::make_shared<src::channel_logger_mt<>>(keywords::channel = ModifiedUniqueSignalCertainUniqueSignalCertainValue))));
                    if (it_US_MUS_update->loggerChannelSharedPointer.unique() == true)
                    {
                        assert(US_MUS_index.modify(it_US_MUS_update, change_LCSP(it_US_MUS_update->loggerChannelSharedPointer.reset())));
                    }
                    else if (it_US_MUS_update->loggerChannelSharedPointer.unique() != true)
                    {
                        throw;
                    }
                }

                boost::fusion::for_each(*it_US_MUS_update, std::cout << arg1 << "\n");
                //it_US_MUS_update_original = it_US_MUS_update;
                ++it_US_MUS_update;//5
                std::cout << "\n ++it_US_MUS_update " << std::endl;

                if (it_US_MUS_update != it_US_MUS_1)
                {
                    boost::fusion::for_each(*it_US_MUS_update, std::cout << arg1 << "\n");
                }

            }

        }

    }
}

file 3: logging_trial_ars_single_map_reduced.cpp

// logger_class_trial_2.cpp : Defines the entry point for the console application.
//
// logger_trial.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "my_logger_class_single_map_reduced.h"
//#include "boost_create_directory_2.h"


int main()
{
  //make LoggingClass_2 instance
    LoggingClass_2 mLoggingInstance;
    BOOST_LOG(mLoggingInstance.mloggerCoutLog) << "starting program";


        std::string UniqueSignal{ "u_h" };

        for (int hour = 0; hour < 2; hour++)
        {
            std::stringstream ss_hour;
            ss_hour << std::setw(2) << std::setfill('0') << hour;
            std::string url_hour{ ss_hour.str() };
            std::stringstream().swap(ss_hour); // swap m with a default constructed stringstream

            mLoggingInstance.CreateUpdate_RCF_Ban_Map(UniqueSignal, url_hour);
            mLoggingInstance.CreateUpdateLoggingStructure(UniqueSignal, url_hour);
        }


    return 0;
}

Solution

  • The problem is with the expression it_US_MUS_update->BackendSharedPointer.reset() in:

    assert(US_MUS_index.modify(
        it_US_MUS_update,
        change_BSP(it_US_MUS_update->BackendSharedPointer.reset())));
    

    As it_US_MUS_update is a constant iterator, it_US_MUS_update->BackendSharedPointer is also seen as constant and can't be reset()'ed. If what you're after is just resetting the thing, you don't need to go through contortions with change_BSP; instead, do the following:

    US_MUS_index.modify(
        it_US_MUS_update,
        [](Log_file_Dur_Sig_F_Map_struct& e){ e.BackendSharedPointer.reset(); });