some refactoring in miscspace(.h|.cpp)

space() renamed to space_value() and takes a third parameter: escape (bool)
space_noescape() removed

space_tab() renamed to space_list_tab()
space_tab_value() renamed to space_list_tab_value()
space_tab_has_next() renamed to space_list_tab_has_next()





git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1035 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2016-03-22 14:53:43 +00:00
parent 7ed41a03ae
commit 42144bb31c
8 changed files with 138 additions and 85 deletions

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2012-2014, Tomasz Sowa
* Copyright (c) 2012-2016, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,11 +37,12 @@
namespace Winix
{
namespace TemplatesFunctions
{
bool are_spaces_the_same(const std::vector<Ezc::Var> & params, const std::vector<std::wstring> & spaces)
{
// last value from params is the parameter name (not a space)
@@ -95,7 +96,12 @@ PT::Space * find_space(const std::vector<Ezc::Var> & params, PT::Space & space,
/*
*
* IMPROVE ME
* add a private namespace?
*
*/
struct SpaceInfo
{
bool inited;
@@ -114,6 +120,46 @@ static size_t space_reqid = 0;
/*
struct SpaceKey
{
PT::Space * global_space;
std::vector<std::wstring> spaces_names;
bool operator<(const SpaceKey & k)
{
if( global_space != k.global_space )
return global_space < k.global_space;
if( spaces_names.size() != k.spaces_names.size() )
return spaces_names.size() < k.spaces_names.size();
for(size_t i=0 ; i<spaces_names.size() ; ++i)
{
if( spaces_names[i] != k.spaces_names[i] )
return spaces_names[i] < k.spaces_names[i];
}
* this is the same space
return false;
}
};
*/
/*
* mapping a global space with spaces names (strings) to a last space address
*/
//static std::map<SpaceKey, PT::Space *> space_map;
void space_init(const std::vector<Ezc::Var> & params, PT::Space & space, SpaceInfo & space_info)
{
if( !space_info.inited || !are_spaces_the_same(params, space_info.spaces) )
@@ -122,11 +168,6 @@ void space_init(const std::vector<Ezc::Var> & params, PT::Space & space, SpaceIn
copy_space(params, space_info.spaces);
space_info.last_space = find_space(params, space);
}
else
{
// !! temp
//log << log1 << "taking space from the cache" << logend;
}
}
@@ -140,7 +181,7 @@ void space_check_reqid()
}
void space(Info & i, PT::Space & space)
void space_value(Info & i, PT::Space & space, bool escape)
{
space_check_reqid();
@@ -155,34 +196,18 @@ void space(Info & i, PT::Space & space)
const std::wstring * value = space_info.last_space->GetValue(param);
if( value )
i.out << *value;
// else
// log << log1 << "nie ma takiej wartosci" << logend; // only for testing
// !! IMPROVE ME
{
if( escape )
i.out << *value;
else
i.out << R(*value);
}
}
}
}
void space_value_noescape(Info & i, PT::Space & space)
{
space_check_reqid();
if( !i.params.empty() )
{
SpaceInfo & space_info = spaces_map[&space];
space_init(i.params, space, space_info);
if( space_info.last_space )
{
const std::wstring & param = i.params.back().str;
const std::wstring * value = space_info.last_space->GetValue(param);
if( value )
i.out << R(*value);
}
}
}
@@ -299,7 +324,7 @@ void spaces_tab_init(std::vector<Ezc::Var> & params, PT::Space & space, SpacesTa
void spaces_tab(Info & i, PT::Space & space)
void space_list_tab(Info & i, PT::Space & space)
{
spaces_tab_check_reqid();
@@ -340,7 +365,7 @@ void spaces_tab_value_print(HtmlTextStream & out, SpacesTabInfo & spaces_tab_inf
}
void spaces_tab_value(Info & i, PT::Space & space)
void space_list_tab_value(Info & i, PT::Space & space)
{
spaces_tab_check_reqid();
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];
@@ -374,7 +399,7 @@ return false;
}
void spaces_tab_has_next(Info & i, PT::Space & space)
void space_list_tab_has_next(Info & i, PT::Space & space)
{
spaces_tab_check_reqid();
SpacesTabInfo & spaces_tab_info = spaces_tab_info_map[&space];