Skip to content

Commit

Permalink
addscienum
Browse files Browse the repository at this point in the history
  • Loading branch information
archibate committed Jul 31, 2022
1 parent 341a012 commit 35b0dea
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 5 deletions.
11 changes: 11 additions & 0 deletions 15/03/b2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <cstdio>
#include <string>

using namespace std;

int main() {
string s1 = "hello";
string s2 = "world";
string s3 = s1 + s2;
printf("%s\n", s3.c_str());
}
9 changes: 6 additions & 3 deletions 15/04/a.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <string>
#include <iostream>
#include <sstream>
#include <iomanip>

using namespace std;

int main() {
int n = 42;
auto s = to_string(n) + " yuan"s;
cout << s << endl;
//string s = (stringstream() << setprecision(100) << 3.1415f).str();
//stringstream("3.1415926535") >> f;
int n = 10011;
cout << setprecision(4) << (n * 0.01) << endl;
}
3 changes: 2 additions & 1 deletion 15/06/f3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ vector<string> split(string s) {
}

int main() {
string s = "hello world pyb teacher good job"s;
string s = "hello world\tpyb teacher\ngood job"s;
vector<string> v = split(s);
for (auto const &vi: v) {
cout << vi << endl;
}
cout << sizeof(string) << endl;
}
16 changes: 16 additions & 0 deletions 15/09/c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <string>
#include <string_view>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <locale>

using namespace std;


int main() {
string s = "你好";
wstring ws = L"你好";
cout << s.size() << endl;
cout << ws.size() << endl;
}
Binary file modified 15/slides.pptx
Binary file not shown.
Binary file added 16/slides.pptx
Binary file not shown.
12 changes: 12 additions & 0 deletions specmacro/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include <string>
#include "scienum.h"

enum Color {
RED = 1, GREEN = 2, BLUE = 3, YELLOW = 4,
};

int main() {
std::cout << scienum::get_enum_name(YELLOW) << std::endl;
std::cout << scienum::enum_from_name<Color>("YELLOW") << std::endl;
}
76 changes: 76 additions & 0 deletions specmacro/scienum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#pragma once

#include <string>

namespace scienum {

namespace details {

template <class T, T N>
const char *get_enum_name_static() {
#if defined(_MSC_VER)
return __FUNCSIG__;
#else
return __PRETTY_FUNCTION__;
#endif
}

template <bool Cond>
struct my_enable_if {
};

template <>
struct my_enable_if<true> {
typedef int type;
};

template <int Beg, int End, class F, typename my_enable_if<Beg == End>::type = 0>
void static_for(F const &func) {
}

template <int Beg, int End, class F, typename my_enable_if<Beg != End>::type = 0>
void static_for(F const &func) {
struct int_constant {
enum { value = Beg };
};
func(int_constant());
static_for<Beg + 1, End>(func);
}

}

template <int Beg = 0, int End = 256, class T>
std::string get_enum_name(T n) {
std::string s;
details::static_for<Beg, End + 1>([&] (auto i) {
if (n == (T)i.value) s = details::get_enum_name_static<T, (T)i.value>();
});
if (s.empty())
return std::to_string((int)n);
#if defined(_MSC_VER)
auto pos = s.find(',');
pos += 1;
auto pos2 = s.find('>', pos);
#else
auto pos = s.find("N = ");
pos += 4;
auto pos2 = s.find_first_of(";]", pos);
#endif
s = s.substr(pos, pos2 - pos);
auto pos3 = s.find("::");
if (pos3 != s.npos)
s = s.substr(pos3 + 2);
return s;
}

template <class T, int Beg = 0, int End = 256>
T enum_from_name(std::string const &s) {
for (int i = Beg; i < End; i++) {
if (s == get_enum_name((T)i)) {
return (T)i;
}
}
throw;
}

}
2 changes: 1 addition & 1 deletion tools/concat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ for x in $*; do
ffmpeg -i $x -vcodec copy -acodec copy -vbsf h264_mp4toannexb /tmp/t_$x.ts
done
cat /tmp/t_*.ts > /tmp/a_a.ts
ffmpeg -i /tmp/a_a.ts -acodec copy -vcodec copy -absf aac_adtstoasc /tmp/out.mp4
ffmpeg -y -i /tmp/a_a.ts -acodec copy -vcodec copy -absf aac_adtstoasc /tmp/out.mp4
rm -f /tmp/a_a.ts /tmp/t_*.ts

0 comments on commit 35b0dea

Please sign in to comment.