Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:39

0001 #include <iostream>
0002 #include <sstream>
0003 #include <fstream>
0004 
0005 #include "SMeta.hh"
0006 #include "SPath.hh"
0007 #include "SLOG.hh"
0008 
0009 const plog::Severity SMeta::LEVEL = SLOG::EnvLevel("SMeta", "DEBUG"); 
0010 
0011 
0012 
0013 SMeta* SMeta::Load(const char* dir, const char* name) // static 
0014 {
0015     int create_dirs = 0 ; // 0:nop 
0016     const char* path = SPath::Resolve(dir, name, create_dirs); 
0017     return Load(path);   
0018 }
0019 
0020 SMeta* SMeta::Load(const char* path) // static 
0021 {
0022     std::ifstream in(path, std::ios::in);
0023     if(!in.is_open()) 
0024     {   
0025         LOG(fatal) << "failed to open " << path ; 
0026         return nullptr;
0027     }   
0028 
0029     SMeta* sm = new SMeta ; 
0030     in >> sm->js ; 
0031 
0032     return sm ; 
0033 }
0034 
0035 
0036 
0037 
0038 
0039 void SMeta::save(const char* dir, const char* reldir, const char* name) const
0040 {
0041     bool create_dirs = 1 ;  // 1:filepath
0042     const char* path = SPath::Resolve(dir, reldir, name, create_dirs); 
0043     save(path); 
0044 }
0045 void SMeta::save(const char* dir, const char* name) const
0046 {
0047     bool create_dirs = 1 ;  // 1:filepath 
0048     const char* path = SPath::Resolve(dir, name, create_dirs); 
0049     save(path); 
0050 }
0051 void SMeta::save(const char* path) const 
0052 {
0053     std::ofstream out(path, std::ios::out);
0054     if(!out.is_open())
0055     {
0056         LOG(fatal) << "SMeta::save failed to open (directories must exist already unlike with BMeta)" << path ;
0057         return ;
0058     }
0059     out << js ;
0060     out.close();
0061 }
0062 
0063 
0064 
0065