source: ThirdParty/mpqc_open/src/lib/util/container/carray.h@ 398fcd

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_levmar Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 398fcd was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 1.7 KB
Line 
1//
2// carray.h --- C Style Arrays
3//
4
5#ifndef _util_container_carray_h
6#define _util_container_carray_h
7
8namespace sc {
9
10template <class T>
11T **
12new_c_array2(int l, int m, T)
13{
14 T *a = 0;
15 T **b = 0;
16 if (l*m) a = new T[l*m];
17 if (l) b = new T*[l];
18 for (int i=0; i<l; i++) b[i] = &a[i*m];
19 return b;
20}
21
22template <class T>
23T **
24new_zero_c_array2(int l, int m, T)
25{
26 T *a = 0;
27 T **b = 0;
28 if (l*m) a = new T[l*m];
29 if (l) b = new T*[l];
30 for (int i=0; i<l; i++) {
31 b[i] = &a[i*m];
32 for (int j=0; j<m; j++) {
33 b[i][j] = 0;
34 }
35 }
36 return b;
37}
38
39template <class T>
40void
41delete_c_array2(T**b)
42{
43 if (b) delete[] b[0];
44 delete[] b;
45}
46
47template <class T>
48T ***
49new_c_array3(int l, int m, int n, T)
50{
51 T *a = 0;
52 T **b = 0;
53 T ***c = 0;
54 if (l*m*n) a = new T[l*m*n];
55 if (l*m) b = new T*[l*m];
56 if (l) c = new T**[l];
57 for (int i=0,ij=0; i<l; i++) {
58 c[i] = &b[i*m];
59 for (int j=0; j<m; j++,ij++) {
60 c[i][j] = &a[ij*n];
61 }
62 }
63 return c;
64}
65
66template <class T>
67T ***
68new_zero_c_array3(int l, int m, int n, T)
69{
70 T *a = 0;
71 T **b = 0;
72 T ***c = 0;
73 if (l*m*n) a = new T[l*m*n];
74 if (l*m) b = new T*[l*m];
75 if (l) c = new T**[l];
76 for (int i=0,ij=0; i<l; i++) {
77 c[i] = &b[i*m];
78 for (int j=0; j<m; j++,ij++) {
79 c[i][j] = &a[ij*n];
80 for (int k=0; k<n; k++) {
81 c[i][j][k] = 0;
82 }
83 }
84 }
85 return c;
86}
87
88template <class T>
89void
90delete_c_array3(T***b)
91{
92 if (b && b[0]) delete[] b[0][0];
93 if (b) delete[] b[0];
94 delete[] b;
95}
96
97}
98
99#endif
100
101// ///////////////////////////////////////////////////////////////////////////
102
103// Local Variables:
104// mode: c++
105// c-file-style: "CLJ"
106// End:
Note: See TracBrowser for help on using the repository browser.