char** to const char** in range stream parser + minor changes (utilities)
This commit is contained in:
parent
fb1a3c9e33
commit
1523fa024e
12 changed files with 40 additions and 23 deletions
|
@ -41,6 +41,9 @@ namespace MultiArrayTools
|
|||
auto createExplicit(std::shared_ptr<RangeFactory> rfp)
|
||||
-> std::shared_ptr<typename RangeFactory::oType>;
|
||||
|
||||
template <class Range>
|
||||
auto createRange(const std::vector<char>& cvec)
|
||||
-> std::shared_ptr<Range>;
|
||||
}
|
||||
|
||||
/* ========================= *
|
||||
|
@ -112,7 +115,19 @@ namespace MultiArrayTools
|
|||
{
|
||||
return std::dynamic_pointer_cast<typename RangeFactory::oType>( rfp->create() );
|
||||
}
|
||||
|
||||
|
||||
template <class Range>
|
||||
auto createRange(const std::vector<char>& cvec)
|
||||
-> std::shared_ptr<Range>
|
||||
{
|
||||
const char* dp = cvec.data();
|
||||
auto ff = createRangeFactory(&dp);
|
||||
auto rbptr = ff->create();
|
||||
assert(rbptr->spaceType() == Range::STYPE);
|
||||
// CATCH CAST ERROR HERE !!!
|
||||
return std::dynamic_pointer_cast<Range>( rbptr );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -220,7 +220,7 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
// -> define in range_base.cc
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp);
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(const char** dp);
|
||||
|
||||
/******************
|
||||
* MultiIndex *
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace MultiArrayTools
|
|||
void setSelf();
|
||||
};
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> createRangeFactory(char** dp);
|
||||
std::shared_ptr<RangeFactoryBase> createRangeFactory(const char** dp);
|
||||
|
||||
class RangeBase
|
||||
{
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace MultiArrayTools
|
|||
typedef SingleRange<size_t,SpaceType::NUL> NullRange;
|
||||
typedef SingleRangeFactory<size_t,SpaceType::NUL> NullRF;
|
||||
|
||||
std::shared_ptr<NullRF> mkNUL(char* dp, size_t size);
|
||||
std::shared_ptr<NullRF> mkNUL(const char* dp, size_t size);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace MultiArrayTools
|
|||
typedef SingleRange<int,SpaceType::PSPACE> PSpaceRange;
|
||||
typedef SingleRangeFactory<int,SpaceType::PSPACE> PSpaceRF;
|
||||
|
||||
std::shared_ptr<PSpaceRF> mkPSPACE(char* dp, size_t size);
|
||||
std::shared_ptr<PSpaceRF> mkPSPACE(const char* dp, size_t size);
|
||||
|
||||
template <class SpaceRange>
|
||||
struct PromoteMSpaceRange
|
||||
|
|
|
@ -73,7 +73,7 @@ namespace MultiArrayTools
|
|||
typedef SingleRange<size_t,SpaceType::SPIN> SpinRange;
|
||||
typedef SingleRangeFactory<size_t,SpaceType::SPIN> SpinRF;
|
||||
|
||||
std::shared_ptr<SpinRF> mkSPIN(char* dp, size_t size);
|
||||
std::shared_ptr<SpinRF> mkSPIN(const char* dp, size_t size);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
//#include <iostream>
|
||||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
|
@ -34,9 +35,9 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
inline void metaCat(std::vector<T>& vec, char* begin, size_t size)
|
||||
inline void metaCat(std::vector<T>& vec, const char* begin, size_t size)
|
||||
{
|
||||
T* tp = reinterpret_cast<T*>( begin );
|
||||
const T* tp = reinterpret_cast<const T*>( begin );
|
||||
vec.insert(vec.end(), tp, tp + size / sizeof(T));
|
||||
}
|
||||
|
||||
|
@ -62,10 +63,11 @@ namespace MultiArrayTools
|
|||
}
|
||||
|
||||
template <>
|
||||
inline void metaCat<std::string>(std::vector<std::string>& vec, char* begin, size_t size)
|
||||
inline void metaCat<std::string>(std::vector<std::string>& vec, const char* begin, size_t size)
|
||||
{
|
||||
|
||||
std::string tmp(begin, size);
|
||||
//std::cout << tmp << std::endl;
|
||||
size_t pos = 0;
|
||||
while(pos != tmp.size()){
|
||||
std::string es = "\n";
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace MultiArrayTools
|
|||
return id;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(char** dp, size_t metaSize)
|
||||
std::shared_ptr<RangeFactoryBase> mkMULTI(char const** dp, size_t metaSize)
|
||||
{
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
RVEC rvec(metaSize);
|
||||
|
@ -88,7 +88,7 @@ namespace MultiArrayTools
|
|||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> mkANONYMOUS(char** dp, size_t metaSize)
|
||||
std::shared_ptr<RangeFactoryBase> mkANONYMOUS(char const** dp, size_t metaSize)
|
||||
{
|
||||
std::shared_ptr<RangeFactoryBase> out = nullptr;
|
||||
auto arf = std::make_shared<AnonymousRangeFactory>();
|
||||
|
@ -100,7 +100,7 @@ namespace MultiArrayTools
|
|||
return out;
|
||||
}
|
||||
|
||||
std::shared_ptr<RangeFactoryBase> createRangeFactory(char** dp)
|
||||
std::shared_ptr<RangeFactoryBase> createRangeFactory(char const** dp)
|
||||
{
|
||||
DataHeader h = *reinterpret_cast<const DataHeader*>(*dp);
|
||||
*dp += sizeof(DataHeader);
|
||||
|
@ -126,7 +126,7 @@ namespace MultiArrayTools
|
|||
if(h.metaType == -1){
|
||||
assert(0);
|
||||
}
|
||||
#define register_type(x) else if(x == h.metaType) {\
|
||||
#define register_type(x) else if(x == h.metaType) { \
|
||||
std::vector<TypeMap<x>::type> vd;\
|
||||
metaCat(vd, *dp, h.metaSize); \
|
||||
out = std::make_shared<SingleRangeFactory<TypeMap<x>::type, \
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
std::shared_ptr<NullRF> mkNUL(char* dp, size_t size)
|
||||
std::shared_ptr<NullRF> mkNUL(const char* dp, size_t size)
|
||||
{
|
||||
return std::make_shared<NullRF>();
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
std::shared_ptr<PSpaceRF> mkPSPACE(char* dp, size_t size)
|
||||
std::shared_ptr<PSpaceRF> mkPSPACE(const char* dp, size_t size)
|
||||
{
|
||||
size_t max = *reinterpret_cast<size_t*>(dp);
|
||||
size_t max = *reinterpret_cast<const size_t*>(dp);
|
||||
return std::make_shared<PSpaceRF>(max);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace MultiArrayTools
|
||||
{
|
||||
std::shared_ptr<SpinRF> mkSPIN(char* dp, size_t size)
|
||||
std::shared_ptr<SpinRF> mkSPIN(const char* dp, size_t size)
|
||||
{
|
||||
return std::make_shared<SpinRF>();
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ namespace {
|
|||
TEST_F(AnonymousTest, ToString1)
|
||||
{
|
||||
std::vector<char> vv = sr1ptr->data();
|
||||
char* dp = vv.data();
|
||||
const char* dp = vv.data();
|
||||
auto ff = createRangeFactory(&dp);
|
||||
auto ss = std::dynamic_pointer_cast<SRange>( ff->create() );
|
||||
|
||||
|
@ -151,9 +151,9 @@ namespace {
|
|||
std::vector<char> cv = cr->data();
|
||||
std::vector<char> sv = sr->data();
|
||||
std::vector<char> nv = nr->data();
|
||||
char* cp = cv.data();
|
||||
char* sp = sv.data();
|
||||
char* np = nv.data();
|
||||
const char* cp = cv.data();
|
||||
const char* sp = sv.data();
|
||||
const char* np = nv.data();
|
||||
|
||||
auto crf2 = createRangeFactory(&cp);
|
||||
auto cr2 = std::dynamic_pointer_cast<ClassicRange>( crf2->create() );
|
||||
|
@ -178,7 +178,7 @@ namespace {
|
|||
TEST_F(AnonymousTest, ToStringMulti)
|
||||
{
|
||||
std::vector<char> vv = m3rptr->data();
|
||||
char* dp = vv.data();
|
||||
const char* dp = vv.data();
|
||||
|
||||
auto ff2 = std::dynamic_pointer_cast<M3RF>( createRangeFactory(&dp) );
|
||||
auto mr2 = std::dynamic_pointer_cast<M3Range>( ff2->create() );
|
||||
|
@ -201,7 +201,7 @@ namespace {
|
|||
AnonymousRangeFactory arf2(sr1ptr,m3rptr,sr2ptr);
|
||||
auto ar = std::dynamic_pointer_cast<AnonymousRange>( arf2.create() );
|
||||
std::vector<char> vv = ar->data();
|
||||
char* dp = vv.data();
|
||||
const char* dp = vv.data();
|
||||
|
||||
auto ff2 = std::dynamic_pointer_cast<AnonymousRangeFactory>( createRangeFactory(&dp) );
|
||||
auto ar2 = std::dynamic_pointer_cast<AnonymousRange>( ff2->create() );
|
||||
|
|
Loading…
Reference in a new issue